@@ -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;
@@ -161,12 +162,12 @@ boolean DHT::read(bool force) {
161
162
162
163
// First expect a low signal for ~80 microseconds followed by a high signal
163
164
// for ~80 microseconds again.
164
- if (expectPulse (LOW) == 0 ) {
165
+ if (expectPulse (LOW) == TIMEOUT ) {
165
166
DEBUG_PRINTLN (F (" Timeout waiting for start signal low pulse." ));
166
167
_lastresult = false ;
167
168
return _lastresult;
168
169
}
169
- if (expectPulse (HIGH) == 0 ) {
170
+ if (expectPulse (HIGH) == TIMEOUT ) {
170
171
DEBUG_PRINTLN (F (" Timeout waiting for start signal high pulse." ));
171
172
_lastresult = false ;
172
173
return _lastresult;
@@ -191,7 +192,7 @@ boolean DHT::read(bool force) {
191
192
for (int i=0 ; i<40 ; ++i) {
192
193
uint32_t lowCycles = cycles[2 *i];
193
194
uint32_t highCycles = cycles[2 *i+1 ];
194
- if ((lowCycles == 0 ) || (highCycles == 0 )) {
195
+ if ((lowCycles == TIMEOUT ) || (highCycles == TIMEOUT )) {
195
196
DEBUG_PRINTLN (F (" Timeout waiting for pulse." ));
196
197
_lastresult = false ;
197
198
return _lastresult;
@@ -242,15 +243,15 @@ uint32_t DHT::expectPulse(bool level) {
242
243
uint8_t portState = level ? _bit : 0 ;
243
244
while ((*portInputRegister (_port) & _bit) == portState) {
244
245
if (count++ >= _maxcycles) {
245
- return 0 ; // Exceeded timeout, fail.
246
+ return TIMEOUT ; // Exceeded timeout, fail.
246
247
}
247
248
}
248
249
// Otherwise fall back to using digitalRead (this seems to be necessary on ESP8266
249
250
// right now, perhaps bugs in direct port access functions?).
250
251
#else
251
252
while (digitalRead (_pin) == level) {
252
253
if (count++ >= _maxcycles) {
253
- return 0 ; // Exceeded timeout, fail.
254
+ return TIMEOUT ; // Exceeded timeout, fail.
254
255
}
255
256
}
256
257
#endif
0 commit comments