Use existing function to generate switch name in YAML switch warning field
This commit is contained in:
@@ -539,7 +539,7 @@ bool w_swtchWarn(const YamlNode* node, uint32_t val, yaml_writer_func wf, void*
|
||||
// state == 1 -> UP
|
||||
// state == 2 -> MIDDLE
|
||||
// state == 3 -> DOWN
|
||||
char swtchWarn[2] = {(char)('A' + i), 0};
|
||||
char swtchWarn[2] = {getRawSwitchFromIdx(i), 0};
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
|
||||
@@ -845,8 +845,8 @@ static void r_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
//
|
||||
swtchWarn = 0;
|
||||
while (val_len--) {
|
||||
signed swtch = *(val++) - 'A';
|
||||
if (swtch >= NUM_SWITCHES) break;
|
||||
signed swtch = getRawSwitchIdx(*(val++));
|
||||
if (swtch < 0) break;
|
||||
|
||||
unsigned state = 0;
|
||||
switch (*(val++)) {
|
||||
@@ -887,7 +887,7 @@ static bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
// state == 1 -> UP
|
||||
// state == 2 -> MIDDLE
|
||||
// state == 3 -> DOWN
|
||||
char swtchWarn[2] = {(char)('A' + i), 0};
|
||||
char swtchWarn[2] = {getRawSwitchFromIdx(i), 0};
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
|
||||
+40
-14
@@ -421,6 +421,45 @@ char *getFlightModeString(char *dest, int8_t idx)
|
||||
// }
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
int getRawSwitchIdx(char sw)
|
||||
{
|
||||
if (sw < 'A' || sw > 'Z')
|
||||
return -1;
|
||||
|
||||
#if defined(PCBX7) && !defined(RADIO_TX12)
|
||||
if (sw >= 'H')
|
||||
return sw - 'H' + 5;
|
||||
#if defined(RADIO_T12)
|
||||
else if (sw == 'G')
|
||||
#else
|
||||
else if (sw == 'F')
|
||||
#endif
|
||||
return 4;
|
||||
else
|
||||
return sw - 'A';
|
||||
#else
|
||||
return sw - 'A';
|
||||
#endif
|
||||
}
|
||||
|
||||
char getRawSwitchFromIdx(int idx)
|
||||
{
|
||||
#if defined(PCBX7) && !defined(RADIO_TX12)
|
||||
if (idx >= 5)
|
||||
return 'H' + idx - 5;
|
||||
else if (idx == 4)
|
||||
#if defined(RADIO_T12)
|
||||
return 'G';
|
||||
#else
|
||||
return 'F';
|
||||
#endif
|
||||
else
|
||||
return 'A' + idx;
|
||||
#else
|
||||
return 'A' + idx;
|
||||
#endif
|
||||
}
|
||||
|
||||
char *getSwitchName(char *dest, swsrc_t idx)
|
||||
{
|
||||
div_t swinfo = switchInfo(idx);
|
||||
@@ -429,20 +468,7 @@ char *getSwitchName(char *dest, swsrc_t idx)
|
||||
strAppend(dest, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME);
|
||||
} else {
|
||||
*dest++ = 'S';
|
||||
#if defined(PCBX7) && !defined(RADIO_TX12)
|
||||
if (swinfo.quot >= 5)
|
||||
*dest++ = 'H' + swinfo.quot - 5;
|
||||
else if (swinfo.quot == 4)
|
||||
#if defined(RADIO_T12)
|
||||
*dest++ = 'G';
|
||||
#else
|
||||
*dest++ = 'F';
|
||||
#endif
|
||||
else
|
||||
*dest++ = 'A' + swinfo.quot;
|
||||
#else
|
||||
*dest++ = 'A' + swinfo.quot;
|
||||
#endif
|
||||
*dest++ = getRawSwitchFromIdx(swinfo.quot);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ char *getGVarString(int idx);
|
||||
char *getSwitchPositionName(char *dest, swsrc_t idx);
|
||||
char *getSwitchName(char *dest, swsrc_t idx);
|
||||
char *getSourceString(char *dest, mixsrc_t idx);
|
||||
int getRawSwitchIdx(char sw);
|
||||
char getRawSwitchFromIdx(int sw);
|
||||
#endif
|
||||
|
||||
char *getFlightModeString(char *dest, int8_t idx);
|
||||
|
||||
Reference in New Issue
Block a user