Skip to content

Day/night backlight color - #2092

Open
gmarull wants to merge 4 commits into
coredevices:mainfrom
teslabs:day-night-backlight
Open

gmarull wants to merge 4 commits into
coredevices:mainfrom
teslabs:day-night-backlight

Conversation

@gmarull

@gmarull gmarull commented Sep 17, 2026

Copy link
Copy Markdown
Member

Revives #1596 by @nick1udwig (closed by the stale bot) on top of current main. Original authorship is preserved on all commits.

Problem

Watches with an RGB backlight should be able to switch automatically between a day and a night backlight color.

Resolves #1139.

Solution

Four new syncable prefs: lightColorDayNightEnabled, lightColorNight, lightColorSunriseMinute, lightColorSunsetMinute (defaults 06:00/18:00; the phone can supply location-based times). The light service picks the system color from the schedule wherever it would otherwise use the user's default color, and arms a timer for the next sunrise/sunset boundary so a backlight that is already on re-tints at the transition.

A backlight daynight <start|status|off> console command arms a green→red switch one minute out for quick manual testing.

Changes vs. #1596

  • Rebased on the CMake tree; light_commands.c folded into services/light/console.c, no longer QEMU-only.
  • Scheduling follows the Do Not Disturb pattern: time_util_get_seconds_until_daily_time(), light_handle_clock_change() from the event loop on PEBBLE_SET_TIME_EVENT, and light_handle_color_prefs_changed() from the pref handlers (covers both local sets and phone sync), instead of subscribing to events inside the service.
  • No capability bit. Older firmware already rejects unknown pref keys (settings_blob_db.c, "Rejecting non-whitelisted setting"), and every other recently added pref, including lightColor itself, ships without one. Day/night backlight color mobileapp#265 should drop SupportsBacklightColorSchedule and gate the UI on the watch model (RGB backlight hardware), or not gate at all like lightColor.
  • The original tests were guarded by CONFIG_BACKLIGHT_HAS_COLOR, which the test build never defined, so they never ran. test_light now builds with it and the fake RTC, covering color selection around sunrise/sunset, midnight-wrapping schedules, the equal-times case, timer arming, and re-tinting a lit backlight when the timer fires.

Testing

  • pbl test -R test_light passes (19 cases, 6 new).
  • Builds: qemu_emery, obelix@pvt (normal + PRF).
  • QEMU (qemu_emery): backlight daynight start → green backlight; at the sunset minute the timer switched it to red while lit; off restores.

🤖 Generated with Claude Code

@gmarull
gmarull requested a review from jplexer as a code owner September 17, 2026 09:52
@gmarull
gmarull force-pushed the day-night-backlight branch from 589a10c to df6f007 Compare September 17, 2026 10:01
@gmarull

gmarull commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

@sjp4 please check the mobile side, otherwise this feature can't be used in practice

nick1udwig and others added 4 commits September 17, 2026 16:02
Watches with an RGB backlight can now switch between a day and a night
color automatically. Four new syncable prefs back the feature: an enable
flag, the night color, and the sunrise/sunset minute of day. Sunrise
and sunset default to 06:00/18:00; the phone can supply location-based
times.

The light service picks the system color from the schedule whenever it
would otherwise drive the user's default color, and registers a daily
cron job for each of sunrise and sunset so a backlight that is already
on re-tints at the transition. Cron is wall-clock based, so the jobs
follow DST, time zone and clock adjustments on their own; the clock
change hook only re-applies the color in case the backlight is lit
while the time jumps across a boundary. Pref changes (local or
phone-synced) rebuild the jobs.

Signed-off-by: Nick Ludwig <nick.b.ludwig@gmail.com>
Co-Authored-By: GPT-5.5-xhigh
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cron_service_deinit() only stopped the timer, so a test that also
resets the new_timer fake between cases left the service holding a
stale TimerID that the next cron_service_init() would not recreate.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Build test_light with CONFIG_BACKLIGHT_HAS_COLOR and the fake RTC so the
schedule logic is exercised: color selection around sunrise/sunset,
schedules that wrap midnight, the degenerate equal-times case, timer
arming for the next boundary, and re-tinting a lit backlight when the
timer fires.

Signed-off-by: Nick Ludwig <nick.b.ludwig@gmail.com>
Co-Authored-By: GPT-5.5-xhigh
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`backlight daynight start` sets green as the day color and red as the
night color, with sunset one minute from now, so the switch can be
observed without waiting for a real sunset. `status` prints the current
schedule and `off` disables it again.

Signed-off-by: Nick Ludwig <nick.b.ludwig@gmail.com>
Co-Authored-By: GPT-5.5-xhigh
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DNM Do Not Merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Time 2 - "night mode" using RGB backlight?

3 participants