From 99ed405b847ecc60491ba4a3697259bdee1d3de8 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 27 Apr 2022 09:14:42 +0200 Subject: [PATCH] fix: switch display --- radio/src/gui/128x64/model_setup.cpp | 11 ++++--- radio/src/gui/212x64/lcd.h | 2 ++ radio/src/gui/212x64/model_setup.cpp | 4 +-- radio/src/strhelpers.cpp | 48 +++++++++++++++++----------- radio/src/strhelpers.h | 2 ++ radio/src/switches.cpp | 9 +----- 6 files changed, 43 insertions(+), 33 deletions(-) diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index b35b070e4..726e3ea96 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -425,6 +425,7 @@ void editTimerCountdown(int timerIdx, coord_t y, LcdFlags attr, event_t event) #endif static const char* _pots_warn_modes[] = { "OFF", "Man", "Auto" }; +static const char* _fct_sw_start[] = { STR_CHAR_UP, STR_CHAR_DOWN, "=" }; void menuModelSetup(event_t event) { @@ -670,13 +671,13 @@ void menuModelSetup(event_t event) case ITEM_MODEL_SETUP_FS_STARTUP: { - char c; + const char* s; lcdDrawText(0, y, INDENT "Start", menuHorizontalPosition < 0 ? attr : 0); for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i++) { uint8_t startPos = (g_model.functionSwitchStartConfig >> 2 * i) & 0x03; - c = STR_CHAR_UP STR_CHAR_DOWN "="[(g_model.functionSwitchStartConfig >> 2 * i) & 0x03]; + s = _fct_sw_start[(g_model.functionSwitchStartConfig >> 2 * i) & 0x03]; lcdDrawNumber(MODEL_SETUP_2ND_COLUMN - (2 + FW) + i * 2 * FW, y, i + 1, 0); - lcdDrawChar(lcdNextPos, y, c, attr && (menuHorizontalPosition == i) ? (s_editMode ? INVERS + BLINK : INVERS) : 0); + lcdDrawText(lcdNextPos, y, s, attr && (menuHorizontalPosition == i) ? (s_editMode ? INVERS + BLINK : INVERS) : 0); if (attr && menuHorizontalPosition == i) { CHECK_INCDEC_MODELVAR(event, startPos, 0, 2); } @@ -855,12 +856,12 @@ void menuModelSetup(event_t event) s_editMode = 0; #endif } - c = (" " STR_CHAR_UP "-" STR_CHAR_DOWN)[states & 0x03]; lcdDrawSizedText( MODEL_SETUP_2ND_COLUMN + qr.rem * ((2 * FW) + 1), y + FH * qr.quot, FIRSTSW_STR[i] + sizeof(STR_CHAR_SWITCH) - 1, 1, attr && (menuHorizontalPosition == current) ? INVERS : 0); - lcdDrawChar(lcdNextPos, y + FH * qr.quot, c); + lcdDrawText(lcdNextPos, y + FH * qr.quot, + getSwitchWarnSymbol(states & 0x03)); ++current; } states >>= 3; diff --git a/radio/src/gui/212x64/lcd.h b/radio/src/gui/212x64/lcd.h index f24b48c9c..f75e98a47 100644 --- a/radio/src/gui/212x64/lcd.h +++ b/radio/src/gui/212x64/lcd.h @@ -250,6 +250,8 @@ public: skip(width - pos%width); } + void reset() { curPtr = src; } + private: enum State {RLE_FIRST_BYTE, RLE_SECOND_BYTE, RLE_CONTINUE} state; const uint8_t* src; diff --git a/radio/src/gui/212x64/model_setup.cpp b/radio/src/gui/212x64/model_setup.cpp index 324bb8a57..27e476377 100644 --- a/radio/src/gui/212x64/model_setup.cpp +++ b/radio/src/gui/212x64/model_setup.cpp @@ -752,12 +752,12 @@ void menuModelSetup(event_t event) g_model.switchWarningState |= (curr_state & 0x03) << (3 * i); storageDirty(EE_MODEL); } - c = (" " STR_CHAR_UP "-" STR_CHAR_DOWN)[states & 0x03]; lcdDrawChar( MODEL_SETUP_2ND_COLUMN + qr.rem * (2 * FW + 1), y + FH * qr.quot, 'A' + i, line && (menuHorizontalPosition == current) ? INVERS : 0); - lcdDrawChar(lcdNextPos, y + FH * qr.quot, c); + lcdDrawText(lcdNextPos, y + FH * qr.quot, + getSwitchWarnSymbol(states & 0x03)); ++current; } states >>= 3; diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index 7cb0432a3..a5fc4c6a2 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -477,6 +477,32 @@ char *getSwitchName(char *dest, swsrc_t idx) return dest; } +static const char* _switch_state_str[] { + " ", + STR_CHAR_UP, + "-", + STR_CHAR_DOWN, +}; + +const char* getSwitchWarnSymbol(uint8_t pos) +{ + // 0: NONE + // 1: UP + // 2: MIDDLE + // 3: DOWN + if (pos >= 4) return ""; + return _switch_state_str[pos]; +} + +const char* getSwitchPositionSymbol(uint8_t pos) +{ + // 0: UP + // 1: MIDDLE + // 2: DOWN + if (pos >= 3) return ""; + return _switch_state_str[pos + 1]; +} + char *getSwitchPositionName(char *dest, swsrc_t idx) { if (idx == SWSRC_NONE) { @@ -494,26 +520,12 @@ char *getSwitchPositionName(char *dest, swsrc_t idx) #define IDX_TRIMS_IN_STR_VSWITCHES (1) #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 defined(FUNCTION_SWITCHES) - if (idx >= SWSRC_FIRST_FUNCTION_SWITCH && idx <= (SWSRC_FIRST_FUNCTION_SWITCH + NUM_FUNCTIONS_SWITCHES)) { - s = getSwitchName(s, idx); - *s++ = (STR_CHAR_UP "-" STR_CHAR_DOWN)[swinfo.rem]; - *s = '\0'; - } - else { - s = getSwitchName(s, idx); - *s++ = (STR_CHAR_UP "-" STR_CHAR_DOWN)[swinfo.rem]; - *s = '\0'; - } -#else - s = getSwitchName(s, idx); - *s++ = (STR_CHAR_UP "-" STR_CHAR_DOWN)[swinfo.rem]; - *s = '\0'; -#endif - + s = getSwitchName(s, idx); + s = strAppend(s, getSwitchPositionSymbol(swinfo.rem), 2); + *s = '\0'; } #if NUM_XPOTS > 0 diff --git a/radio/src/strhelpers.h b/radio/src/strhelpers.h index c4e14989b..ba26e9237 100644 --- a/radio/src/strhelpers.h +++ b/radio/src/strhelpers.h @@ -76,6 +76,8 @@ char *getFormattedTimerString(char *dest, int32_t tme, TimerOptions timerOptions char *getCurveString(char *dest, int idx); char *getGVarString(char *dest, int idx); char *getGVarString(int idx); +const char* getSwitchWarnSymbol(uint8_t pos); +const char* getSwitchPositionSymbol(uint8_t pos); char *getSwitchPositionName(char *dest, swsrc_t idx); char *getSwitchName(char *dest, swsrc_t idx); diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index b2e2920d4..8678194ba 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -746,13 +746,6 @@ void checkSwitches() } #elif defined(GUI) -static const char* switch_state_str[] { - " ", - STR_CHAR_UP, - "-", - STR_CHAR_DOWN, -}; - void checkSwitches() { swarnstate_t last_bad_switches = 0xff; @@ -788,7 +781,7 @@ void checkSwitches() ((states & mask) == (switches_states & mask)) ? 0 : INVERS; if (attr) { if (++numWarnings < 6) { - const char* s = switch_state_str[(states & mask) >> (i * 3)]; + const char* s = getSwitchWarnSymbol((states & mask) >> (i * 3)); drawSource(x, y, MIXSRC_FIRST_SWITCH + i, attr); lcdDrawText(lcdNextPos, y, s, attr); x = lcdNextPos + 3;