DHT_U.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // DHT Temperature & Humidity Unified Sensor Library
  2. // Copyright (c) 2014 Adafruit Industries
  3. // Author: Tony DiCola
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. // The above copyright notice and this permission notice shall be included in all
  11. // copies or substantial portions of the Software.
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. // SOFTWARE.
  19. #ifndef DHT_U_H
  20. #define DHT_U_H
  21. #include <Adafruit_Sensor.h>
  22. #include <DHT.h>
  23. #define DHT_SENSOR_VERSION 1
  24. class DHT_Unified {
  25. public:
  26. DHT_Unified(uint8_t pin, uint8_t type, uint8_t count=6, int32_t tempSensorId=-1, int32_t humiditySensorId=-1);
  27. void begin();
  28. class Temperature : public Adafruit_Sensor {
  29. public:
  30. Temperature(DHT_Unified* parent, int32_t id);
  31. bool getEvent(sensors_event_t* event);
  32. void getSensor(sensor_t* sensor);
  33. private:
  34. DHT_Unified* _parent;
  35. int32_t _id;
  36. };
  37. class Humidity : public Adafruit_Sensor {
  38. public:
  39. Humidity(DHT_Unified* parent, int32_t id);
  40. bool getEvent(sensors_event_t* event);
  41. void getSensor(sensor_t* sensor);
  42. private:
  43. DHT_Unified* _parent;
  44. int32_t _id;
  45. };
  46. Temperature temperature() {
  47. return _temp;
  48. }
  49. Humidity humidity() {
  50. return _humidity;
  51. }
  52. private:
  53. DHT _dht;
  54. uint8_t _type;
  55. Temperature _temp;
  56. Humidity _humidity;
  57. void setName(sensor_t* sensor);
  58. void setMinDelay(sensor_t* sensor);
  59. };
  60. #endif