Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ bool DHT::read(bool force) {
for (int i = 0; i < 80; i += 2) {
cycles[i] = expectPulse(LOW);
cycles[i + 1] = expectPulse(HIGH);

if (cycles[i] == TIMEOUT || cycles[i + 1] == TIMEOUT) {
DEBUG_PRINTLN(F("DHT timeout waiting for data signal."));
_lastresult = false;
return _lastresult;
}
}
} // Timing critical code is now complete.

Expand All @@ -312,11 +318,7 @@ bool DHT::read(bool force) {
for (int i = 0; i < 40; ++i) {
uint32_t lowCycles = cycles[2 * i];
uint32_t highCycles = cycles[2 * i + 1];
if ((lowCycles == TIMEOUT) || (highCycles == TIMEOUT)) {
DEBUG_PRINTLN(F("DHT timeout waiting for pulse."));
_lastresult = false;
return _lastresult;
}

data[i / 8] <<= 1;
// Now compare the low and high cycle times to see if the bit is a 0 or 1.
if (highCycles > lowCycles) {
Expand Down
Loading