From 98b23b348e161eb436e50f53ff6df71ce929ce2e Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 18 Jun 2015 19:09:08 +0200 Subject: [PATCH] Fixes #2369 --- radio/src/gui/Taranis/helpers.cpp | 20 ++++++++++++++------ radio/src/myeeprom.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/radio/src/gui/Taranis/helpers.cpp b/radio/src/gui/Taranis/helpers.cpp index 1f9f5e61a..a5063223b 100755 --- a/radio/src/gui/Taranis/helpers.cpp +++ b/radio/src/gui/Taranis/helpers.cpp @@ -191,11 +191,10 @@ bool isLogicalSwitchAvailable(int index) bool isSwitchAvailable(int swtch, SwitchContext context) { - uint32_t index = switchInfo(abs(swtch)).quot; + bool negative = false; if (swtch < 0) { - if (!IS_3POS(index)) - return false; + negative = true; if (swtch == -SWSRC_ON || swtch == -SWSRC_One) { return false; } @@ -203,10 +202,19 @@ bool isSwitchAvailable(int swtch, SwitchContext context) } if (swtch >= SWSRC_SA0 && swtch <= SWSRC_LAST_SWITCH) { - if (!SWITCH_EXISTS(index)) + div_t swinfo = switchInfo(swtch); + if (!SWITCH_EXISTS(swinfo.quot)) { return false; - if ((swtch-SWSRC_SA1)%3 == 0) - return IS_3POS(index); + } + if (!IS_3POS(swinfo.quot)) { + if (negative) { + return false; + } + if (IS_3POS_MIDDLE(swinfo.rem)) { + return false; + } + } + return true; } if (swtch >= SWSRC_FIRST_MULTIPOS_SWITCH && swtch <= SWSRC_LAST_MULTIPOS_SWITCH) { diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 1b3d7712f..3c1f4902f 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -732,6 +732,7 @@ PACK(typedef struct { #define SWITCH_EXISTS(x) (SWITCH_CONFIG(x) != SWITCH_NONE) #define IS_3POS(x) (SWITCH_CONFIG(x) == SWITCH_3POS) #define IS_TOGGLE(x) (SWITCH_CONFIG(x) == SWITCH_TOGGLE) + #define IS_3POS_MIDDLE(x) ((x) == 1) #define SWITCH_WARNING_ALLOWED(x) (SWITCH_EXISTS(x) && !IS_TOGGLE(x)) #endif