@@ -17,7 +17,19 @@ bool g_mqtt_enabled = false;
1717// Global flag to decide fallback vs dynamic
1818static bool useFallback = false ;
1919
20- static bool readConfigJSON (const char * path, String &outSSID, String &outPASS, String &outScript, bool &outMqttEnabled) {
20+ // Define global color variables with default values
21+ uint32_t g_bg_color = 0x000000 ; // Default: black
22+ uint32_t g_fg_color = 0xFFFFFF ; // Default: white
23+
24+ static bool readConfigJSON (
25+ const char * path,
26+ String &outSSID,
27+ String &outPASS,
28+ String &outScript,
29+ bool &outMqttEnabled,
30+ uint32_t &outBgColor,
31+ uint32_t &outFgColor
32+ ) {
2133 File f = SD_MMC.open (path);
2234 if (!f) {
2335 LOG (" No JSON file" );
@@ -42,21 +54,13 @@ static bool readConfigJSON(const char* path, String &outSSID, String &outPASS, S
4254 // Extract the script filename
4355 outScript = doc[" script" ] | " app.js" ;
4456
45- // Update 'last_read' if desired
46- time_t now;
47- time (&now);
48- doc[" last_read" ] = (unsigned long )now;
57+ const char * bgColorStr = doc[" screen" ][" background" ] | " #000000" ;
58+ const char * fgColorStr = doc[" screen" ][" foreground" ] | " #FFFFFF" ;
4959
50- // Optionally write back the updated JSON
51- String updated;
52- serializeJson (doc, updated);
53- f = SD_MMC.open (path, FILE_WRITE);
54- if (!f) {
55- LOG (" Failed to open JSON for writing" );
56- return false ;
57- }
58- f.print (updated);
59- f.close ();
60+ // Convert hex color string (e.g., "#RRGGBB") to a 32-bit integer
61+ // We use strtol with base 16 and skip the leading '#' character.
62+ outBgColor = strtol (bgColorStr + 1 , NULL , 16 );
63+ outFgColor = strtol (fgColorStr + 1 , NULL , 16 );
6064
6165 return true ;
6266}
@@ -80,7 +84,7 @@ void setup() {
8084
8185 // Optionally read /webscreen.json for Wi-Fi
8286 String s, p, scriptFile;
83- if (!readConfigJSON (" /webscreen.json" , s, p, scriptFile, g_mqtt_enabled)) {
87+ if (!readConfigJSON (" /webscreen.json" , s, p, scriptFile, g_mqtt_enabled, g_bg_color, g_fg_color )) {
8488 LOG (" Failed to read /webscreen.json => fallback" );
8589 useFallback = true ;
8690 fallback_setup ();
0 commit comments