[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:
co-authored by
3djc
elecpower
parent
c6a9101314
commit
d1ef6f866c
@@ -256,7 +256,7 @@ inline uint8_t MODULE_SUBTYPE_ROWS(int moduleIdx)
|
||||
#endif
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define FUNCTION_SWITCHES_ROWS READONLY_ROW, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|(NUM_FUNCTIONS_SWITCHES-1),
|
||||
#define FUNCTION_SWITCHES_ROWS READONLY_ROW, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|(NUM_FUNCTIONS_SWITCHES-1),
|
||||
#else
|
||||
#define FUNCTION_SWITCHES_ROWS
|
||||
#endif
|
||||
@@ -631,11 +631,23 @@ void menuModelSetup(event_t event)
|
||||
}
|
||||
|
||||
config = FSWITCH_GROUP(index);
|
||||
config = editChoice(30 + 15*FW, y, "", STR_FSGROUPS, config, 0, 3, menuHorizontalPosition == 2 ? attr : 0, event);
|
||||
config = editChoice(30 + 13 * FW, y, "", STR_FSGROUPS, config, 0, 3, menuHorizontalPosition == 2 ? attr : 0, event);
|
||||
if (attr && checkIncDec_Ret && menuHorizontalPosition == 2) {
|
||||
swconfig_t mask = (swconfig_t) 0x03 << (2 * index);
|
||||
g_model.functionSwitchGroup = (g_model.functionSwitchGroup & ~mask) | ((swconfig_t(config) & 0x03) << (2 * index));
|
||||
}
|
||||
|
||||
if (FSWITCH_GROUP(index)) {
|
||||
uint8_t groupeAlwaysOn = IS_FSWITCH_GROUP_ON(config);
|
||||
groupeAlwaysOn = editCheckBox(groupeAlwaysOn, 30 + 15 * FW, y, "", menuHorizontalPosition == 3 ? attr : 0, event);
|
||||
if (attr && checkIncDec_Ret && menuHorizontalPosition == 3) {
|
||||
swconfig_t mask = (swconfig_t) 0x01 << (2 * NUM_FUNCTIONS_SWITCHES + config);
|
||||
g_model.functionSwitchGroup = (g_model.functionSwitchGroup & ~mask) | (groupeAlwaysOn << (2 * NUM_FUNCTIONS_SWITCHES + config));
|
||||
}
|
||||
}
|
||||
else if (attr && menuHorizontalPosition == 3) { // Non visible checkbox
|
||||
REPEAT_LAST_CURSOR_MOVE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,9 @@
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define FSWITCH_CONFIG(x) (bfGet<swconfig_t>(g_model.functionSwitchConfig, 2*(x), 2))
|
||||
#define FSWITCH_GROUP(x) (bfGet<swconfig_t>(g_model.functionSwitchGroup, 2*(x), 2))
|
||||
#define IS_FSWITCH_GROUP_ON(x) (bfGet<swconfig_t>(g_model.functionSwitchGroup, 2 * NUM_FUNCTIONS_SWITCHES + x, 1))
|
||||
#define IS_SWITCH_FS(x) (x >= NUM_REGULAR_SWITCHES)
|
||||
#define SWITCH_EXISTS(x) (IS_SWITCH_FS(x) ? true : (FSWITCH_CONFIG(x) != SWITCH_NONE))
|
||||
#define SWITCH_EXISTS(x) (IS_SWITCH_FS(x) ? true : (SWITCH_CONFIG(x) != SWITCH_NONE))
|
||||
#define IS_CONFIG_3POS(x) (IS_SWITCH_FS(x) ? (FSWITCH_CONFIG(x - NUM_REGULAR_SWITCHES) == SWITCH_3POS) : (SWITCH_CONFIG(x) == SWITCH_3POS))
|
||||
#define IS_CONFIG_TOGGLE(x) (IS_SWITCH_FS(x) ? (FSWITCH_CONFIG(x - NUM_REGULAR_SWITCHES) == SWITCH_TOGGLE) : (SWITCH_CONFIG(x) == SWITCH_TOGGLE))
|
||||
#else
|
||||
|
||||
+10
-6
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user