fix(radio): 2POS switch connected to 3POS socket may not behave as expected (#6067)
This commit is contained in:
+14
-7
@@ -727,15 +727,22 @@ bool getSwitch(swsrc_t swtch, uint8_t flags)
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (flags & GETSWITCH_MIDPOS_DELAY) {
|
div_t qr = div(cs_idx, 3);
|
||||||
result = SWITCH_POSITION(cs_idx);
|
if (SWITCH_EXISTS(qr.quot)) {
|
||||||
} else {
|
auto sw_cfg = (SwitchConfig)SWITCH_CONFIG(qr.quot);
|
||||||
div_t qr = div(cs_idx, 3);
|
if (flags & GETSWITCH_MIDPOS_DELAY) {
|
||||||
if (SWITCH_EXISTS(qr.quot)) {
|
result = SWITCH_POSITION(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 = SWITCH_POSITION(cs_idx - 1);
|
||||||
} else {
|
} else {
|
||||||
result = false;
|
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 {
|
||||||
|
result = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -810,11 +810,14 @@ 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);
|
||||||
|
|
||||||
simuSetSwitch(switch_index, 0);
|
auto sw_cfg = (SwitchConfig)SWITCH_CONFIG(switch_index);
|
||||||
CHECK_DELAY(0, 500);
|
if (sw_cfg == SWITCH_3POS) {
|
||||||
|
simuSetSwitch(switch_index, 0);
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user