feat: customisable switch generated source groups (#5016)
Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
@@ -514,6 +514,10 @@ enum MixSources {
|
||||
MIXSRC_FIRST_SWITCH SKIP,
|
||||
MIXSRC_LAST_SWITCH SKIP = MIXSRC_FIRST_SWITCH + MAX_SWITCHES - 1,
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
MIXSRC_FIRST_CUSTOMSWITCH_GROUP SKIP,
|
||||
MIXSRC_LAST_CUSTOMSWITCH_GROUP SKIP = MIXSRC_FIRST_CUSTOMSWITCH_GROUP + NUM_FUNCTIONS_GROUPS - 1,
|
||||
#endif
|
||||
MIXSRC_FIRST_LOGICAL_SWITCH SKIP,
|
||||
MIXSRC_LAST_LOGICAL_SWITCH SKIP = MIXSRC_FIRST_LOGICAL_SWITCH + MAX_LOGICAL_SWITCHES - 1,
|
||||
|
||||
|
||||
@@ -241,6 +241,11 @@ bool isSourceAvailable(int source)
|
||||
if (source >= MIXSRC_FIRST_TRAINER && source <= MIXSRC_LAST_TRAINER)
|
||||
return g_model.trainerData.mode > 0;
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
if (source >= MIXSRC_FIRST_CUSTOMSWITCH_GROUP && source <= MIXSRC_LAST_CUSTOMSWITCH_GROUP)
|
||||
return getSwitchCountInFSGroup(source - MIXSRC_FIRST_CUSTOMSWITCH_GROUP + 1) > 0;
|
||||
#endif
|
||||
|
||||
if (source >= MIXSRC_FIRST_CH && source <= MIXSRC_LAST_CH) {
|
||||
return isChannelUsed(source - MIXSRC_FIRST_CH);
|
||||
}
|
||||
@@ -323,6 +328,11 @@ bool isSourceAvailableInInputs(int source)
|
||||
if (source >= MIXSRC_FIRST_SWITCH && source <= MIXSRC_LAST_SWITCH)
|
||||
return SWITCH_EXISTS(source - MIXSRC_FIRST_SWITCH);
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
if (source >= MIXSRC_FIRST_CUSTOMSWITCH_GROUP && source <= MIXSRC_LAST_CUSTOMSWITCH_GROUP)
|
||||
return getSwitchCountInFSGroup(source - MIXSRC_FIRST_CUSTOMSWITCH_GROUP + 1) > 0;
|
||||
#endif
|
||||
|
||||
if (source >= MIXSRC_FIRST_CH && source <= MIXSRC_LAST_CH)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -425,6 +425,30 @@ getvalue_t _getValue(mixsrc_t i, bool* valid)
|
||||
return _switch_3pos_lookup[switchGetPosition(sw_idx)];
|
||||
}
|
||||
}
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
else if (i <= MIXSRC_LAST_CUSTOMSWITCH_GROUP) {
|
||||
uint8_t group_idx = (uint8_t)(i - MIXSRC_FIRST_CUSTOMSWITCH_GROUP + 1);
|
||||
uint8_t stepcount = getSwitchCountInFSGroup(group_idx);
|
||||
if (stepcount == 0)
|
||||
return 0;
|
||||
|
||||
if (IS_FSWITCH_GROUP_ON(group_idx))
|
||||
stepcount--;
|
||||
|
||||
int stepsize = (2 * RESX) / stepcount;
|
||||
int value = -RESX;
|
||||
|
||||
for (uint8_t i = 0; i < switchGetMaxFctSwitches(); i++) {
|
||||
if(FSWITCH_GROUP(i) == group_idx) {
|
||||
if (getFSLogicalState(i) == 1)
|
||||
return value + (IS_FSWITCH_GROUP_ON(group_idx) ? 0 : stepsize);
|
||||
else
|
||||
value += stepsize;
|
||||
}
|
||||
}
|
||||
return -RESX;
|
||||
}
|
||||
#endif
|
||||
|
||||
else if (i <= MIXSRC_LAST_LOGICAL_SWITCH) {
|
||||
return getSwitch(SWSRC_FIRST_LOGICAL_SWITCH + i - MIXSRC_FIRST_LOGICAL_SWITCH) ? 1024 : -1024;
|
||||
|
||||
@@ -215,7 +215,15 @@ static uint32_t r_mixSrcRaw(const YamlNode* node, const char* val, uint8_t val_l
|
||||
val += 3; val_len -= 3;
|
||||
// parse int and ignore closing ')'
|
||||
return yaml_str2uint(val, val_len) + MIXSRC_FIRST_GVAR;
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
} else if (val_len > 2 &&
|
||||
val[0] == 'G' &&
|
||||
val[1] == 'R' &&
|
||||
val[2] >= '1' &&
|
||||
val[2] <= '3') {
|
||||
|
||||
return MIXSRC_FIRST_CUSTOMSWITCH_GROUP + (val[2] - '1');
|
||||
#endif
|
||||
} else if (val_len > 5 &&
|
||||
val[0] == 't' &&
|
||||
val[1] == 'e' &&
|
||||
@@ -353,6 +361,12 @@ static bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf,
|
||||
&& val <= MIXSRC_LAST_SWITCH) {
|
||||
str = switchGetCanonicalName(val - MIXSRC_FIRST_SWITCH);
|
||||
}
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
else if (val >= MIXSRC_FIRST_CUSTOMSWITCH_GROUP
|
||||
&& val <= MIXSRC_LAST_CUSTOMSWITCH_GROUP) {
|
||||
str = fsSwitchGroupGetCanonicalName(val - MIXSRC_FIRST_CUSTOMSWITCH_GROUP);
|
||||
}
|
||||
#endif
|
||||
else if (val >= MIXSRC_FIRST_LOGICAL_SWITCH
|
||||
&& val <= MIXSRC_LAST_LOGICAL_SWITCH) {
|
||||
|
||||
|
||||
@@ -450,6 +450,13 @@ char *getFlightModeString(char *dest, int8_t idx)
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *getCustomSwitchesGroupName(char *dest, uint8_t idx)
|
||||
{
|
||||
dest = strAppendStringWithIndex(dest, "GR", idx + 1);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *getSwitchName(char *dest, uint8_t idx)
|
||||
{
|
||||
if (switchHasCustomName(idx)) {
|
||||
@@ -738,6 +745,12 @@ char *getSourceString(char (&destRef)[L], mixsrc_t idx)
|
||||
idx -= MIXSRC_FIRST_SWITCH;
|
||||
char *pos = strAppend(dest, STR_CHAR_SWITCH, sizeof(STR_CHAR_SWITCH) - 1);
|
||||
getSwitchName(pos, idx);
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
} else if (idx <= MIXSRC_LAST_CUSTOMSWITCH_GROUP) {
|
||||
idx -= MIXSRC_FIRST_CUSTOMSWITCH_GROUP;
|
||||
char *pos = strAppend(dest, STR_CHAR_SWITCH, sizeof(STR_CHAR_SWITCH) - 1);
|
||||
getCustomSwitchesGroupName(pos, idx);
|
||||
#endif
|
||||
} else if (idx <= MIXSRC_LAST_LOGICAL_SWITCH) {
|
||||
// TODO: unnecessary, use the direct way instead
|
||||
idx -= MIXSRC_FIRST_LOGICAL_SWITCH;
|
||||
|
||||
@@ -109,6 +109,7 @@ const char *getMainControlLabel(uint8_t idx);
|
||||
const char *getTrimLabel(uint8_t idx);
|
||||
const char *getTrimSourceLabel(uint16_t src_raw, int8_t trim_src);
|
||||
const char *getPotLabel(uint8_t idx);
|
||||
char *getCustomSwitchesGroupName(char *dest, uint8_t idx);
|
||||
|
||||
template <size_t L>
|
||||
char *getSourceString(char (&dest)[L], mixsrc_t idx);
|
||||
|
||||
@@ -136,6 +136,23 @@ uint8_t getFSPreviousPhysicalState(uint8_t index)
|
||||
return (uint8_t )(bfSingleBitGet(fsPreviousState, index) >> (index));
|
||||
}
|
||||
|
||||
uint8_t getSwitchCountInFSGroup(uint8_t index)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
|
||||
for (uint8_t i = 0; i < switchGetMaxFctSwitches(); i++) {
|
||||
if (FSWITCH_GROUP(i) == index)
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool isFSGroupUsed(uint8_t index)
|
||||
{
|
||||
return getSwitchCountInFSGroup(index) != 0;
|
||||
}
|
||||
|
||||
void evalFunctionSwitches()
|
||||
{
|
||||
uint8_t fct_switches = switchGetMaxFctSwitches();
|
||||
@@ -312,6 +329,13 @@ const char* switchGetCanonicalName(uint8_t idx)
|
||||
return switchGetName(idx);
|
||||
}
|
||||
|
||||
const char* fsSwitchGroupGetCanonicalName(uint8_t idx)
|
||||
{
|
||||
static const char fsgroupname[3][4] = {"GR1", "GR2", "GR3"};
|
||||
|
||||
return &fsgroupname[idx][0];
|
||||
}
|
||||
|
||||
SwitchConfig switchGetMaxType(uint8_t idx)
|
||||
{
|
||||
auto hw_type = switchGetHwType(idx);
|
||||
|
||||
@@ -79,9 +79,11 @@ char switchGetLetter(uint8_t idx);
|
||||
const char* switchGetCanonicalName(uint8_t idx);
|
||||
|
||||
// customizable switches supported
|
||||
const char* fsSwitchGroupGetCanonicalName(uint8_t idx);
|
||||
void switchSetCustomName(uint8_t idx, const char* str, size_t len);
|
||||
const char* switchGetCustomName(uint8_t idx);
|
||||
bool switchHasCustomName(uint8_t idx);
|
||||
uint8_t getSwitchCountInFSGroup(uint8_t index);
|
||||
|
||||
SwitchConfig switchGetMaxType(uint8_t idx);
|
||||
|
||||
|
||||
@@ -328,6 +328,7 @@ void bluetoothDisable();
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define NUM_FUNCTIONS_SWITCHES 6
|
||||
#define NUM_FUNCTIONS_GROUPS 3
|
||||
#define DEFAULT_FS_CONFIG \
|
||||
(SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_2POS << 6) + \
|
||||
(SWITCH_2POS << 4) + (SWITCH_2POS << 2) + (SWITCH_2POS << 0)
|
||||
|
||||
@@ -110,6 +110,7 @@ uint32_t isBootloaderStart(const uint8_t * buffer);
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
|
||||
#define NUM_FUNCTIONS_SWITCHES 6
|
||||
#define NUM_FUNCTIONS_GROUPS 3
|
||||
|
||||
#define DEFAULT_FS_CONFIG \
|
||||
(SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_2POS << 6) + \
|
||||
|
||||
Reference in New Issue
Block a user