From 86a8e6a1288d144da927cc6a07c402bacbc27b4e Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 5 Jun 2014 12:04:03 +0200 Subject: [PATCH] Fixes #1157 --- radio/src/switches.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index d733acb4e..426ff7ad0 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -305,15 +305,29 @@ bool getLogicalSwitch(uint8_t idx) break; default: { - if (LS_LAST_VALUE(s_current_mixer_flight_mode, idx) == CS_LAST_VALUE_INIT) + if (LS_LAST_VALUE(s_current_mixer_flight_mode, idx) == CS_LAST_VALUE_INIT) { LS_LAST_VALUE(s_current_mixer_flight_mode, idx) = x; + } int16_t diff = x - LS_LAST_VALUE(s_current_mixer_flight_mode, idx); - if (ls->func == LS_FUNC_DIFFEGREATER) - result = (y >= 0 ? (diff >= y) : (diff <= y)); - else + bool update = false; + if (ls->func == LS_FUNC_DIFFEGREATER) { + if (y >= 0) { + result = (diff >= y); + if (diff < 0) + update = true; + } + else { + result = (diff <= y); + if (diff > 0) + update = true; + } + } + else { result = (abs(diff) >= y); - if (result) + } + if (result || update) { LS_LAST_VALUE(s_current_mixer_flight_mode, idx) = x; + } break; } }