DHT-sensor-library/DHT_U.h

102 lines
3.0 KiB
C
Raw Normal View History

2019-07-04 18:06:42 +03:00
/*!
* @file DHT_U.h
*
* DHT Temperature & Humidity Unified Sensor Library<Paste>
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit andopen-source hardware by purchasing products
* from Adafruit!
*
* Written by Tony DiCola (Adafruit Industries) 2014.
*
* MIT license, all text above must be included in any redistribution
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
2016-10-27 00:44:39 +03:00
#ifndef DHT_U_H
#define DHT_U_H
#include <Adafruit_Sensor.h>
#include <DHT.h>
2019-07-04 18:06:42 +03:00
#define DHT_SENSOR_VERSION 1 /**< Sensor Version */
2016-10-27 00:44:39 +03:00
2019-07-04 18:06:42 +03:00
/*!
* @brief Class that stores state and functions for interacting with
* DHT_Unified.
*/
2016-10-27 00:44:39 +03:00
class DHT_Unified {
public:
2019-07-04 18:06:42 +03:00
DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6,
int32_t tempSensorId = -1, int32_t humiditySensorId = -1);
2016-10-27 00:44:39 +03:00
void begin();
2019-07-04 18:06:42 +03:00
/*!
* @brief Class that stores state and functions about Temperature
*/
2016-10-27 00:44:39 +03:00
class Temperature : public Adafruit_Sensor {
public:
2019-07-04 18:06:42 +03:00
Temperature(DHT_Unified *parent, int32_t id);
bool getEvent(sensors_event_t *event);
void getSensor(sensor_t *sensor);
2016-10-27 00:44:39 +03:00
private:
2019-07-04 18:06:42 +03:00
DHT_Unified *_parent;
2016-10-27 00:44:39 +03:00
int32_t _id;
};
2019-07-04 18:06:42 +03:00
/*!
* @brief Class that stores state and functions about Humidity
*/
2016-10-27 00:44:39 +03:00
class Humidity : public Adafruit_Sensor {
public:
2019-07-04 18:06:42 +03:00
Humidity(DHT_Unified *parent, int32_t id);
bool getEvent(sensors_event_t *event);
void getSensor(sensor_t *sensor);
2016-10-27 00:44:39 +03:00
private:
2019-07-04 18:06:42 +03:00
DHT_Unified *_parent;
2016-10-27 00:44:39 +03:00
int32_t _id;
};
2019-07-04 18:28:10 +03:00
/*!
* @brief Returns temperature stored in _temp
* @return Temperature value
*/
2019-07-04 18:06:42 +03:00
Temperature temperature() { return _temp; }
2016-10-27 00:44:39 +03:00
2019-07-04 18:28:10 +03:00
/*!
* @brief Returns humidity stored in _humidity
* @return Humidity value
*/
2019-07-04 18:06:42 +03:00
Humidity humidity() { return _humidity; }
2016-10-27 00:44:39 +03:00
private:
DHT _dht;
uint8_t _type;
Temperature _temp;
Humidity _humidity;
2019-07-04 18:06:42 +03:00
void setName(sensor_t *sensor);
void setMinDelay(sensor_t *sensor);
2016-10-27 00:44:39 +03:00
};
#endif