From 537d7e089fbf5c7958d775a6254cdc87d608d4d1 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Tue, 18 Aug 2015 19:56:09 +0200 Subject: [PATCH] Fixes #2728: edge switch could trigger right after the logicalSwitchesReset() was called --- radio/src/switches.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 746e37755..6415699ff 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -835,6 +835,13 @@ void logicalSwitchesTimerTick() #if defined(CPUARM) else if (ls->func == LS_FUNC_EDGE) { ls_stay_struct & lastValue = (ls_stay_struct &)LS_LAST_VALUE(fm, i); + // if this ls was reset by the logicalSwitchesReset() the lastValue will be set to CS_LAST_VALUE_INIT(0x8000) + // when it is unpacked into ls_stay_struct the lastValue.duration will have a value of 0x4000 + // this will produce an instant true for edge logical switch if the second parameter is big enough. + // So we reset it here. + if (LS_LAST_VALUE(fm, i) == CS_LAST_VALUE_INIT) { + lastValue.duration = 0; + } lastValue.state = false; bool state = getSwitch(ls->v1); if (state) {