[tpro] fix function switch behaviours and add always on capability (#1479)

* fix: tpro function switch toggle mode

* feat: Function switches now have alway on option

* Companion support for function switch always on

* Fix nasty eeprom error

* Update fs startup item model

* Fix Tpro SWITCH_EXISTS

Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
Peter Feerick
2022-01-23 18:42:31 +10:00
committed by GitHub
co-authored by 3djc elecpower
parent c6a9101314
commit d1ef6f866c
8 changed files with 98 additions and 33 deletions
+10 -6
View File
@@ -122,21 +122,25 @@ void evalFunctionSwitches()
uint8_t physicalState = getFSPhysicalState(i);
if (physicalState != getFSPreviousPhysicalState(i)) { // FS was moved
if (FSWITCH_CONFIG(i) == SWITCH_2POS && physicalState == 1) {
g_model.functionSwitchLogicalState ^= 1 << i; // Toggle bit
}
else if (FSWITCH_CONFIG(i) == SWITCH_TOGGLE) {
g_model.functionSwitchLogicalState ^= (physicalState ^ g_model.functionSwitchLogicalState) & (1 << i); // Set bit to switch value
if ((FSWITCH_CONFIG(i) == SWITCH_2POS && physicalState == 1) || (FSWITCH_CONFIG(i) == SWITCH_TOGGLE)) {
if (IS_FSWITCH_GROUP_ON(FSWITCH_GROUP(i)) != 0) { // In an always on group
g_model.functionSwitchLogicalState |= 1 << i; // Set bit
}
else {
g_model.functionSwitchLogicalState ^= 1 << i; // Toggle bit
}
}
if (FSWITCH_GROUP(i) && physicalState == 1) { // switch is in a group, other in group need to be turned off
for (uint8_t j = 0; j < NUM_FUNCTIONS_SWITCHES; j++) {
if (i == j)
if (i == j)
continue;
if (FSWITCH_GROUP(j) == FSWITCH_GROUP(i)) {
g_model.functionSwitchLogicalState &= ~(1 << j); // clear state
}
}
}
fsPreviousState ^= 1 << i; // Toggle state
storageDirty(EE_MODEL);
}