From 7432bd8fd0813fd0e87c6baeff3307e03a93e5fb Mon Sep 17 00:00:00 2001 From: Trankid <291778318+jtpydk5gyh-alt@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:58:19 +0100 Subject: [PATCH] fix(cyd): persist Invert Color setting across reboots On CYD-2432S028 and nm-cyd-c5, _post_setup_gpio() unconditionally forced colorInverted after begin_storage() had already loaded the user's value from bruceConf.json, so the "Invert Color" setting reverted on every reboot (#3053). Track whether colorInverted was loaded from the config file and apply the board-specific default only on first boot (no stored value). Once the user changes the setting it now persists, while fresh devices still get the correct panel default. --- boards/CYD-2432S028/interface.cpp | 15 ++++++++------- boards/nm-cyd-c5/interface.cpp | 18 ++++++++---------- src/core/config.cpp | 1 + src/core/config.h | 1 + 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/boards/CYD-2432S028/interface.cpp b/boards/CYD-2432S028/interface.cpp index 17b9ac5e76..1050b424d2 100644 --- a/boards/CYD-2432S028/interface.cpp +++ b/boards/CYD-2432S028/interface.cpp @@ -113,16 +113,17 @@ void _post_setup_gpio() { ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); ledcWrite(TFT_BL, 255); - // Force sync color inversion to prevent bruceConf.json from overriding - // the value set in _setup_gpio(). For CYD variants with TFT_INVERSION_ON, - // the init() sequence sends INVON; we send INVOFF here to ensure normal colors. + // Apply the board-appropriate color inversion default only on first boot, + // when bruceConf.json has no stored value. Once the user changes "Invert + // Color" in Settings the stored value must persist across reboots (#3053). + if (!bruceConfig.colorInvertedSet) { #ifdef TFT_INVERSION_ON - bruceConfig.colorInverted = 0; - tft.invertDisplay(0); + bruceConfig.colorInverted = 0; #else - bruceConfig.colorInverted = 1; - tft.invertDisplay(1); + bruceConfig.colorInverted = 1; #endif + } + tft.invertDisplay(bruceConfig.colorInverted); bruceConfigPins.gps_bus.rx = (gpio_num_t)GPS_SERIAL_RX; bruceConfigPins.gps_bus.tx = (gpio_num_t)GPS_SERIAL_TX; diff --git a/boards/nm-cyd-c5/interface.cpp b/boards/nm-cyd-c5/interface.cpp index ea903b882f..54842c4d58 100644 --- a/boards/nm-cyd-c5/interface.cpp +++ b/boards/nm-cyd-c5/interface.cpp @@ -55,17 +55,15 @@ void _post_setup_gpio() { bruceConfigPins.rfTx = 8; bruceConfigPins.rfRx = 9; - // Force disable color inversion for ST7789/ILI9341 on nm-cyd-c5. - // Must be done here because begin_storage() loads bruceConf.json which may - // override the value set in _setup_gpio(). -#ifdef ST7789_DRIVER - bruceConfig.colorInverted = 0; - tft.invertDisplay(0); -#endif -#ifdef ILI9341_DRIVER - bruceConfig.colorInverted = 0; - tft.invertDisplay(0); + // Apply the color inversion default for ST7789/ILI9341 only on first boot, + // when bruceConf.json has no stored value. Once the user changes "Invert + // Color" in Settings the stored value must persist across reboots (#3053). + if (!bruceConfig.colorInvertedSet) { +#if defined(ST7789_DRIVER) || defined(ILI9341_DRIVER) + bruceConfig.colorInverted = 0; #endif + } + tft.invertDisplay(bruceConfig.colorInverted); // Force set I2C bus pins for nm-cyd-c5. // brucePins.conf may have stale/wrong i2c_bus values, so override them diff --git a/src/core/config.cpp b/src/core/config.cpp index ab133884e4..ab85e32483 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -382,6 +382,7 @@ void BruceConfig::fromFile(bool checkFS) { } if (!setting["colorInverted"].isNull()) { colorInverted = setting["colorInverted"].as(); + colorInvertedSet = true; } else { count++; log_e("Fail"); diff --git a/src/core/config.h b/src/core/config.h index bd3cde1aab..1b4aaf61fc 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -87,6 +87,7 @@ class BruceConfig : public BruceTheme { String wdgwarsApiKey = "your 64-char hex key from wdgwars.pl/profile"; int devMode = 0; int colorInverted = 1; + bool colorInvertedSet = false; int badUSBBLEKeyboardLayout = 0; uint16_t badUSBBLEKeyDelay = 10; bool badUSBBLEShowOutput = true;