From 6eb1ade13543d71240575adf84ff7494900294b5 Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 18 Jan 2021 13:38:47 +0100 Subject: [PATCH] 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; + } } } }