dht.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // FILE: dht.h
  3. // AUTHOR: Rob Tillaart
  4. // VERSION: 0.1.14
  5. // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
  6. // URL: http://arduino.cc/playground/Main/DHTLib
  7. //
  8. // HISTORY:
  9. // see dht.cpp file
  10. //
  11. #ifndef dht_h
  12. #define dht_h
  13. // #if ARDUINO < 100
  14. // #include <WProgram.h>
  15. // #else
  16. // #include <Arduino.h>
  17. // #endif
  18. #include <stdint.h>
  19. #define DHT_LIB_VERSION "0.1.14"
  20. #define DHTLIB_OK 0
  21. #define DHTLIB_ERROR_CHECKSUM -1
  22. #define DHTLIB_ERROR_TIMEOUT -2
  23. #define DHTLIB_INVALID_VALUE -999
  24. #define DHTLIB_DHT11_WAKEUP 18
  25. #define DHTLIB_DHT_WAKEUP 1
  26. #define DHTLIB_DHT_UNI_WAKEUP 18
  27. // max timeout is 100 usec.
  28. // For a 16 Mhz proc 100 usec is 1600 clock cycles
  29. // loops using DHTLIB_TIMEOUT use at least 4 clock cycli
  30. // so 100 us takes max 400 loops
  31. // so by dividing F_CPU by 40000 we "fail" as fast as possible
  32. // ESP8266 uses delay_us get 1us time
  33. #define DHTLIB_TIMEOUT (100)
  34. // Platform specific I/O definitions
  35. #define DIRECT_READ(pin) (0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[pin])))
  36. #define DIRECT_MODE_INPUT(pin) GPIO_DIS_OUTPUT(pin_num[pin])
  37. #define DIRECT_MODE_OUTPUT(pin)
  38. #define DIRECT_WRITE_LOW(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 0))
  39. #define DIRECT_WRITE_HIGH(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 1))
  40. typedef enum {
  41. DHT11 = 0,
  42. DHT12,
  43. DHT22,
  44. DHT_NON11
  45. } dht_type;
  46. // return values:
  47. // DHTLIB_OK
  48. // DHTLIB_ERROR_CHECKSUM
  49. // DHTLIB_ERROR_TIMEOUT
  50. int dht_read(uint8_t pin, dht_type type);
  51. double dht_getHumidity(void);
  52. double dht_getTemperature(void);
  53. #endif
  54. //
  55. // END OF FILE
  56. //