From 756bda0389295d59fc12feb7c44dfde7a98f59bb Mon Sep 17 00:00:00 2001 From: alteman Date: Tue, 13 Aug 2024 06:59:06 +0300 Subject: [PATCH] fix: remove extra cycle in LS timer v2->v1 transition (#4664) --- radio/src/switches.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 166b6c456..67072f256 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -1077,20 +1077,15 @@ void logicalSwitchesTimerTick() for (uint8_t i=0; ifunc == LS_FUNC_TIMER) { - int16_t * lastValue = &LS_LAST_VALUE(fm, i); + int16_t *lastValue = &LS_LAST_VALUE(fm, i); if (*lastValue == 0 || *lastValue == CS_LAST_VALUE_INIT) { *lastValue = -lswTimerValue(ls->v1); + } else if (*lastValue < 0) { + if (++(*lastValue) == 0) *lastValue = lswTimerValue(ls->v2); + } else { // if (*lastValue > 0) + if (--(*lastValue) == 0) *lastValue = -lswTimerValue(ls->v1); } - - else if (*lastValue < 0) { - if (++(*lastValue) == 0) - *lastValue = lswTimerValue(ls->v2); - } - else { // if (*lastValue > 0) - *lastValue -= 1; - } - } - else if (ls->func == LS_FUNC_STICKY) { + } else if (ls->func == LS_FUNC_STICKY) { ls_sticky_struct & lastValue = (ls_sticky_struct &)LS_LAST_VALUE(fm, i); bool before = lastValue.last & 0x01; if (lastValue.state) { @@ -1115,8 +1110,7 @@ void logicalSwitchesTimerTick() } } } - } - else if (ls->func == LS_FUNC_EDGE) { + } 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