From 7b7186e29397396ee55b0b9ce3db820ba6501bbf Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Tue, 10 Mar 2026 04:37:10 +0100 Subject: [PATCH] Improve one and two-letter scan list names (issue #206) --- App/ui/helper.c | 10 ++++++++++ App/ui/helper.h | 1 + App/ui/main.c | 2 +- App/ui/menu.c | 4 ++-- App/ui/status.c | 5 +---- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/App/ui/helper.c b/App/ui/helper.c index 252a7c15..764de28f 100644 --- a/App/ui/helper.c +++ b/App/ui/helper.c @@ -321,6 +321,16 @@ static void sort(int16_t *a, int16_t *b) x += 4; } } + + bool IsEmptyName(const char *name, uint8_t len) { + if (name[0] == '\0' || name[0] == '\xff') + return true; + for (uint8_t i = 0; i < len; i++) { + if (name[i] != ' ' && name[i] != '\xff' && name[i] != '\0') + return false; + } + return true; + } #endif void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black) diff --git a/App/ui/helper.h b/App/ui/helper.h index 302d375c..267a158e 100644 --- a/App/ui/helper.h +++ b/App/ui/helper.h @@ -38,6 +38,7 @@ void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black void PutPixel(uint8_t x, uint8_t y, bool fill); void PutPixelStatus(uint8_t x, uint8_t y, bool fill); void GUI_DisplaySmallest(const char *pString, uint8_t x, uint8_t y, bool statusbar, bool fill); + bool IsEmptyName(const char *name, uint8_t len); #endif void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black); void UI_DrawRectangleBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black); diff --git a/App/ui/main.c b/App/ui/main.c index f17456a6..5db22460 100644 --- a/App/ui/main.c +++ b/App/ui/main.c @@ -976,7 +976,7 @@ void UI_DisplayMain(void) const char *name = gListName[countList - 1]; // If name is empty/invalid, display number - if (name[0] == '\0' || name[0] == '\xff') { + if (IsEmptyName(name, sizeof(gListName[0]))) { sprintf(String, "%02d", countList); xStart = 117; // 2-digit number aligned right xDisplay = 119; diff --git a/App/ui/menu.c b/App/ui/menu.c index c9d22b01..a9b486ed 100644 --- a/App/ui/menu.c +++ b/App/ui/menu.c @@ -976,7 +976,7 @@ void UI_DisplayMenu(void) const char *name = gListName[gSubMenuSelection - 1]; // If first character is empty/invalid, display "N/A" - if (name[0] == '\0' || name[0] == '\xff') + if (IsEmptyName(name, sizeof(gListName[0]))) sprintf(String, "%02u", gSubMenuSelection); else sprintf(String, "%02u (%.3s)", gSubMenuSelection, name); @@ -989,7 +989,7 @@ void UI_DisplayMenu(void) else { const char *name = gListName[gSubMenuSelection - 1]; // If first character is empty/invalid, display "N/A" - if (name[0] == '\0' || name[0] == '\xff') + if (IsEmptyName(name, sizeof(gListName[0]))) sprintf(String, "%02u", gSubMenuSelection); else sprintf(String, "%02u (%.3s)", gSubMenuSelection, name); diff --git a/App/ui/status.c b/App/ui/status.c index 1f2de5a8..cb37526e 100644 --- a/App/ui/status.c +++ b/App/ui/status.c @@ -114,10 +114,7 @@ void UI_DisplayStatus() const char *name = gListName[gEeprom.SCAN_LIST_DEFAULT - 1]; // Check if name is valid - bool nameValid = (name[0] != '\0' && name[0] != '\xff'); - - // Format the string - if (nameValid) { + if (!IsEmptyName(name, sizeof(gListName[0]))) { sprintf(str, "%.3s%s", name, gEeprom.SCAN_LIST_ENABLED ? "+" : ""); end = gEeprom.SCAN_LIST_ENABLED ? 18 : 14; }