Merge pull request #36 from Zirientis/master

Cause interrupts to be reenabled if a timeout occurs while waiting for the sensor
This commit is contained in:
Tony DiCola 2015-07-01 22:16:10 -07:00
commit 9419315c50
2 changed files with 58 additions and 46 deletions

View File

@ -140,7 +140,8 @@ boolean DHT::read(void) {
// Turn off interrupts temporarily because the next sections are timing critical // Turn off interrupts temporarily because the next sections are timing critical
// and we don't want any interruptions. // and we don't want any interruptions.
noInterrupts(); {
InterruptLock lock;
// End the start signal by setting data line high for 40 microseconds. // End the start signal by setting data line high for 40 microseconds.
digitalWrite(_pin, HIGH); digitalWrite(_pin, HIGH);
@ -193,9 +194,9 @@ boolean DHT::read(void) {
// cycle count so this must be a zero. Nothing needs to be changed in the // cycle count so this must be a zero. Nothing needs to be changed in the
// stored data. // stored data.
} }
// Timing critical code is now complete.
// Re-enable interrupts, timing critical code is complete. }
interrupts();
DEBUG_PRINTLN(F("Received:")); DEBUG_PRINTLN(F("Received:"));
DEBUG_PRINT(data[0], HEX); DEBUG_PRINT(F(", ")); DEBUG_PRINT(data[0], HEX); DEBUG_PRINT(F(", "));

11
DHT.h
View File

@ -57,4 +57,15 @@ class DHT {
}; };
class InterruptLock {
public:
InterruptLock() {
noInterrupts();
}
~InterruptLock() {
interrupts();
}
};
#endif #endif