diff --git a/radio/src/gui/navigation/navigation_9x.cpp b/radio/src/gui/navigation/navigation_9x.cpp index bbc958c63..74380a69b 100644 --- a/radio/src/gui/navigation/navigation_9x.cpp +++ b/radio/src/gui/navigation/navigation_9x.cpp @@ -136,7 +136,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla #if defined(AUTOSWITCH) else { uint8_t swtch = abs(getMovedSwitch()); - if (swtch) { + if (swtch && !IS_SWITCH_MULTIPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/gui/navigation/navigation_horus.cpp b/radio/src/gui/navigation/navigation_horus.cpp index d62d07810..9679ab6e7 100644 --- a/radio/src/gui/navigation/navigation_horus.cpp +++ b/radio/src/gui/navigation/navigation_horus.cpp @@ -137,7 +137,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla #if defined(AUTOSWITCH) else { unsigned int swtch = abs(getMovedSwitch()); - if (swtch) { + if (swtch && !IS_SWITCH_MULTIPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/gui/navigation/navigation_x7.cpp b/radio/src/gui/navigation/navigation_x7.cpp index 7e4255dac..ecf00a02b 100644 --- a/radio/src/gui/navigation/navigation_x7.cpp +++ b/radio/src/gui/navigation/navigation_x7.cpp @@ -106,7 +106,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla #if defined(AUTOSWITCH) else { unsigned int swtch = abs(getMovedSwitch()); - if (swtch) { + if (swtch && !IS_SWITCH_MULTIPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/gui/navigation/navigation_x9d.cpp b/radio/src/gui/navigation/navigation_x9d.cpp index a5d6fc332..2b3587cba 100644 --- a/radio/src/gui/navigation/navigation_x9d.cpp +++ b/radio/src/gui/navigation/navigation_x9d.cpp @@ -173,7 +173,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla #if defined(AUTOSWITCH) else { unsigned int swtch = abs(getMovedSwitch()); - if (swtch) { + if (swtch && !IS_SWITCH_MULTIPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/gui/navigation/navigation_xlite.cpp b/radio/src/gui/navigation/navigation_xlite.cpp index 9cbafda8b..974308f1b 100644 --- a/radio/src/gui/navigation/navigation_xlite.cpp +++ b/radio/src/gui/navigation/navigation_xlite.cpp @@ -166,7 +166,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla #if defined(AUTOSWITCH) else { uint8_t swtch = abs(getMovedSwitch()); - if (swtch) { + if (swtch && !IS_SWITCH_MULTIPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 4e31efacb..7e89312dc 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -557,6 +557,8 @@ bool isInputRecursive(int index) } #if defined(AUTOSOURCE) +constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / XPOTS_MULTIPOS_COUNT; + int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS) { int8_t result = 0; @@ -565,7 +567,7 @@ int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS) static int16_t inputsStates[MAX_INPUTS]; if (min <= MIXSRC_FIRST_INPUT) { for (uint8_t i=0; i 512) { + if (abs(anas[i] - inputsStates[i]) > MULTIPOS_STEP_SIZE) { if (!isInputRecursive(i)) { result = MIXSRC_FIRST_INPUT+i; break; @@ -577,7 +579,7 @@ int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS) static int16_t sourcesStates[NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_MOUSE_ANALOGS]; if (result == 0) { for (uint8_t i=0; i 512) { + if (abs(calibratedAnalogs[i] - sourcesStates[i]) > MULTIPOS_STEP_SIZE) { result = MIXSRC_Rud+i; break; } diff --git a/radio/src/opentx.h b/radio/src/opentx.h index bb756305b..2580aa653 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -282,6 +282,12 @@ void memswap(void * a, void * b, uint8_t size); #define IS_MULTIPOS_CALIBRATED(cal) (false) #endif +#if NUM_XPOTS > 0 + #define IS_SWITCH_MULTIPOS(x) (SWSRC_FIRST_MULTIPOS_SWITCH <= (x) && (x) <= SWSRC_LAST_MULTIPOS_SWITCH) +#else + #define IS_SWITCH_MULTIPOS(x) (false) +#endif + #if defined(PWR_BUTTON_PRESS) #define pwrOffPressed() pwrPressed() #else diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 727b05096..9a7fbb2f8 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -520,14 +520,28 @@ swsrc_t getMovedSwitch() swsrc_t result = 0; #if defined(PCBTARANIS) || defined(PCBHORUS) - for (int i=0; i> (i*2); - uint8_t next = (1024+getValue(MIXSRC_SA+i)) / 1024; + swarnstate_t mask = ((swarnstate_t) 0x03 << (i * 2)); + uint8_t prev = (switches_states & mask) >> (i * 2); + uint8_t next = (1024 + getValue(MIXSRC_SA + i)) / 1024; if (prev != next) { - switches_states = (switches_states & (~mask)) | ((swarnstate_t)next << (i*2)); - result = 1+(3*i)+next; + switches_states = (switches_states & (~mask)) | ((swarnstate_t) next << (i * 2)); + result = 1 + (3 * i) + next; + } + } + } + // Multipos + for (int i = 0; i < NUM_XPOTS; i++) { + if (IS_POT_MULTIPOS(POT1 + i)) { + StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[POT1 + i]; + if (IS_MULTIPOS_CALIBRATED(calib)) { + uint8_t prev = potsPos[i] & 0x0F; + uint8_t next = anaIn(POT1 + i) / (2 * RESX / calib->count); + if (prev != next) { + result = SWSRC_LAST_SWITCH + i * XPOTS_MULTIPOS_COUNT + next + 1; + } } } }