DHT_U.h (3080B)
1 /*! 2 * @file DHT_U.h 3 * 4 * DHT Temperature & Humidity Unified Sensor Library<Paste> 5 * 6 * Adafruit invests time and resources providing this open source code, 7 * please support Adafruit andopen-source hardware by purchasing products 8 * from Adafruit! 9 * 10 * Written by Tony DiCola (Adafruit Industries) 2014. 11 * 12 * MIT license, all text above must be included in any redistribution 13 * 14 * Permission is hereby granted, free of charge, to any person obtaining a copy 15 * of this software and associated documentation files (the "Software"), to 16 * deal in the Software without restriction, including without limitation the 17 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 18 * sell copies of the Software, and to permit persons to whom the Software is 19 * furnished to do so, subject to the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be included in 22 * all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 30 * IN THE SOFTWARE. 31 */ 32 33 #ifndef DHT_U_H 34 #define DHT_U_H 35 36 #include <Adafruit_Sensor.h> 37 #include <DHT.h> 38 39 #define DHT_SENSOR_VERSION 1 /**< Sensor Version */ 40 41 /*! 42 * @brief Class that stores state and functions for interacting with 43 * DHT_Unified. 44 */ 45 class DHT_Unified { 46 public: 47 DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6, 48 int32_t tempSensorId = -1, int32_t humiditySensorId = -1); 49 void begin(); 50 51 /*! 52 * @brief Class that stores state and functions about Temperature 53 */ 54 class Temperature : public Adafruit_Sensor { 55 public: 56 Temperature(DHT_Unified *parent, int32_t id); 57 bool getEvent(sensors_event_t *event); 58 void getSensor(sensor_t *sensor); 59 60 private: 61 DHT_Unified *_parent; 62 int32_t _id; 63 }; 64 65 /*! 66 * @brief Class that stores state and functions about Humidity 67 */ 68 class Humidity : public Adafruit_Sensor { 69 public: 70 Humidity(DHT_Unified *parent, int32_t id); 71 bool getEvent(sensors_event_t *event); 72 void getSensor(sensor_t *sensor); 73 74 private: 75 DHT_Unified *_parent; 76 int32_t _id; 77 }; 78 79 /*! 80 * @brief Returns temperature stored in _temp 81 * @return Temperature value 82 */ 83 Temperature temperature() { return _temp; } 84 85 /*! 86 * @brief Returns humidity stored in _humidity 87 * @return Humidity value 88 */ 89 Humidity humidity() { return _humidity; } 90 91 private: 92 DHT _dht; 93 uint8_t _type; 94 Temperature _temp; 95 Humidity _humidity; 96 97 void setName(sensor_t *sensor); 98 void setMinDelay(sensor_t *sensor); 99 }; 100 101 #endif