From 6eb1ade13543d71240575adf84ff7494900294b5 Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 18 Jan 2021 13:38:47 +0100 Subject: [PATCH 1/8] Multipos autoswitch --- radio/src/switches.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) 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; + } } } } From 233d1d26303ec7b982c651445fc9b2905c08c90d Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 19 Jan 2021 08:24:02 +0100 Subject: [PATCH 2/8] Prevent multipos switch to be returned as a source --- radio/src/gui/navigation/navigation_horus.cpp | 2 +- radio/src/opentx.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/navigation/navigation_horus.cpp b/radio/src/gui/navigation/navigation_horus.cpp index d62d07810..07c53ae1d 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_MULTPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/opentx.h b/radio/src/opentx.h index bb756305b..ffabdc9b7 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -268,6 +268,7 @@ void memswap(void * a, void * b, uint8_t size); #define IS_POT_AVAILABLE(x) (IS_POT(x) && POT_CONFIG(x)!=POT_NONE) #define IS_POT_SLIDER_AVAILABLE(x) (IS_POT_AVAILABLE(x) || IS_SLIDER_AVAILABLE(x)) #define IS_MULTIPOS_CALIBRATED(cal) (cal->count>0 && cal->count> (2*((x)-POT1)))&0x03) #define IS_POT_MULTIPOS(x) (IS_POT(x) && POT_CONFIG(x)==POT_MULTIPOS_SWITCH) From ce028e7fe4939b64c5045bf8b87ffe06baa46026 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 19 Jan 2021 08:50:10 +0100 Subject: [PATCH 3/8] Apply to all targets --- radio/src/gui/navigation/navigation_9x.cpp | 2 +- radio/src/gui/navigation/navigation_x7.cpp | 2 +- radio/src/gui/navigation/navigation_x9d.cpp | 2 +- radio/src/gui/navigation/navigation_xlite.cpp | 2 +- radio/src/opentx.h | 2 ++ 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/radio/src/gui/navigation/navigation_9x.cpp b/radio/src/gui/navigation/navigation_9x.cpp index bbc958c63..db9b34d4e 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_MULTPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/gui/navigation/navigation_x7.cpp b/radio/src/gui/navigation/navigation_x7.cpp index 7e4255dac..3d58c619b 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_MULTPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/gui/navigation/navigation_x9d.cpp b/radio/src/gui/navigation/navigation_x9d.cpp index a5d6fc332..e0a7a9dae 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_MULTPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/gui/navigation/navigation_xlite.cpp b/radio/src/gui/navigation/navigation_xlite.cpp index 9cbafda8b..4a914a1d3 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_MULTPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/opentx.h b/radio/src/opentx.h index ffabdc9b7..ed4a42d43 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -276,11 +276,13 @@ void memswap(void * a, void * b, uint8_t size); #define IS_POT_AVAILABLE(x) (IS_POT(x) && POT_CONFIG(x)!=POT_NONE) #define IS_POT_SLIDER_AVAILABLE(x) (IS_POT_AVAILABLE(x)) #define IS_MULTIPOS_CALIBRATED(cal) (cal->count>0 && cal->count Date: Tue, 19 Jan 2021 09:01:00 +0100 Subject: [PATCH 4/8] Cosmetics --- radio/src/opentx.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index ed4a42d43..652c26409 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -268,7 +268,6 @@ void memswap(void * a, void * b, uint8_t size); #define IS_POT_AVAILABLE(x) (IS_POT(x) && POT_CONFIG(x)!=POT_NONE) #define IS_POT_SLIDER_AVAILABLE(x) (IS_POT_AVAILABLE(x) || IS_SLIDER_AVAILABLE(x)) #define IS_MULTIPOS_CALIBRATED(cal) (cal->count>0 && cal->count> (2*((x)-POT1)))&0x03) #define IS_POT_MULTIPOS(x) (IS_POT(x) && POT_CONFIG(x)==POT_MULTIPOS_SWITCH) @@ -276,12 +275,16 @@ void memswap(void * a, void * b, uint8_t size); #define IS_POT_AVAILABLE(x) (IS_POT(x) && POT_CONFIG(x)!=POT_NONE) #define IS_POT_SLIDER_AVAILABLE(x) (IS_POT_AVAILABLE(x)) #define IS_MULTIPOS_CALIBRATED(cal) (cal->count>0 && cal->count 0 + #define IS_SWITCH_MULTPOS(x) (SWSRC_FIRST_MULTIPOS_SWITCH <= (x) && (x) <= SWSRC_LAST_MULTIPOS_SWITCH) +#else #define IS_SWITCH_MULTPOS(x) (false) #endif From 957631a95b2c0b87625905244bd52e1bf804c670 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 19 Jan 2021 11:00:57 +0100 Subject: [PATCH 5/8] Fix detection step size --- radio/src/opentx.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 4e31efacb..c473fc67a 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 + 1); + 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; } From 925af297e5894efbc2af667c12d73992a345bc53 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 19 Jan 2021 14:34:43 +0100 Subject: [PATCH 6/8] Cosmetics --- radio/src/gui/navigation/navigation_9x.cpp | 2 +- radio/src/gui/navigation/navigation_horus.cpp | 2 +- radio/src/gui/navigation/navigation_x7.cpp | 2 +- radio/src/gui/navigation/navigation_x9d.cpp | 2 +- radio/src/gui/navigation/navigation_xlite.cpp | 2 +- radio/src/opentx.cpp | 2 +- radio/src/opentx.h | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/radio/src/gui/navigation/navigation_9x.cpp b/radio/src/gui/navigation/navigation_9x.cpp index db9b34d4e..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 && !IS_SWITCH_MULTPOS(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 07c53ae1d..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 && !IS_SWITCH_MULTPOS(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 3d58c619b..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 && !IS_SWITCH_MULTPOS(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 e0a7a9dae..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 && !IS_SWITCH_MULTPOS(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 4a914a1d3..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 && !IS_SWITCH_MULTPOS(swtch)) { + if (swtch && !IS_SWITCH_MULTIPOS(swtch)) { newval = switchToMix(swtch); } } diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index c473fc67a..64e5e5419 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -557,7 +557,7 @@ bool isInputRecursive(int index) } #if defined(AUTOSOURCE) -constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / (XPOTS_MULTIPOS_COUNT + 1); +constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / (XPOTS_MULTIPOS_COUNT - 1); int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS) { diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 652c26409..2580aa653 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -283,9 +283,9 @@ void memswap(void * a, void * b, uint8_t size); #endif #if NUM_XPOTS > 0 - #define IS_SWITCH_MULTPOS(x) (SWSRC_FIRST_MULTIPOS_SWITCH <= (x) && (x) <= SWSRC_LAST_MULTIPOS_SWITCH) + #define IS_SWITCH_MULTIPOS(x) (SWSRC_FIRST_MULTIPOS_SWITCH <= (x) && (x) <= SWSRC_LAST_MULTIPOS_SWITCH) #else - #define IS_SWITCH_MULTPOS(x) (false) + #define IS_SWITCH_MULTIPOS(x) (false) #endif #if defined(PWR_BUTTON_PRESS) From ab067249702187ed1b3c1b538c9c1dfce8d48462 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 19 Jan 2021 14:43:36 +0100 Subject: [PATCH 7/8] Consistency --- radio/src/opentx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 64e5e5419..9cdfa7b59 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -557,7 +557,7 @@ bool isInputRecursive(int index) } #if defined(AUTOSOURCE) -constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / (XPOTS_MULTIPOS_COUNT - 1); +constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / (XPOTS_MULTIPOS_COUNT); int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS) { From 7b05b086e495b60bc004caaef282ded6e2c0a1ca Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 19 Jan 2021 14:48:41 +0100 Subject: [PATCH 8/8] Cosmetics --- radio/src/opentx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 9cdfa7b59..7e89312dc 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -557,7 +557,7 @@ bool isInputRecursive(int index) } #if defined(AUTOSOURCE) -constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / (XPOTS_MULTIPOS_COUNT); +constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / XPOTS_MULTIPOS_COUNT; int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS) {