From 9f9f0a3c38643c6cdc12ee3ee511a776d44ddf2e Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 6 Aug 2024 12:09:59 +1000 Subject: [PATCH 1/3] Change char selection order when editing names. --- .../src/gui/common/stdlcd/draw_functions.cpp | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/radio/src/gui/common/stdlcd/draw_functions.cpp b/radio/src/gui/common/stdlcd/draw_functions.cpp index 444d77c67bd..5694178cc70 100644 --- a/radio/src/gui/common/stdlcd/draw_functions.cpp +++ b/radio/src/gui/common/stdlcd/draw_functions.cpp @@ -159,26 +159,17 @@ char getPreviousChar(char c, uint8_t position) return c - 1; } -static bool isNameCharset(int v) -{ - char c = (char)v; - - if (c == ' ') - return true; - - if (c == '-') - return true; +static const char nameChars[] = " abcdefghijklmnopqrstuvwxyz0123456789-,."; - if (c >= '0' && c <= '9') - return true; - - if (c >= 'A' && c <= 'Z') - return true; - - if (c >= 'a' && c <= 'z') - return true; - - return false; +static int nameCharIdx(char v) +{ + if (islower(v)) return v - 'a' + 1; + if (isupper(v)) return v - 'A' + 1; + if (isdigit(v)) return v - '0' + 27; + if (v == '-') return 37; + if (v == ',') return 38; + if (v == '.') return 39; + return 0; } void editName(coord_t x, coord_t y, char* name, uint8_t size, event_t event, @@ -202,7 +193,9 @@ void editName(coord_t x, coord_t y, char* name, uint8_t size, event_t event, int8_t v = c ? c : ' '; if (IS_NEXT_EVENT(event) || IS_PREVIOUS_EVENT(event)) { - v = checkIncDec(event, abs(v), ' ', 'z', 0, isNameCharset); + bool caps = isupper(v); + v = nameChars[checkIncDec(event, nameCharIdx(v), 0, DIM(nameChars)-2)]; + if (caps && islower(v)) v = toupper(v); } switch (event) { From 5aa93be7e8a75e5fa428589240ea92ea9b388a60 Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 6 Aug 2024 16:12:25 +1000 Subject: [PATCH 2/3] Update Companion to allow extra valid characters. --- companion/src/shared/namevalidator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/shared/namevalidator.h b/companion/src/shared/namevalidator.h index 2b4dff10b34..a40202db2e6 100644 --- a/companion/src/shared/namevalidator.h +++ b/companion/src/shared/namevalidator.h @@ -25,7 +25,7 @@ #include "textvalidator.h" // characters supportd by B&W radio firmware gui editor -constexpr char NAME_VALID_PATTERN_BW[] {"[ A-Za-z0-9\\-]*"}; +constexpr char NAME_VALID_PATTERN_BW[] {"[ A-Za-z0-9\\-\\,\\.]*"}; // characters supported by color radio firmware keyboard widget constexpr char NAME_VALID_PATTERN_COLOR[] {"[ A-Za-z0-9\\-\\_\\,\\.\"\\+\\/\\*\\=\\%\\!\\?\\#\\<\\>\\@\\$\\(\\)\\{\\}\\[\\]\\;\\:\\']*"}; From 5d171b6b4f6bf5bb71f77f50eb59c81278da4cd9 Mon Sep 17 00:00:00 2001 From: philmoz Date: Thu, 8 Aug 2024 13:36:51 +1000 Subject: [PATCH 3/3] Add '_' character. --- companion/src/shared/namevalidator.h | 2 +- radio/src/gui/common/stdlcd/draw_functions.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/companion/src/shared/namevalidator.h b/companion/src/shared/namevalidator.h index a40202db2e6..e85bbd85da8 100644 --- a/companion/src/shared/namevalidator.h +++ b/companion/src/shared/namevalidator.h @@ -25,7 +25,7 @@ #include "textvalidator.h" // characters supportd by B&W radio firmware gui editor -constexpr char NAME_VALID_PATTERN_BW[] {"[ A-Za-z0-9\\-\\,\\.]*"}; +constexpr char NAME_VALID_PATTERN_BW[] {"[ A-Za-z0-9\\_\\-\\,\\.]*"}; // characters supported by color radio firmware keyboard widget constexpr char NAME_VALID_PATTERN_COLOR[] {"[ A-Za-z0-9\\-\\_\\,\\.\"\\+\\/\\*\\=\\%\\!\\?\\#\\<\\>\\@\\$\\(\\)\\{\\}\\[\\]\\;\\:\\']*"}; diff --git a/radio/src/gui/common/stdlcd/draw_functions.cpp b/radio/src/gui/common/stdlcd/draw_functions.cpp index 5694178cc70..2c4dafd9b80 100644 --- a/radio/src/gui/common/stdlcd/draw_functions.cpp +++ b/radio/src/gui/common/stdlcd/draw_functions.cpp @@ -159,16 +159,17 @@ char getPreviousChar(char c, uint8_t position) return c - 1; } -static const char nameChars[] = " abcdefghijklmnopqrstuvwxyz0123456789-,."; +static const char nameChars[] = " abcdefghijklmnopqrstuvwxyz0123456789_-,."; static int nameCharIdx(char v) { if (islower(v)) return v - 'a' + 1; if (isupper(v)) return v - 'A' + 1; if (isdigit(v)) return v - '0' + 27; - if (v == '-') return 37; - if (v == ',') return 38; - if (v == '.') return 39; + if (v == '_') return 37; + if (v == '-') return 38; + if (v == ',') return 39; + if (v == '.') return 40; return 0; }