fix(switches): widen fsPreviousState to 32-bit to fix toggle detection for more than 16 switches (#7560)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
norulers
2026-07-16 09:50:17 +10:00
committed by GitHub
co-authored by Claude Fable 5
parent c966bee5f2
commit 0a6d3d0f72
2 changed files with 45 additions and 3 deletions
+42
View File
@@ -428,3 +428,45 @@ TEST(FlexSwitches, getSwitch)
EXPECT_FALSE(getSwitch(SWSRC_FIRST_SWITCH + sw_idx * 3 + 1));
EXPECT_TRUE(getSwitch(SWSRC_FIRST_SWITCH + sw_idx * 3 + 2));
}
#if defined(FUNCTION_SWITCHES)
TEST(FunctionSwitches, holdIsNotRepeatedToggle)
{
MODEL_RESET();
setModelDefaults();
switchInit();
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
if (!switchIsCustomSwitch(i)) continue;
// Toggle type with no group, so a phantom "switch moved" event
// flips the logical state and is observable
g_model.cfsSetType(i, SWITCH_TOGGLE);
g_model.cfsSetGroup(i, 0);
simuSetSwitch(i, -1);
}
setFSStartupPosition();
evalFunctionSwitches(); // sync previous state with all switches released
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
if (!switchIsCustomSwitch(i)) continue;
bool released = g_model.cfsState(i);
simuSetSwitch(i, 1);
evalFunctionSwitches();
bool pressed = g_model.cfsState(i);
EXPECT_NE(released, pressed) << "press did not toggle switch index " << (int)i;
// holding the switch must not generate further toggles
evalFunctionSwitches();
EXPECT_EQ(pressed, g_model.cfsState(i))
<< "hold re-toggled switch index " << (int)i;
evalFunctionSwitches();
EXPECT_EQ(pressed, g_model.cfsState(i))
<< "hold re-toggled switch index " << (int)i;
simuSetSwitch(i, -1);
evalFunctionSwitches();
}
}
#endif