Let SignalRGB keep the clock awake at night

New "Wake at night" setting (prmExt.wledWakeAtNight, web UI only): while
WLED frames arrive, the night schedule is ignored and the clock runs as by
day. Night mode returns as soon as the frames time out. The manual night
toggle, radar and HA Tubes switch still win.

The field uses the former padding byte of prmExt; MAGIC_VALUE_EXT is now
0x5702 and 0x5701 settings are migrated, so existing SignalRGB settings
are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-03 00:04:15 +01:00
1 parent 7d5cd3bf8d
commit 6b1d20acde
5 files changed
+48 -16

No files matched your search

@@ -446,13 +446,18 @@ struct {
// Adding them to `prm` would change its layout, and the MAGIC_VALUE check would then factory-reset
// the clock (WiFi settings included). If the magic value doesn't match (first boot after the update),
// loadEEPROM() sets these defaults and leaves `prm` alone.
#define MAGIC_VALUE_EXT 0x5701
// 0x5701 had no wledWakeAtNight; it sat in what was the padding byte, so the other fields kept their place and
// loadEEPROM() takes them over.
#define MAGIC_VALUE_EXT 0x5702
#define MAGIC_VALUE_EXT_5701 0x5701
struct {
boolean wledEnable = false; //SignalRGB/WLED realtime control of the backlight (wled.ino)
boolean wledDarkWithTubes = true; //WLED frames stay dark while the tubes/backlight are off
boolean wledUseBrightness = true; //WLED frames are scaled by the RGB brightness (and auto dim)
boolean wledWakeAtNight = false; //while WLED frames arrive, the night schedule is ignored (evalShutoffTime())
uint16_t magic = MAGIC_VALUE_EXT;
} prmExt;
static_assert(offsetof(decltype(prmExt), magic) == 4, "prmExt layout changed: MAGIC_VALUE_EXT_5701 migration no longer fits");
#define EEPROM_SIZE (sizeof(prm) + sizeof(prmExt)) //no extra reserved space for future growth: a change to either struct needs its own magic value bumped
@@ -1415,6 +1420,10 @@ void handleConfigChanged(AsyncWebServerRequest *request) {
else if (key == "wledUseBrightness") {
prmExt.wledUseBrightness = (value == "true");
}
else if (key == "wledWakeAtNight") {
prmExt.wledWakeAtNight = (value == "true");
evalShutoffTime(); //takes effect now, not at the next second
}
#endif
else if (key == "wifiSsid") {
value.toCharArray(prm.wifiSsid,sizeof(prm.wifiSsid));
@@ -1653,6 +1662,7 @@ if (useTemp > 1)
doc["wledEnable"] = prmExt.wledEnable;
doc["wledDarkWithTubes"] = prmExt.wledDarkWithTubes;
doc["wledUseBrightness"] = prmExt.wledUseBrightness;
doc["wledWakeAtNight"] = prmExt.wledWakeAtNight;
#endif
doc["wifiMode"] = prm.wifiMode;
doc["wifiSsid"] = prm.wifiSsid;
@@ -2126,6 +2136,10 @@ void loadEEPROM() {
EEPROM.get(EEPROM_addr, prm);
DPRINT(" version:"); DPRINTLN(prm.magic);
EEPROM.get(EEPROM_addr + sizeof(prm), prmExt);
if (prmExt.magic == MAGIC_VALUE_EXT_5701) { //older layout: keep its settings, the new one starts off
prmExt.wledWakeAtNight = false;
prmExt.magic = MAGIC_VALUE_EXT;
}
if (prmExt.magic != MAGIC_VALUE_EXT) resetPrmExt();
}
@@ -2134,6 +2148,7 @@ void resetPrmExt() {
prmExt.wledEnable = false;
prmExt.wledDarkWithTubes = true;
prmExt.wledUseBrightness = true;
prmExt.wledWakeAtNight = false;
prmExt.magic = MAGIC_VALUE_EXT;
}
@@ -2931,7 +2946,7 @@ void evalShutoffTime(void) { // Determine whether tubes should be turned to NI
static bool prevShutoffState = true;
if ( (((mn_off < mn_on) && (mn >= mn_off) && (mn < mn_on))) || // Nighttime
((mn_off > mn_on) && ((mn >= mn_off) || (mn < mn_on)))) {
if (!manualOverride) displayON = false;
if (!manualOverride) displayON = wledWakesNight(); //SignalRGB frames can keep day mode (wled.ino)
if (prevShutoffState == true) manualOverride = false;
prevShutoffState = false;
}
Binary file not shown.
+22 -10
View File
@@ -15,7 +15,9 @@
// gap between tubes (neoShow()), so fewer updates mean less risk of tube flicker.
// Settings (web page and the Home Assistant "SignalRGB" switch): prmExt.wledEnable, prmExt.wledDarkWithTubes (dark
// while the backlight would be off: night, radar, HA Tubes switch), prmExt.wledUseBrightness (scale by the RGB
// brightness and auto dim instead of only the RGB_MAX_BRIGHTNESS cap).
// brightness and auto dim instead of only the RGB_MAX_BRIGHTNESS cap), prmExt.wledWakeAtNight (while frames arrive,
// the night schedule is ignored: tubes and LEDs run as by day; the manual night toggle, radar and HA Tubes switch
// still win. Night mode returns as soon as the frames time out).
//_______________________________________________________________________________________________________________________
#if !defined(ESP8266) || !defined(USE_NEOPIXEL)
@@ -130,26 +132,35 @@ void wledSetup() {
wledReady = true;
}
//Used by evalShutoffTime(): true while the night schedule should be ignored.
boolean wledWakesNight() {
return prmExt.wledWakeAtNight && wledLive;
}
//Called from loop() and Fdelay(). Follows prmExt.wledEnable, reads frames and shows them.
void wledHandle() {
static unsigned long lastShow = 0;
static boolean wasLive = false;
if (!wledReady) return;
if (prmExt.wledEnable != wledRunning) {
if (prmExt.wledEnable) wledBegin();
else wledEnd();
}
if (!wledRunning) return;
wledReceive(wledUdp, false);
wledReceive(wledDdp, true);
if (wledRunning) {
wledReceive(wledUdp, false);
wledReceive(wledDdp, true);
if (wledLive && ((millis() - wledLastPacket) > wledTimeout)) {
wledLive = false; //doAnimationMakuna() takes over again
DPRINTLN("WLED: realtime frames stopped");
}
}
if (wledLive != wasLive) {
wasLive = wledLive;
if (prmExt.wledWakeAtNight) evalShutoffTime(); //wake or sleep now, not at the next second
}
if (!wledLive) return;
if ((millis() - wledLastPacket) > wledTimeout) {
wledLive = false; //doAnimationMakuna() takes over again
DPRINTLN("WLED: realtime frames stopped");
return;
}
if (alarmON || EEPROMsaving) return; //the alarm flash wins
if ((millis() - lastShow) < (1000ul / WLED_MAX_FPS)) return;
lastShow = millis();
@@ -267,5 +278,6 @@ void wledRoutes() {
#else
void wledSetup() {}
void wledHandle() {}
boolean wledWakesNight() { return false; }
void wledRoutes() {}
#endif