From 60d5d95175d0b39bdd0640f39c9ae0e9f711c0cb Mon Sep 17 00:00:00 2001 From: destroyedlolo Date: Wed, 28 Mar 2018 00:45:17 +0200 Subject: [PATCH] Really handle early requests and secure command waiting --- examples/DS18B20_DHT22/DS18B20_DHT22.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/DS18B20_DHT22/DS18B20_DHT22.ino b/examples/DS18B20_DHT22/DS18B20_DHT22.ino index 2d88af7..d9e894d 100644 --- a/examples/DS18B20_DHT22/DS18B20_DHT22.ino +++ b/examples/DS18B20_DHT22/DS18B20_DHT22.ino @@ -42,11 +42,13 @@ enum DeviceState { volatile DeviceState state = DeviceState::WAIT4RESET; volatile unsigned long conversionStartTime = 0; +volatile int ignByte = 0; // Bytes to be ignored void owRcv( OneWireSlave::ReceiveEvent evt, byte cmd ){ switch( evt ){ case OneWireSlave::RE_Reset: state = DeviceState::WAIT4COMMAND; + ignByte = 0; #ifdef DEBUG Serial.println(F("Reset")); #endif @@ -58,10 +60,10 @@ void owRcv( OneWireSlave::ReceiveEvent evt, byte cmd ){ #endif break; case OneWireSlave::RE_Byte: - switch( cmd ){ + if( state == DeviceState::WAIT4COMMAND ) switch( cmd ){ case OW_Cmd::START_CONVERSION: // Do a new request only if enough time passed - if( !millis() || millis() < conversionStartTime || millis() > conversionStartTime + 2000 ){ + if( !conversionStartTime || millis() < conversionStartTime || millis() > conversionStartTime + 2000 ){ state = DeviceState::CONVERTING; OWSlave.beginWriteBit(0, true); // send zeros as long as the conversion is not finished }