|
3 | 3 | * |
4 | 4 | * This is a library for DHT series of low cost temperature/humidity sensors. |
5 | 5 | * |
6 | | - * You must have Adafruit Unified Sensor Library library installed to use this class. |
| 6 | + * You must have Adafruit Unified Sensor Library library installed to use this |
| 7 | + * class. |
7 | 8 | * |
8 | 9 | * Adafruit invests time and resources providing this open source code, |
9 | 10 | * please support Adafruit andopen-source hardware by purchasing products |
|
22 | 23 | /* Uncomment to enable printing out nice debug messages. */ |
23 | 24 | //#define DHT_DEBUG |
24 | 25 |
|
25 | | - |
26 | | -#define DEBUG_PRINTER Serial /**< Define where debug output will be printed. */ |
| 26 | +#define DEBUG_PRINTER \ |
| 27 | + Serial /**< Define where debug output will be printed. \ |
| 28 | + */ |
27 | 29 |
|
28 | 30 | /* Setup debug printing macros. */ |
29 | 31 | #ifdef DHT_DEBUG |
30 | | - #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); } |
31 | | - #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); } |
| 32 | +#define DEBUG_PRINT(...) \ |
| 33 | + { DEBUG_PRINTER.print(__VA_ARGS__); } |
| 34 | +#define DEBUG_PRINTLN(...) \ |
| 35 | + { DEBUG_PRINTER.println(__VA_ARGS__); } |
32 | 36 | #else |
33 | | - #define DEBUG_PRINT(...) {} /**< Debug Print Placeholder if Debug is disabled */ |
34 | | - #define DEBUG_PRINTLN(...) {} /**< Debug Print Line Placeholder if Debug is disabled */ |
| 37 | +#define DEBUG_PRINT(...) \ |
| 38 | + {} /**< Debug Print Placeholder if Debug is disabled */ |
| 39 | +#define DEBUG_PRINTLN(...) \ |
| 40 | + {} /**< Debug Print Line Placeholder if Debug is disabled */ |
35 | 41 | #endif |
36 | 42 |
|
37 | 43 | /* Define types of sensors. */ |
38 | | -#define DHT11 11 /**< DHT TYPE 11 */ |
39 | | -#define DHT12 12 /**< DHY TYPE 12 */ |
40 | | -#define DHT22 22 /**< DHT TYPE 22 */ |
41 | | -#define DHT21 21 /**< DHT TYPE 21 */ |
| 44 | +#define DHT11 11 /**< DHT TYPE 11 */ |
| 45 | +#define DHT12 12 /**< DHY TYPE 12 */ |
| 46 | +#define DHT22 22 /**< DHT TYPE 22 */ |
| 47 | +#define DHT21 21 /**< DHT TYPE 21 */ |
42 | 48 | #define AM2301 21 /**< AM2301 */ |
43 | 49 |
|
44 | | -/*! |
| 50 | +/*! |
45 | 51 | * @brief Class that stores state and functions for DHT |
46 | 52 | */ |
47 | 53 | class DHT { |
48 | | - public: |
49 | | - DHT(uint8_t pin, uint8_t type, uint8_t count=6); |
50 | | - void begin(uint8_t usec=55); |
51 | | - float readTemperature(bool S=false, bool force=false); |
52 | | - float convertCtoF(float); |
53 | | - float convertFtoC(float); |
54 | | - float computeHeatIndex(bool isFahrenheit=true); |
55 | | - float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); |
56 | | - float readHumidity(bool force=false); |
57 | | - bool read(bool force=false); |
| 54 | +public: |
| 55 | + DHT(uint8_t pin, uint8_t type, uint8_t count = 6); |
| 56 | + void begin(uint8_t usec = 55); |
| 57 | + float readTemperature(bool S = false, bool force = false); |
| 58 | + float convertCtoF(float); |
| 59 | + float convertFtoC(float); |
| 60 | + float computeHeatIndex(bool isFahrenheit = true); |
| 61 | + float computeHeatIndex(float temperature, float percentHumidity, |
| 62 | + bool isFahrenheit = true); |
| 63 | + float readHumidity(bool force = false); |
| 64 | + bool read(bool force = false); |
58 | 65 |
|
59 | | - private: |
| 66 | +private: |
60 | 67 | uint8_t data[5]; |
61 | 68 | uint8_t _pin, _type; |
62 | | - #ifdef __AVR |
63 | | - // Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask |
64 | | - // for the digital pin connected to the DHT. Other platforms will use digitalRead. |
65 | | - uint8_t _bit, _port; |
66 | | - #endif |
| 69 | +#ifdef __AVR |
| 70 | + // Use direct GPIO access on an 8-bit AVR so keep track of the port and |
| 71 | + // bitmask for the digital pin connected to the DHT. Other platforms will use |
| 72 | + // digitalRead. |
| 73 | + uint8_t _bit, _port; |
| 74 | +#endif |
67 | 75 | uint32_t _lastreadtime, _maxcycles; |
68 | 76 | bool _lastresult; |
69 | 77 | uint8_t pullTime; // Time (in usec) to pull up data line before reading |
70 | 78 |
|
71 | 79 | uint32_t expectPulse(bool level); |
72 | | - |
73 | 80 | }; |
74 | 81 |
|
75 | | -/*! |
| 82 | +/*! |
76 | 83 | * @brief Class that defines Interrupt Lock Avaiability |
77 | 84 | */ |
78 | 85 | class InterruptLock { |
79 | | - public: |
80 | | - InterruptLock() { |
81 | | -#if !defined(ARDUINO_ARCH_NRF52) |
| 86 | +public: |
| 87 | + InterruptLock() { |
| 88 | +#if !defined(ARDUINO_ARCH_NRF52) |
82 | 89 | noInterrupts(); |
83 | 90 | #endif |
84 | | - } |
85 | | - ~InterruptLock() { |
86 | | -#if !defined(ARDUINO_ARCH_NRF52) |
| 91 | + } |
| 92 | + ~InterruptLock() { |
| 93 | +#if !defined(ARDUINO_ARCH_NRF52) |
87 | 94 | interrupts(); |
88 | 95 | #endif |
89 | | - } |
| 96 | + } |
90 | 97 | }; |
91 | 98 |
|
92 | 99 | #endif |
0 commit comments