dht.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "c_types.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. #define DHT_DEBUG
  28. // max timeout is 100 usec.
  29. // For a 16 Mhz proc 100 usec is 1600 clock cycles
  30. // loops using DHTLIB_TIMEOUT use at least 4 clock cycli
  31. // so 100 us takes max 400 loops
  32. // so by dividing F_CPU by 40000 we "fail" as fast as possible
  33. // ESP8266 uses delay_us get 1us time
  34. #define DHTLIB_TIMEOUT (100)
  35. // Platform specific I/O definitions
  36. #define DIRECT_READ(pin) (0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[pin])))
  37. #define DIRECT_MODE_INPUT(pin) GPIO_DIS_OUTPUT(pin_num[pin])
  38. #define DIRECT_MODE_OUTPUT(pin)
  39. #define DIRECT_WRITE_LOW(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 0))
  40. #define DIRECT_WRITE_HIGH(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 1))
  41. // return values:
  42. // DHTLIB_OK
  43. // DHTLIB_ERROR_CHECKSUM
  44. // DHTLIB_ERROR_TIMEOUT
  45. int dht_read_universal(uint8_t pin);
  46. int dht_read11(uint8_t pin);
  47. int dht_read(uint8_t pin);
  48. int dht_read21(uint8_t pin);
  49. int dht_read22(uint8_t pin);
  50. int dht_read33(uint8_t pin);
  51. int dht_read44(uint8_t pin);
  52. double dht_getHumidity(void);
  53. double dht_getTemperature(void);
  54. #endif
  55. //
  56. // END OF FILE
  57. //