Fix merge conflict with interrupt disable lock.

This commit is contained in:
Tony DiCola 2015-07-22 12:22:35 -07:00
commit 5cd78aead6
2 changed files with 49 additions and 39 deletions

View File

@ -143,9 +143,11 @@ boolean DHT::read(void) {
digitalWrite(_pin, LOW);
delay(20);
uint32_t cycles[80];
{
// Turn off interrupts temporarily because the next sections are timing critical
// and we don't want any interruptions.
noInterrupts();
InterruptLock lock;
// End the start signal by setting data line high for 40 microseconds.
digitalWrite(_pin, HIGH);
@ -176,14 +178,11 @@ boolean DHT::read(void) {
// if the bit is a 0 (high state cycle count < low state cycle count), or a
// 1 (high state cycle count > low state cycle count). Note that for speed all
// the pulses are read into a array and then examined in a later step.
uint32_t cycles[80];
for (int i=0; i<80; i+=2) {
cycles[i] = expectPulse(LOW);
cycles[i+1] = expectPulse(HIGH);
}
// Re-enable interrupts, timing critical code is complete.
interrupts();
} // Timing critical code is now complete.
// Inspect pulses and determine which ones are 0 (high state cycle count < low
// state cycle count), or 1 (high state cycle count > low state cycle count).

11
DHT.h
View File

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