DHT_U.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifndef DHT_U_H
  33. #define DHT_U_H
  34. #include <Adafruit_Sensor.h>
  35. #include <DHT.h>
  36. #define DHT_SENSOR_VERSION 1 /**< Sensor Version */
  37. /*!
  38. * @brief Class that stores state and functions for interacting with
  39. * DHT_Unified.
  40. */
  41. class DHT_Unified {
  42. public:
  43. DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6,
  44. int32_t tempSensorId = -1, int32_t humiditySensorId = -1);
  45. void begin();
  46. /*!
  47. * @brief Class that stores state and functions about Temperature
  48. */
  49. class Temperature : public Adafruit_Sensor {
  50. public:
  51. Temperature(DHT_Unified *parent, int32_t id);
  52. bool getEvent(sensors_event_t *event);
  53. void getSensor(sensor_t *sensor);
  54. private:
  55. DHT_Unified *_parent;
  56. int32_t _id;
  57. };
  58. /*!
  59. * @brief Class that stores state and functions about Humidity
  60. */
  61. class Humidity : public Adafruit_Sensor {
  62. public:
  63. Humidity(DHT_Unified *parent, int32_t id);
  64. bool getEvent(sensors_event_t *event);
  65. void getSensor(sensor_t *sensor);
  66. private:
  67. DHT_Unified *_parent;
  68. int32_t _id;
  69. };
  70. /*!
  71. * @brief Returns temperature stored in _temp
  72. * @return Temperature value
  73. */
  74. Temperature temperature() { return _temp; }
  75. /*!
  76. * @brief Returns humidity stored in _humidity
  77. * @return Humidity value
  78. */
  79. Humidity humidity() { return _humidity; }
  80. private:
  81. DHT _dht;
  82. uint8_t _type;
  83. Temperature _temp;
  84. Humidity _humidity;
  85. void setName(sensor_t *sensor);
  86. void setMinDelay(sensor_t *sensor);
  87. };
  88. #endif