Really handle early requests and secure command waiting
This commit is contained in:
parent
273fb764e8
commit
60d5d95175
@ -42,11 +42,13 @@ enum DeviceState {
|
|||||||
|
|
||||||
volatile DeviceState state = DeviceState::WAIT4RESET;
|
volatile DeviceState state = DeviceState::WAIT4RESET;
|
||||||
volatile unsigned long conversionStartTime = 0;
|
volatile unsigned long conversionStartTime = 0;
|
||||||
|
volatile int ignByte = 0; // Bytes to be ignored
|
||||||
|
|
||||||
void owRcv( OneWireSlave::ReceiveEvent evt, byte cmd ){
|
void owRcv( OneWireSlave::ReceiveEvent evt, byte cmd ){
|
||||||
switch( evt ){
|
switch( evt ){
|
||||||
case OneWireSlave::RE_Reset:
|
case OneWireSlave::RE_Reset:
|
||||||
state = DeviceState::WAIT4COMMAND;
|
state = DeviceState::WAIT4COMMAND;
|
||||||
|
ignByte = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println(F("Reset"));
|
Serial.println(F("Reset"));
|
||||||
#endif
|
#endif
|
||||||
@ -58,10 +60,10 @@ void owRcv( OneWireSlave::ReceiveEvent evt, byte cmd ){
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case OneWireSlave::RE_Byte:
|
case OneWireSlave::RE_Byte:
|
||||||
switch( cmd ){
|
if( state == DeviceState::WAIT4COMMAND ) switch( cmd ){
|
||||||
case OW_Cmd::START_CONVERSION:
|
case OW_Cmd::START_CONVERSION:
|
||||||
// Do a new request only if enough time passed
|
// 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;
|
state = DeviceState::CONVERTING;
|
||||||
OWSlave.beginWriteBit(0, true); // send zeros as long as the conversion is not finished
|
OWSlave.beginWriteBit(0, true); // send zeros as long as the conversion is not finished
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user