diff --git a/radio/src/gui/128x64/lcd.cpp b/radio/src/gui/128x64/lcd.cpp index 4cbcd4669..c3722475c 100644 --- a/radio/src/gui/128x64/lcd.cpp +++ b/radio/src/gui/128x64/lcd.cpp @@ -791,7 +791,7 @@ void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att) void drawSwitch(coord_t x, coord_t y, swsrc_t idx, LcdFlags flags) { char s[8]; - getSwitchString(s, idx); + getSwitchPositionName(s, idx); lcdDrawText(x, y, s, flags); } diff --git a/radio/src/gui/212x64/lcd.cpp b/radio/src/gui/212x64/lcd.cpp index e71fda26b..56492e5c5 100644 --- a/radio/src/gui/212x64/lcd.cpp +++ b/radio/src/gui/212x64/lcd.cpp @@ -696,7 +696,7 @@ void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att) void drawSwitch(coord_t x, coord_t y, int32_t idx, LcdFlags flags) { char s[8]; - getSwitchString(s, idx); + getSwitchPositionName(s, idx); lcdDrawText(x, y, s, flags); } diff --git a/radio/src/gui/480x272/lcd.cpp b/radio/src/gui/480x272/lcd.cpp index a614eda90..c260bf54b 100644 --- a/radio/src/gui/480x272/lcd.cpp +++ b/radio/src/gui/480x272/lcd.cpp @@ -290,7 +290,7 @@ void putsModelName(coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att) void drawSwitch(coord_t x, coord_t y, swsrc_t idx, LcdFlags flags) { char s[8]; - getSwitchString(s, idx); + getSwitchPositionName(s, idx); lcdDrawText(x, y, s, flags); } diff --git a/radio/src/logs.cpp b/radio/src/logs.cpp index 0ac375041..822f5e7b4 100644 --- a/radio/src/logs.cpp +++ b/radio/src/logs.cpp @@ -22,20 +22,21 @@ #include "ff.h" FIL g_oLogFile __DMA; -const char * g_logError = NULL; +const char * g_logError = nullptr; uint8_t logDelay; void writeHeader(); #if defined(PCBTARANIS) || defined(PCBHORUS) - #define GET_2POS_STATE(sw) (switchState(SW_ ## sw ## 0) ? -1 : 1) + int getSwitchState(uint8_t swtch) { + int value = getValue(MIXSRC_FIRST_SWITCH + swtch); + return (value == 0) ? 0 : (value < 0) ? -1 : +1; + } #else #define GET_2POS_STATE(sw) (switchState(SW_ ## sw) ? -1 : 1) + #define GET_3POS_STATE(sw) (switchState(SW_ ## sw ## 0) ? -1 : (switchState(SW_ ## sw ## 2) ? 1 : 0)) #endif -#define GET_3POS_STATE(sw) (switchState(SW_ ## sw ## 0) ? -1 : (switchState(SW_ ## sw ## 2) ? 1 : 0)) - - void logsInit() { memset(&g_oLogFile, 0, sizeof(g_oLogFile)); @@ -108,7 +109,7 @@ const char * logsOpen() writeHeader(); } - return NULL; + return nullptr; } tmr10ms_t lastLogTime = 0; @@ -166,18 +167,18 @@ void writeHeader() } f_putc(',', &g_oLogFile); } -#if defined(PCBX7) - #define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD,SF,SH" -#elif defined(PCBXLITE) - #define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD" -#elif defined(PCBXLITES) - #define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD,SE,SF" -#elif defined(PCBX9LITE) - #define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SE,SF" -#else - #define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD,SE,SF,SG,SH" -#endif - f_puts(STR_SWITCHES_LOG_HEADER ",LSW,", &g_oLogFile); + + for (uint8_t i=0; i 0) { tmr10ms_t tmr10ms = get_tmr10ms(); @@ -205,7 +206,7 @@ void logsWrite() if (!g_oLogFile.obj.fs) { const char * result = logsOpen(); - if (result != NULL) { + if (result) { if (result != error_displayed) { error_displayed = result; POPUP_WARNING(result); @@ -272,46 +273,13 @@ void logsWrite() f_printf(&g_oLogFile, "%d,", calibratedAnalogs[i]); } -// TODO: use hardware config to populate -#if defined(PCBX9LITE) - f_printf(&g_oLogFile, "%d,%d,%d,%d,0x%08X%08X,", - GET_3POS_STATE(SA), - GET_3POS_STATE(SB), - GET_3POS_STATE(SC), - GET_2POS_STATE(SD), - GET_2POS_STATE(SE), - getLogicalSwitchesStates(32), - getLogicalSwitchesStates(0)); -#elif defined(PCBXLITE) - f_printf(&g_oLogFile, "%d,%d,%d,%d,0x%08X%08X,", - GET_3POS_STATE(SA), - GET_3POS_STATE(SB), - GET_3POS_STATE(SC), - GET_3POS_STATE(SD), - getLogicalSwitchesStates(32), - getLogicalSwitchesStates(0)); -#elif defined(PCBX7) - f_printf(&g_oLogFile, "%d,%d,%d,%d,%d,%d,0x%08X%08X,", - GET_3POS_STATE(SA), - GET_3POS_STATE(SB), - GET_3POS_STATE(SC), - GET_3POS_STATE(SD), - GET_2POS_STATE(SF), - GET_2POS_STATE(SH), - getLogicalSwitchesStates(32), - getLogicalSwitchesStates(0)); -#elif defined(PCBTARANIS) || defined(PCBHORUS) - f_printf(&g_oLogFile, "%d,%d,%d,%d,%d,%d,%d,%d,0x%08X%08X,", - GET_3POS_STATE(SA), - GET_3POS_STATE(SB), - GET_3POS_STATE(SC), - GET_3POS_STATE(SD), - GET_3POS_STATE(SE), - GET_2POS_STATE(SF), - GET_3POS_STATE(SG), - GET_2POS_STATE(SH), - getLogicalSwitchesStates(32), - getLogicalSwitchesStates(0)); +#if defined(PCBTARANIS) || defined(PCBHORUS) + for (uint8_t i=0; i= 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 + } + return dest; +} +#endif + +char * getSwitchPositionName(char * dest, swsrc_t idx) { if (idx == SWSRC_NONE) { return getStringAtIndex(dest, STR_VSWITCHES, 0); @@ -267,27 +296,7 @@ char * getSwitchString(char * dest, swsrc_t idx) #define IDX_ON_IN_STR_VSWITCHES (IDX_TRIMS_IN_STR_VSWITCHES+SWSRC_LAST_TRIM-SWSRC_FIRST_TRIM+1) if (idx <= SWSRC_LAST_SWITCH) { div_t swinfo = switchInfo(idx); - if (ZEXIST(g_eeGeneral.switchNames[swinfo.quot])) { - s += zchar2str(s, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME); - // TODO tous zchar2str - } - else { - *s++ = 'S'; -#if defined(PCBX7) - if (swinfo.quot >= 5) - *s++ = 'H' + swinfo.quot - 5; - else if (swinfo.quot == 4) -#if defined(RADIO_T12) - *s++ = 'G'; -#else - *s++ = 'F'; -#endif - else - *s++ = 'A'+swinfo.quot; -#else - *s++ = 'A' + swinfo.quot; -#endif - } + s = getSwitchName(s, idx); *s++ = "\300-\301"[swinfo.rem]; *s = '\0'; } @@ -396,7 +405,7 @@ char * getSourceString(char * dest, mixsrc_t idx) } } else if (idx <= MIXSRC_LAST_LOGICAL_SWITCH) { - getSwitchString(dest, SWSRC_SW1 + idx - MIXSRC_SW1); + getSwitchPositionName(dest, SWSRC_SW1 + idx - MIXSRC_SW1); } else if (idx <= MIXSRC_LAST_TRAINER) { strAppendStringWithIndex(dest, STR_PPM_TRAINER, idx - MIXSRC_FIRST_TRAINER + 1); diff --git a/radio/src/strhelpers.h b/radio/src/strhelpers.h index e9e45425d..114d7a009 100644 --- a/radio/src/strhelpers.h +++ b/radio/src/strhelpers.h @@ -35,7 +35,8 @@ char * strAppendStringWithIndex(char * dest, const char * s, int idx); char * getTimerString(char * dest, int32_t tme, uint8_t hours=0); char * getCurveString(char * dest, int idx); char * getGVarString(char * dest, int idx); -char * getSwitchString(char * dest, swsrc_t idx); +char * getSwitchPositionName(char * dest, swsrc_t idx); +char * getSwitchName(char * dest, swsrc_t idx); char * getSourceString(char * dest, mixsrc_t idx); #endif