diff --git a/radio/src/gui/menu_model_setup.cpp b/radio/src/gui/menu_model_setup.cpp index c57a0c2ab..59b63dcca 100755 --- a/radio/src/gui/menu_model_setup.cpp +++ b/radio/src/gui/menu_model_setup.cpp @@ -285,6 +285,14 @@ void menuModelSetup(uint8_t event) switch (m_posHorz) { case 0: CHECK_INCDEC_MODELVAR_CHECK(event, timer->mode, SWSRC_FIRST, TMRMODE_COUNT+SWSRC_LAST-1/*SWSRC_None removed*/, isSwitchAvailableInTimers); + if (s_editMode>0) { + int8_t val = timer->mode - (TMRMODE_COUNT-1); + int8_t switchVal = checkIncDecMovedSwitch(val); + if (val != switchVal) { + timer->mode = switchVal + (TMRMODE_COUNT-1); + eeDirty(EE_MODEL); + } + } break; case 1: CHECK_INCDEC_MODELVAR_ZERO(event, qr.quot, 59); diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 06db8b795..68e7ade84 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -104,6 +104,34 @@ uint8_t switchToMix(uint8_t source) #endif } +#if defined(AUTOSWITCH) +int8_t checkIncDecMovedSwitch(int8_t val) +{ + if (s_editMode>0) { + int8_t swtch = getMovedSwitch(); + if (swtch) { +#if defined(PCBTARANIS) + div_t info = switchInfo(swtch); + if (IS_TOGGLE(info.quot)) { + if (info.rem != 0) { + val = (val == swtch ? swtch+2 : swtch); + } + } + else { + val = swtch; + } +#else + if (IS_MOMENTARY(val) && swtch==val) + val = -val; + else + val = swtch; +#endif + } + } + return val; +} +#endif + int8_t checkIncDec_Ret; #if defined(CPUARM) @@ -217,22 +245,7 @@ int16_t checkIncDec(uint8_t event, int16_t val, int16_t i_min, int16_t i_max, ui #if defined(AUTOSWITCH) if (i_flags & INCDEC_SWITCH) { - if (s_editMode>0) { - int8_t swtch = getMovedSwitch(); - if (swtch) { -#if defined(PCBTARANIS) - if(swtch == SWSRC_SH2) - newval = (newval == SWSRC_SH2 ? SWSRC_SH0 : SWSRC_SH2); - else if(swtch != SWSRC_SH0) - newval = swtch; -#else - if (IS_MOMENTARY(newval) && IS_MOMENTARY(swtch)) - newval = -newval; - else - newval = swtch; -#endif - } - } + newval = checkIncDecMovedSwitch(newval); } #endif diff --git a/radio/src/gui/menus.h b/radio/src/gui/menus.h index ba8bc9c54..f2b115a34 100644 --- a/radio/src/gui/menus.h +++ b/radio/src/gui/menus.h @@ -200,6 +200,8 @@ int checkIncDec(uint8_t event, int val, int i_min, int i_max, uint8_t i_flags=0, int16_t checkIncDec(uint8_t event, int16_t val, int16_t i_min, int16_t i_max, uint8_t i_flags=0); #endif +int8_t checkIncDecMovedSwitch(int8_t val); + #if defined(CPUM64) int8_t checkIncDecModel(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max); int8_t checkIncDecModelZero(uint8_t event, int8_t i_val, int8_t i_max); diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index bd1f18778..0880a5edd 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -721,12 +721,14 @@ int switchConfig(int idx); #define SWITCH_DEFAULT_CONFIG(x) (SWITCH_3POS) #define IS_2x2POS(x) (false) #define ONE_2x2POS_DEFINED() (false) + #define SWITCH_EXISTS(x) (switchConfig(x) != SWITCH_NONE) #define SWITCH_WARNING_ALLOWED(x) (!IS_TOGGLE(x)) #else #define SWITCH_DEFAULT_CONFIG(x) ((x)==5 ? SWITCH_2POS : ((x)==7 ? SWITCH_TOGGLE : SWITCH_3POS)) #define IS_2x2POS(x) (switchConfig(x) == SWITCH_2x2POS) #define ONE_2x2POS_DEFINED() (g_eeGeneral.switchConfig & 0x44444444) - #define SWITCH_WARNING_ALLOWED(x) (x<8 ? !IS_TOGGLE(x) : IS_2x2POS(x-8)) + #define SWITCH_EXISTS(x) ((x)<8 ? (switchConfig(x) != SWITCH_NONE) : (IS_2x2POS(x-8))) + #define SWITCH_WARNING_ALLOWED(x) ((x)<8 ? !IS_TOGGLE(x) : IS_2x2POS(x-8)) #endif inline int getSwitchWarningsAllowed() { diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 44692a6fc..4f1a41f25 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -587,20 +587,22 @@ int8_t getMovedSwitch() int8_t result = 0; #if defined(PCBTARANIS) - for (uint8_t i=0; i> (i*2); - uint8_t next = (1024+getValue(MIXSRC_SA+i)) / 1024; - if (prev != next) { - switches_states = (switches_states & (~mask)) | (next << (i*2)); - if (i<5) - result = 1+(3*i)+next; - else if (i==5) - result = 1+(3*5)+(next!=0); - else if (i==6) - result = 1+(3*5)+2+next; - else - result = 1+(3*5)+2+3+(next!=0); + for (int i=0; i> (i*2); + uint8_t next = (1024+getValue(MIXSRC_SA+i)) / 1024; + if (prev != next) { + switches_states = (switches_states & (~mask)) | (next << (i*2)); + if (i<5) + result = 1+(3*i)+next; + else if (i==5) + result = 1+(3*5)+(next!=0); + else if (i==6) + result = 1+(3*5)+2+next; + else + result = 1+(3*5)+2+3+(next!=0); + } } } #else