diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 4e4eacbb6..7d61b1f3e 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -171,6 +171,24 @@ void getSwitchesPosition(bool startup) } #define SWITCH_POSITION(sw) (switchesPos & (1<<(sw))) #define POT_POSITION(sw) ((potsPos[(sw)/XPOTS_MULTIPOS_COUNT] & 0x0f) == ((sw) % XPOTS_MULTIPOS_COUNT)) + +getvalue_t getValueForLogicalSwitch(uint8_t i) +{ + getvalue_t result = getValue(i); + if (i>=MIXSRC_FIRST_INPUT && i<=MIXSRC_LAST_INPUT) { + int8_t trimIdx = virtualInputsTrims[i-MIXSRC_FIRST_INPUT]; + if (trimIdx >= 0) { + int16_t trim = trims[trimIdx]; + if (trimIdx == THR_STICK && g_model.throttleReversed) + result -= trim; + else + result += trim; + } + } + return result; +} +#else + #define getValueForLogicalSwitch(i) getValue(i) #endif bool getLogicalSwitch(uint8_t idx) @@ -219,10 +237,10 @@ bool getLogicalSwitch(uint8_t idx) } #endif else { - getvalue_t x = getValue(ls->v1); + getvalue_t x = getValueForLogicalSwitch(ls->v1); getvalue_t y; if (s == LS_FAMILY_COMP) { - y = getValue(ls->v2); + y = getValueForLogicalSwitch(ls->v2); switch (ls->func) { case LS_FUNC_EQUAL: diff --git a/radio/src/tests/switches.cpp b/radio/src/tests/switches.cpp index 85344c517..4e52657c7 100644 --- a/radio/src/tests/switches.cpp +++ b/radio/src/tests/switches.cpp @@ -57,6 +57,7 @@ TEST(getSwitch, undefCSW) } #endif +#if !defined(CPUARM) TEST(getSwitch, circularCSW) { MODEL_RESET(); @@ -70,6 +71,7 @@ TEST(getSwitch, circularCSW) EXPECT_EQ(getSwitch(SWSRC_SW2), false); EXPECT_EQ(getSwitch(-SWSRC_SW2), true); } +#endif #if defined(PCBTARANIS) TEST(getSwitch, OldTypeStickyCSW) @@ -109,7 +111,6 @@ TEST(getSwitch, nullSW) EXPECT_EQ(getSwitch(0), true); } - #if defined(PCBTARANIS) && defined(FRSKY) TEST(getSwitch, VfasWithDelay) { @@ -340,3 +341,23 @@ TEST(getSwitch, recursiveSW) EXPECT_EQ(getSwitch(SWSRC_SW2), false); } #endif // #if !defined(CPUARM) + +#if defined(PCBTARANIS) +TEST(getSwitch, inputWithTrim) +{ + MODEL_RESET(); + modelDefault(0); + MIXER_RESET(); + + g_model.logicalSw[0] = { MIXSRC_FIRST_INPUT, 0, 0, LS_FUNC_VPOS }; + + doMixerCalculations(); + evalLogicalSwitches(); + EXPECT_EQ(getSwitch(SWSRC_SW1), false); + + setTrimValue(0, 0, 32); + doMixerCalculations(); + evalLogicalSwitches(); + EXPECT_EQ(getSwitch(SWSRC_SW1), true); +} +#endif