@@ -7,6 +7,7 @@ written by Adafruit Industries
7
7
#include " DHT.h"
8
8
9
9
#define MIN_INTERVAL 2000
10
+ #define TIMEOUT -1
10
11
11
12
DHT::DHT (uint8_t pin, uint8_t type, uint8_t count) {
12
13
_pin = pin;
@@ -157,12 +158,12 @@ boolean DHT::read(bool force) {
157
158
158
159
// First expect a low signal for ~80 microseconds followed by a high signal
159
160
// for ~80 microseconds again.
160
- if (expectPulse (LOW) == 0 ) {
161
+ if (expectPulse (LOW) == TIMEOUT ) {
161
162
DEBUG_PRINTLN (F (" Timeout waiting for start signal low pulse." ));
162
163
_lastresult = false ;
163
164
return _lastresult;
164
165
}
165
- if (expectPulse (HIGH) == 0 ) {
166
+ if (expectPulse (HIGH) == TIMEOUT ) {
166
167
DEBUG_PRINTLN (F (" Timeout waiting for start signal high pulse." ));
167
168
_lastresult = false ;
168
169
return _lastresult;
@@ -187,7 +188,7 @@ boolean DHT::read(bool force) {
187
188
for (int i=0 ; i<40 ; ++i) {
188
189
uint32_t lowCycles = cycles[2 *i];
189
190
uint32_t highCycles = cycles[2 *i+1 ];
190
- if ((lowCycles == 0 ) || (highCycles == 0 )) {
191
+ if ((lowCycles == TIMEOUT ) || (highCycles == TIMEOUT )) {
191
192
DEBUG_PRINTLN (F (" Timeout waiting for pulse." ));
192
193
_lastresult = false ;
193
194
return _lastresult;
@@ -238,15 +239,15 @@ uint32_t DHT::expectPulse(bool level) {
238
239
uint8_t portState = level ? _bit : 0 ;
239
240
while ((*portInputRegister (_port) & _bit) == portState) {
240
241
if (count++ >= _maxcycles) {
241
- return 0 ; // Exceeded timeout, fail.
242
+ return TIMEOUT ; // Exceeded timeout, fail.
242
243
}
243
244
}
244
245
// Otherwise fall back to using digitalRead (this seems to be necessary on ESP8266
245
246
// right now, perhaps bugs in direct port access functions?).
246
247
#else
247
248
while (digitalRead (_pin) == level) {
248
249
if (count++ >= _maxcycles) {
249
- return 0 ; // Exceeded timeout, fail.
250
+ return TIMEOUT ; // Exceeded timeout, fail.
250
251
}
251
252
}
252
253
#endif
0 commit comments