MistyGro API
C++ API for MistyGro's ESP32 controller based on the Arduino framework
temperature_sensor.cpp
Go to the documentation of this file.
1 // Copyright 2023 Myron Rodrigues
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "temperature_sensor.h"
16 
17 TemperatureSensor::TemperatureSensor(int pin) : wire_(pin), sensors_(&wire_){};
18 
19 void TemperatureSensor::begin() { sensors_.begin(); }
20 
21 uint8_t TemperatureSensor::device_count() { return sensors_.getDeviceCount(); }
22 
24 {
25  // request temperature form 1st/only sensor
26  sensors_.requestTemperaturesByIndex(0);
27  // read first/only sensor
28  return sensors_.getTempCByIndex(0);
29 }
void begin()
Initialise all one wire sensors.
uint8_t device_count()
Get count of total sensors on the one wire bus.
float read()
Read temperature as float value from sensor.
TemperatureSensor(int pin)
Construct a new TemperatureSensor.
Definition: utility.h:39