fix(radio): 2POS switch connected to 3POS socket may not behave as expected (#6067)

This commit is contained in:
philmoz
2025-04-11 12:57:31 +10:00
committed by GitHub
parent 31fe413190
commit 071a6ba805
2 changed files with 21 additions and 11 deletions
+11 -4
View File
@@ -727,18 +727,25 @@ bool getSwitch(swsrc_t swtch, uint8_t flags)
} else } else
#endif #endif
{ {
if (flags & GETSWITCH_MIDPOS_DELAY) {
result = SWITCH_POSITION(cs_idx);
} else {
div_t qr = div(cs_idx, 3); div_t qr = div(cs_idx, 3);
if (SWITCH_EXISTS(qr.quot)) { if (SWITCH_EXISTS(qr.quot)) {
auto sw_cfg = (SwitchConfig)SWITCH_CONFIG(qr.quot);
if (flags & GETSWITCH_MIDPOS_DELAY) {
result = SWITCH_POSITION(cs_idx);
// Handle 2POS switch installed in 3POS slot
if (!result && qr.rem == SWITCH_HW_DOWN && (sw_cfg == SWITCH_2POS || sw_cfg == SWITCH_TOGGLE))
result = SWITCH_POSITION(cs_idx - 1);
} else {
result = switchState(cs_idx); result = switchState(cs_idx);
// Handle 2POS switch installed in 3POS slot
if (!result && qr.rem == SWITCH_HW_DOWN && (sw_cfg == SWITCH_2POS || sw_cfg == SWITCH_TOGGLE))
result = switchState(cs_idx - 1);
}
} else { } else {
result = false; result = false;
} }
} }
} }
}
else if (cs_idx <= SWSRC_LAST_MULTIPOS_SWITCH) { else if (cs_idx <= SWSRC_LAST_MULTIPOS_SWITCH) {
result = POT_POSITION(cs_idx - SWSRC_FIRST_MULTIPOS_SWITCH); result = POT_POSITION(cs_idx - SWSRC_FIRST_MULTIPOS_SWITCH);
} }
+3
View File
@@ -810,12 +810,15 @@ TEST_F(MixerTest, DelayOnSwitch)
evalFlightModeMixes(e_perout_mode_normal, 1); evalFlightModeMixes(e_perout_mode_normal, 1);
EXPECT_EQ(chans[0], CHANNEL_MAX); EXPECT_EQ(chans[0], CHANNEL_MAX);
auto sw_cfg = (SwitchConfig)SWITCH_CONFIG(switch_index);
if (sw_cfg == SWITCH_3POS) {
simuSetSwitch(switch_index, 0); simuSetSwitch(switch_index, 0);
CHECK_DELAY(0, 500); CHECK_DELAY(0, 500);
evalFlightModeMixes(e_perout_mode_normal, 1); evalFlightModeMixes(e_perout_mode_normal, 1);
EXPECT_EQ(chans[0], 0); EXPECT_EQ(chans[0], 0);
} }
}
TEST_F(MixerTest, DelayOnSwitch2) TEST_F(MixerTest, DelayOnSwitch2)
{ {