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:
1 parent
7d5cd3bf8d
commit
6b1d20acde
5 files changed
+48
-16
No files matched your search
@@ -103,9 +103,13 @@ GPIO0 to GND, tap RST to GND, then release GPIO0.
|
||||
6. Done (2026-10-25): SignalRGB via WLED emulation (`wled.ino`, `USE_WLED_REALTIME`,
|
||||
`WLED_MAX_FPS` 30: no flicker, no loop stalls). SignalRGB's WLED plugin only sends as many LEDs as the channel's component has (needs 4). LED order checked:
|
||||
SignalRGB LED 0 = left tube, `tubePixels` {0,1,2,3} is right. Settings `wledEnable` /
|
||||
`wledDarkWithTubes` / `wledUseBrightness` live in `prmExt`, stored in EEPROM after `prm` with
|
||||
their own magic value: never add fields to `prm` (a `MAGIC_VALUE` bump factory-resets the
|
||||
clock, WiFi included). HA switch "SignalRGB".
|
||||
`wledDarkWithTubes` / `wledUseBrightness` / `wledWakeAtNight` live in `prmExt`, stored in EEPROM
|
||||
after `prm` with their own magic value: never add fields to `prm` (a `MAGIC_VALUE` bump
|
||||
factory-resets the clock, WiFi included). `prmExt` 0x5702 added `wledWakeAtNight` in the old
|
||||
padding byte and migrates 0x5701; it has no padding left, so the next field needs a real
|
||||
migration. HA switch "SignalRGB".
|
||||
`wledWakeAtNight` ("Wake at night", web UI only): while frames arrive, `evalShutoffTime()` keeps
|
||||
day mode during the night schedule; the manual night toggle, radar and HA Tubes switch still win.
|
||||
7. Done (2026-10-29, on the clock): new web UI. Source `firmware/uniclock/web/index.html`
|
||||
(one file, no jQuery, controls generated from the `PAGES` table), gzipped by `web/gzip_web.py`
|
||||
to `data/index.html.gz` (12 KB, was 147 KB), served by one `serveStatic` with `no-cache`.
|
||||
|
||||
@@ -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.
@@ -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
|
||||
@@ -130,7 +130,7 @@ const SAMPLE = {
|
||||
enableAutoShutoff: true, dayTime: "07:00", nightTime: "22:30", dayBright: 72, nightBright: 10, manualOverride: false,
|
||||
animMode: 6, alarmEnable: false, alarmTime: "06:30", alarmPeriod: 15, enableRadar: false, radarTimeout: 5,
|
||||
rgbEffect: 1, rgbBrightness: 120, rgbFixColor: 30, rgbSpeed: 50, rgbDir: false, rgbMinBrightness: 8,
|
||||
wledEnable: true, wledDarkWithTubes: true, wledUseBrightness: true,
|
||||
wledEnable: true, wledDarkWithTubes: true, wledUseBrightness: true, wledWakeAtNight: false,
|
||||
wifiMode: true, wifiSsid: "dlink-iot", wifiPsw: "", wifiPswSet: true, ApSsid: "UNICLOCK", ApPsw: "", ApPswSet: false,
|
||||
NtpServer: "pool.ntp.org", firmware: "", mqttBrokerAddr: "10.1.1.175", mqttBrokerUser: "mqtt", mqttBrokerPsw: "",
|
||||
mqttBrokerPswSet: true, mqttEnable: true, mqttBrokerRefresh: 30, dateMode: 0, dateRepeatMin: 3, tempRepeatMin: 1,
|
||||
@@ -281,6 +281,7 @@ const PAGES = [
|
||||
{ t: "sw", k: "wledEnable", l: "SignalRGB control", h: "The clock shows up in SignalRGB as a WLED device" },
|
||||
{ t: "sw", k: "wledDarkWithTubes", l: "Off with the tubes", h: "LEDs stay dark while the tubes are off" },
|
||||
{ t: "sw", k: "wledUseBrightness", l: "Use backlight brightness", h: "Off: colours exactly as SignalRGB sends them" },
|
||||
{ t: "sw", k: "wledWakeAtNight", l: "Wake at night", h: "Tubes and LEDs stay on at night while SignalRGB sends colours", show: () => cfg.enableAutoShutoff },
|
||||
{ t: "info", k: "wledLive", l: "Receiving colours", f: v => v ? "yes" : "no" }] }
|
||||
] },
|
||||
{ id: "network", l: "Network", cards: [
|
||||
|
||||
Reference in new issue
Block a user