From 8d58ae3cf8752a8507affb920ae608cab8c0ada8 Mon Sep 17 00:00:00 2001 From: philmoz Date: Mon, 13 Jan 2025 09:45:58 +1100 Subject: [PATCH] fix(bw): customisable switch LED color text sometimes incorrect on GX12 (#5776) --- radio/src/gui/128x64/model_setup.cpp | 15 +++++++++++---- radio/src/hal/rgbleds.h | 7 +++++-- radio/src/targets/simu/led_driver.cpp | 11 ++++++++--- radio/src/targets/taranis/led_driver.cpp | 10 +++++++--- radio/src/translations/cn.h | 2 +- radio/src/translations/cz.h | 2 +- radio/src/translations/da.h | 2 +- radio/src/translations/de.h | 2 +- radio/src/translations/en.h | 2 +- radio/src/translations/es.h | 2 +- radio/src/translations/fi.h | 2 +- radio/src/translations/fr.h | 2 +- radio/src/translations/he.h | 2 +- radio/src/translations/it.h | 2 +- radio/src/translations/jp.h | 2 +- radio/src/translations/nl.h | 2 +- radio/src/translations/pl.h | 2 +- radio/src/translations/pt.h | 2 +- radio/src/translations/ru.h | 2 +- radio/src/translations/se.h | 2 +- radio/src/translations/tw.h | 2 +- radio/src/translations/ua.h | 2 +- 22 files changed, 49 insertions(+), 30 deletions(-) diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index 593cd1c67a3..e6114aa6eca 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -643,6 +643,13 @@ bool checkCFSSwitchAvailable(int sw) } #endif +#if defined(FUNCTION_SWITCHES_RGB_LEDS) +bool checkCFSColorAvailable(int col) +{ + return col > 0; +} +#endif + void menuModelSetup(event_t event) { int8_t old_editMode = s_editMode; @@ -963,18 +970,18 @@ void menuModelSetup(event_t event) // ON selectedColor = getRGBColorIndex(g_model.functionSwitchLedONColor[index].getColor()); selectedColor = editChoice(INDENT_WIDTH + getTextWidth(STR_FS_ON_COLOR) + 2, y, STR_FS_ON_COLOR, \ - STR_FS_COLOR_LIST, selectedColor, 0, (sizeof(colorTable) / sizeof(colorTable[0])) - 1, menuHorizontalPosition == 0 ? attr : 0, event, INDENT_WIDTH); + STR_FS_COLOR_LIST, selectedColor, 0, DIM(colorTable), menuHorizontalPosition == 0 ? attr : 0, event, INDENT_WIDTH, checkCFSColorAvailable); if (attr && menuHorizontalPosition == 0 && checkIncDec_Ret) { - g_model.functionSwitchLedONColor[index].setColor(colorTable[selectedColor]); + g_model.functionSwitchLedONColor[index].setColor(colorTable[selectedColor - 1]); storageDirty(EE_MODEL); } // OFF selectedColor = getRGBColorIndex(g_model.functionSwitchLedOFFColor[index].getColor()); selectedColor = editChoice((30 + 5*FW) + getTextWidth(STR_FS_OFF_COLOR) + 2, y, STR_FS_OFF_COLOR, \ - STR_FS_COLOR_LIST, selectedColor, 0, (sizeof(colorTable) / sizeof(colorTable[0])) - 1, menuHorizontalPosition == 1 ? attr : 0, event, 30 + 5*FW); + STR_FS_COLOR_LIST, selectedColor, 0, DIM(colorTable), menuHorizontalPosition == 1 ? attr : 0, event, 30 + 5*FW, checkCFSColorAvailable); if (attr && menuHorizontalPosition == 1 && checkIncDec_Ret) { - g_model.functionSwitchLedOFFColor[index].setColor(colorTable[selectedColor]); + g_model.functionSwitchLedOFFColor[index].setColor(colorTable[selectedColor - 1]); storageDirty(EE_MODEL); } diff --git a/radio/src/hal/rgbleds.h b/radio/src/hal/rgbleds.h index ad33f51beb6..a9c26ffae4c 100644 --- a/radio/src/hal/rgbleds.h +++ b/radio/src/hal/rgbleds.h @@ -22,8 +22,11 @@ #pragma once #include -// MUST match TR_FS_COLOR_LIST ( "White", "Red", "Green", "Yellow", "Orange", "Blue", "Pink", "Off", Custom gets display when none previous match -constexpr uint32_t colorTable[] = {0xF8F8F8, 0xF80000, 0x00F800, 0xF8F800, 0xF84000, 0x0000F8, 0xF800F8, 0x000000}; +// MUST match TR_FS_COLOR_LIST (except 'Custom') - Custom gets display when none previous match +// "Off", "White", "Red", "Green", "Yellow", "Orange", "Blue", "Pink" +constexpr uint32_t colorTable[] = {0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0xFFFF00, 0xFF4000, 0x0000FF, 0xFF00FF}; +// Alternate table for matching original RGB 565 converted values +constexpr uint32_t colorTabl2[] = {0x000000, 0xF8F8F8, 0xF80000, 0x00F800, 0xF8F800, 0xF84000, 0x0000F8, 0xF800F8}; void setFSLedOFF(uint8_t index); void setFSLedON(uint8_t index); diff --git a/radio/src/targets/simu/led_driver.cpp b/radio/src/targets/simu/led_driver.cpp index e48faf35fcb..6956616fa4e 100644 --- a/radio/src/targets/simu/led_driver.cpp +++ b/radio/src/targets/simu/led_driver.cpp @@ -21,6 +21,7 @@ #include #include "hal/rgbleds.h" +#include "definitions.h" bool usbChargerLed() { return true; } void ledRed() {} @@ -36,11 +37,15 @@ void rgbLedColorApply() {} uint8_t getRGBColorIndex(uint32_t color) { - for (uint8_t i = 0; i < (sizeof(colorTable) / sizeof(colorTable[0])); i++) { + for (uint8_t i = 0; i < DIM(colorTable); i++) { if (color == colorTable[i]) - return(i); + return(i + 1); } - return 5; // Custom value set with Companion + for (uint8_t i = 0; i < DIM(colorTabl2); i++) { + if (color == colorTabl2[i]) + return(i + 1); + } + return 0; // Custom value set with Companion } // RGB diff --git a/radio/src/targets/taranis/led_driver.cpp b/radio/src/targets/taranis/led_driver.cpp index 94c616f8b30..34df3e7ffce 100644 --- a/radio/src/targets/taranis/led_driver.cpp +++ b/radio/src/targets/taranis/led_driver.cpp @@ -71,11 +71,15 @@ void fsLedRGB(uint8_t index, uint32_t color) uint8_t getRGBColorIndex(uint32_t color) { - for (uint8_t i = 0; i < (sizeof(colorTable) / sizeof(colorTable[0])); i++) { + for (uint8_t i = 0; i < DIM(colorTable); i++) { if (color == colorTable[i]) - return(i); + return(i + 1); } - return 5; // Custom value set with Companion + for (uint8_t i = 0; i < DIM(colorTabl2); i++) { + if (color == colorTabl2[i]) + return(i + 1); + } + return 0; // Custom value set with Companion } #elif defined(FUNCTION_SWITCHES) void fsLedOff(uint8_t index) diff --git a/radio/src/translations/cn.h b/radio/src/translations/cn.h index d29c78d2cc1..17f69db0f90 100644 --- a/radio/src/translations/cn.h +++ b/radio/src/translations/cn.h @@ -285,7 +285,7 @@ #define TR_MS "ms" #define TR_SWITCH "开关" #define TR_FUNCTION_SWITCHES "可自定义开关" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/cz.h b/radio/src/translations/cz.h index d7ac164164a..9cd75c12bcf 100644 --- a/radio/src/translations/cz.h +++ b/radio/src/translations/cz.h @@ -299,7 +299,7 @@ #define TR_MS "ms" #define TR_SWITCH "Spínač" #define TR_FUNCTION_SWITCHES "Nastavitelné přepínače" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/da.h b/radio/src/translations/da.h index 64bcdb2edde..2f2fb0a28f4 100644 --- a/radio/src/translations/da.h +++ b/radio/src/translations/da.h @@ -292,7 +292,7 @@ #define TR_MS "ms" #define TR_SWITCH "Kontakt" #define TR_FUNCTION_SWITCHES "Kontakter der kan tilpasses" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/de.h b/radio/src/translations/de.h index 085df8707ff..bfb847613e0 100644 --- a/radio/src/translations/de.h +++ b/radio/src/translations/de.h @@ -290,7 +290,7 @@ #define TR_MS "ms" #define TR_SWITCH TR("Schalt.", "Schalter") #define TR_FUNCTION_SWITCHES "Anpassbare Schalter" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_FS_ON_COLOR TR("ON:","ON Color") diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index 6618d5c7637..0b3c65a49ac 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -289,7 +289,7 @@ #define TR_MS "ms" #define TR_SWITCH "Switch" #define TR_FUNCTION_SWITCHES "Customizable Switches" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_FS_ON_COLOR TR("ON:","ON Color") diff --git a/radio/src/translations/es.h b/radio/src/translations/es.h index 523c6485b9b..c85cc56e0ea 100644 --- a/radio/src/translations/es.h +++ b/radio/src/translations/es.h @@ -287,7 +287,7 @@ #define TR_MS "ms" #define TR_SWITCH TR("Interr.", "Interruptor") #define TR_FUNCTION_SWITCHES "Customizable switches" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/fi.h b/radio/src/translations/fi.h index 97b7564a5c8..83e3a1c6460 100644 --- a/radio/src/translations/fi.h +++ b/radio/src/translations/fi.h @@ -300,7 +300,7 @@ #define TR_MS "ms" #define TR_SWITCH "Switch" #define TR_FUNCTION_SWITCHES "Customizable switches" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/fr.h b/radio/src/translations/fr.h index b0b407eed96..40ecfa422fb 100644 --- a/radio/src/translations/fr.h +++ b/radio/src/translations/fr.h @@ -295,7 +295,7 @@ #define TR_MS "ms" #define TR_SWITCH TR("Inter", "Interrupteur") #define TR_FUNCTION_SWITCHES "Inters paramétrables" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/he.h b/radio/src/translations/he.h index 633e5bc7f46..e086b3fe7cb 100644 --- a/radio/src/translations/he.h +++ b/radio/src/translations/he.h @@ -293,7 +293,7 @@ #define TR_MS "ms" #define TR_SWITCH "מתג" #define TR_FUNCTION_SWITCHES "מפסקים בהתאמה אישית" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/it.h b/radio/src/translations/it.h index 9476941a5da..655aa957edd 100644 --- a/radio/src/translations/it.h +++ b/radio/src/translations/it.h @@ -289,7 +289,7 @@ #define TR_MS "ms" #define TR_SWITCH "Inter." #define TR_FUNCTION_SWITCHES "Interruttori personalizzabili" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/jp.h b/radio/src/translations/jp.h index c71f6720866..65b69c4e434 100644 --- a/radio/src/translations/jp.h +++ b/radio/src/translations/jp.h @@ -288,7 +288,7 @@ #define TR_MS "ms" #define TR_SWITCH "スイッチ" #define TR_FUNCTION_SWITCHES "カスタマイズ スイッチ" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/nl.h b/radio/src/translations/nl.h index f9644277fa2..d2b3482f7ca 100644 --- a/radio/src/translations/nl.h +++ b/radio/src/translations/nl.h @@ -286,7 +286,7 @@ #define TR_MS "ms" #define TR_SWITCH TR("Schak.", "Schakelaar") #define TR_FUNCTION_SWITCHES "Customizable switches" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/pl.h b/radio/src/translations/pl.h index bbc0c15bc36..2fed1b2f8ae 100644 --- a/radio/src/translations/pl.h +++ b/radio/src/translations/pl.h @@ -286,7 +286,7 @@ #define TR_MS "ms" #define TR_SWITCH "Przełą" #define TR_FUNCTION_SWITCHES "Ustawiane przełączniki" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" #define TR_LAST "Last" diff --git a/radio/src/translations/pt.h b/radio/src/translations/pt.h index 376207e13c7..e05f15e53de 100644 --- a/radio/src/translations/pt.h +++ b/radio/src/translations/pt.h @@ -292,7 +292,7 @@ #define TR_MS "ms" #define TR_SWITCH "Chave" #define TR_FUNCTION_SWITCHES "Chaves customizáveis" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/ru.h b/radio/src/translations/ru.h index 4673472c8ef..0ce0f49d5f7 100644 --- a/radio/src/translations/ru.h +++ b/radio/src/translations/ru.h @@ -291,7 +291,7 @@ #define TR_MS "ms" #define TR_SWITCH "Тумблер" #define TR_FUNCTION_SWITCHES "Настр тумблеры" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/se.h b/radio/src/translations/se.h index c75f6351c58..febc715f4e1 100644 --- a/radio/src/translations/se.h +++ b/radio/src/translations/se.h @@ -301,7 +301,7 @@ #define TR_MS "ms" #define TR_SWITCH "Brytare" #define TR_FUNCTION_SWITCHES "Anpassningsbara brytare" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Grupp" #define TR_GROUP_ALWAYS_ON "Alltid på" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/tw.h b/radio/src/translations/tw.h index d42ee4d93bd..1c2bd96ad33 100644 --- a/radio/src/translations/tw.h +++ b/radio/src/translations/tw.h @@ -290,7 +290,7 @@ #define TR_MS "ms" #define TR_SWITCH "開關" #define TR_FUNCTION_SWITCHES "可自定義開關" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups" diff --git a/radio/src/translations/ua.h b/radio/src/translations/ua.h index 0cfe90f96d5..4d5d5d4353f 100644 --- a/radio/src/translations/ua.h +++ b/radio/src/translations/ua.h @@ -291,7 +291,7 @@ #define TR_MS "ms" #define TR_SWITCH "Перемикач" #define TR_FUNCTION_SWITCHES "Користувацькі перемикачі" -#define TR_FS_COLOR_LIST "White","Red","Green","Yellow","Orange","Blue","Pink","Off","Custom" +#define TR_FS_COLOR_LIST "Custom","Off","White","Red","Green","Yellow","Orange","Blue","Pink" #define TR_GROUP "Group" #define TR_GROUP_ALWAYS_ON "Always on" #define TR_GROUPS "Always on groups"