Skip to content

Commit f1b7902

Browse files
Clean up two-second interval check
There was some handling of millis() overflow that is not needed. Standard unsigned subtraction and wraparound already works as expected, so this extra check can be removed (it even hurts, since it introduces 2 seconds after a wraparound where no new data will be read, even if it could otherwise happen). Also, this prevents calling millis() a second time, since its value is already known.
1 parent 04905bc commit f1b7902

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

DHT.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,11 @@ boolean DHT::read(bool force) {
117117
// Check if sensor was read less than two seconds ago and return early
118118
// to use last reading.
119119
uint32_t currenttime = millis();
120-
if (currenttime < _lastreadtime) {
121-
// ie there was a rollover
122-
_lastreadtime = 0;
123-
}
124120
if (!force && !_firstreading && ((currenttime - _lastreadtime) < 2000)) {
125121
return _lastresult; // return last correct measurement
126122
}
127123
_firstreading = false;
128-
_lastreadtime = millis();
124+
_lastreadtime = currenttime;
129125

130126
// Reset 40 bits of received data to zero.
131127
data[0] = data[1] = data[2] = data[3] = data[4] = 0;

0 commit comments

Comments
 (0)