dht22.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. DHT library for the ESP8266, a port from the Adafruit library for the Arduino
  3. MIT license
  4. written by IoT Pipe
  5. */
  6. #ifndef DHT22_H
  7. #define DHT22_H
  8. #include "ets_sys.h"
  9. #include "osapi.h"
  10. #include "os_type.h"
  11. #include "user_config.h"
  12. #include "mem.h"
  13. #include "user_interface.h"
  14. #include "gpio.h"
  15. // Uncomment to enable printing out nice debug messages.
  16. //#define DHT_DEBUG
  17. // Setup debug printing macros.
  18. #ifdef DHT_DEBUG
  19. #define LOG_DEBUG(message) do {os_printf("[DHT-DEBUG] %s", message); os_printf("\r\n");} while (0)
  20. #define LOG_DEBUG_ARGS(message, args...) do {os_printf("[DHT-DEBUG] "); os_printf(message, args); os_printf("\r\n");} while (0)
  21. #else
  22. #define LOG_DEBUG(message) do {} while(0)
  23. #define LOG_DEBUG_ARGS(message, args...) do {} while(0)
  24. #endif
  25. // Define types of sensors.
  26. #define DHT11 11
  27. #define DHT22 22
  28. #define DHT21 21
  29. #define AM2301 21
  30. static uint8_t data[5];
  31. static uint8_t _pin, _type, _bit, _type;
  32. static uint32_t _lastreadtime, _maxcycles;
  33. static bool _lastresult;
  34. static uint32_t expectPulse(bool level);
  35. static int ICACHE_FLASH_ATTR get_index(int pin);
  36. static bool read();
  37. void DHT_init(uint8_t pin, uint8_t type, uint8_t count);
  38. void DHT_begin(void);
  39. float readTemperature(bool S);
  40. float readHumidity();
  41. float ICACHE_FLASH_ATTR convertCtoF(float);
  42. float ICACHE_FLASH_ATTR convertFtoC(float);
  43. #endif