diff --git a/sonoff/xsns_06_dht.ino b/sonoff/xsns_06_dht.ino index 036dc873d..d98cf49bc 100644 --- a/sonoff/xsns_06_dht.ino +++ b/sonoff/xsns_06_dht.ino @@ -51,13 +51,13 @@ void DhtReadPrep() } } -uint32_t DhtExpectPulse(byte sensor, bool level) +int32_t DhtExpectPulse(byte sensor, bool level) { - uint32_t count = 0; + int32_t count = 0; while (digitalRead(Dht[sensor].pin) == level) { if (count++ >= dht_max_cycles) { - return 0; + return -1; // Timeout } } return count; @@ -65,7 +65,7 @@ uint32_t DhtExpectPulse(byte sensor, bool level) void DhtRead(byte sensor) { - uint32_t cycles[80]; + int32_t cycles[80]; uint32_t currenttime = millis(); if ((currenttime - Dht[sensor].lastreadtime) < MIN_INTERVAL) { @@ -92,12 +92,12 @@ void DhtRead(byte sensor) delayMicroseconds(40); pinMode(Dht[sensor].pin, INPUT_PULLUP); delayMicroseconds(10); - if (0 == DhtExpectPulse(sensor, LOW)) { + if (-1 == DhtExpectPulse(sensor, LOW)) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE)); Dht[sensor].lastresult++; return; } - if (0 == DhtExpectPulse(sensor, HIGH)) { + if (-1 == DhtExpectPulse(sensor, HIGH)) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_HIGH " " D_PULSE)); Dht[sensor].lastresult++; return; @@ -108,17 +108,17 @@ void DhtRead(byte sensor) } interrupts(); - for (int i=0; i<40; ++i) { - uint32_t lowCycles = cycles[2*i]; - uint32_t highCycles = cycles[2*i+1]; - if ((0 == lowCycles) || (0 == highCycles)) { + for (int i = 0; i < 40; ++i) { + int32_t lowCycles = cycles[2*i]; + int32_t highCycles = cycles[2*i+1]; + if ((-1 == lowCycles) || (-1 == highCycles)) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_PULSE)); Dht[sensor].lastresult++; return; } dht_data[i/8] <<= 1; if (highCycles > lowCycles) { - dht_data[i/8] |= 1; + dht_data[i / 8] |= 1; } }