leds: persist brightness across reboots and firmware updates

leds.brightness (PWM-capable boards) was RAM-only since it was added: it
always reset to ZEPHCORE_LED_DEFAULT_BRIGHTNESS_PCT (10%) on every boot,
regardless of what a user had last set it to.

New field led_brightness on NodePrefs, following the exact same
append-only pattern as leds_radio_mode/leds_hb_mode added just before it:
offset 311 in RepeaterDataStore.cpp (repeater/room-server/observer,
shared file), offset 174 in ZephyrDataStore.cpp (companion). Both are
backward compatible by construction: a prefs file written before this
field existed simply leaves it at the initNodePrefs() default (10%),
which is exactly the behaviour every already-deployed node has today --
no special-casing needed to keep "10% on a new/not-yet-upgraded node" as
the effective default.

CommonCLI.cpp's "set leds.brightness" handler now writes the prefs field
and calls savePrefs(), same as the leds.radio/leds.hb handlers right
above it; "get leds.brightness" now reads from prefs instead of the RAM
getter directly, for the same reason those two already do (always in
sync, prefs is the source of truth). The four boot call sites
(main_companion.cpp, main_repeater.cpp, main_room_server.cpp,
main_observer.cpp) each gained a zephcore_led_set_brightness_pct() call
seeding the RAM cache from the persisted value, mirroring the existing
leds_radio_mode/leds_hb_mode lines right next to them.

Verified building for heltec_t096/nrf52840 (companion) and rak3401_1watt
(repeater), the two roles/datastores touched by this change.
This commit is contained in:
ZephCore T096
2026-10-08 18:27:00 +02:00
parent 4905191b1c
commit ec2a07dfa9
6 changed files with 29 additions and 4 deletions
+10
View File
@@ -187,6 +187,11 @@ bool companionPrefsDecode(NodePrefs &prefs, const uint8_t *buf, size_t len)
r.take(&p.tz_offset, 1);
r.take(&p.leds_radio_mode, 1);
r.take(&p.leds_hb_mode, 1);
/* led_brightness (ZephCore extension, since 1.17.4). Absent in files
* written before this field existed; the no-op EOF read leaves the
* initNodePrefs() default ZEPHCORE_LED_DEFAULT_BRIGHTNESS_PCT (10%),
* same value a fresh node already showed before this was persisted. */
r.take(&p.led_brightness, 1);
r.take(&p.wifi_enabled, 1);
r.take(p.wifi_ssid, sizeof(p.wifi_ssid));
r.take(p.wifi_pwd, sizeof(p.wifi_pwd));
@@ -355,6 +360,11 @@ void serverPrefsDecode(NodePrefs &prefs, const uint8_t *buf, size_t len)
r.get(&prefs.tz_offset, sizeof(prefs.tz_offset));
r.get(&prefs.leds_radio_mode, sizeof(prefs.leds_radio_mode));
r.get(&prefs.leds_hb_mode, sizeof(prefs.leds_hb_mode));
/* led_brightness (ZephCore extension, since 1.17.4). Absent in files
* written before this field existed; the no-op EOF read leaves the
* initNodePrefs() default ZEPHCORE_LED_DEFAULT_BRIGHTNESS_PCT (10%),
* same value a fresh node already showed before this was persisted. */
r.get(&prefs.led_brightness, sizeof(prefs.led_brightness));
/* Only the explicit "off" magic disables LEDs; a legacy AGC interval or an
* unwritten byte both mean "on". */