Light the screen (dimmed) while a Notification's Toast shows

An Off screen turns on dimmed for the Toast's duration so the user can
see what beeped. It isn't user activity: the timeouts aren't restarted,
and a key pressed meanwhile reaches the App.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-02 11:35:13 +02:00
co-authored by Claude Opus 5.5
parent 15ea53e17f
commit 9218a34c3e
7 changed files with 65 additions and 1 deletions
+1
View File
@@ -79,6 +79,7 @@ void setup() {
power = new PowerService(settings);
clockService = new ClockService(settings, bus);
notifier = new Notifier(bus, settings);
notifier->onShow = [](uint32_t now, uint32_t until) { power->onNotification(now, until); };
services.add(*power);
services.add(*clockService);
services.add(*battery);
+3
View File
@@ -19,6 +19,9 @@ class PowerService : public Service {
// Call for every key press before routing it. Returns true if the key must not reach the App.
bool onKey(uint32_t nowMs) { return policy_.activity(nowMs); }
// A Toast is showing until untilMs: light an Off screen (dimmed) so it can be read.
void onNotification(uint32_t nowMs, uint32_t untilMs) { policy_.notify(nowMs, untilMs); }
ScreenState screen() const { return applied_; }
private:
+1
View File
@@ -31,6 +31,7 @@ void Notifier::update(uint32_t nowMs) {
if (shown && shown->id != alertedId_) {
alertedId_ = shown->id;
alert(shown->level, nowMs);
if (onShow) onShow(nowMs, nowMs + kToastMs);
}
if (ledOn_ && static_cast<int32_t>(nowMs - ledOffAtMs_) >= 0) {
rgbLedWrite(kLedPin, 0, 0, 0);
+7 -1
View File
@@ -1,5 +1,7 @@
#pragma once
#include <functional>
#include "event_bus.h"
#include "settings.h"
#include "toast_queue.h"
@@ -14,11 +16,15 @@ class Notifier {
void update(uint32_t nowMs); // alerts for a newly shown Toast, ends the LED flash
ToastQueue& toasts() { return toasts_; }
// Called when a Toast appears, with the time it will disappear (e.g. to light the screen).
std::function<void(uint32_t nowMs, uint32_t untilMs)> onShow;
private:
void alert(NotificationLevel level, uint32_t nowMs);
const Settings& settings_;
ToastQueue toasts_{3000, 8};
static constexpr uint32_t kToastMs = 3000;
ToastQueue toasts_{kToastMs, 8};
uint32_t ledOffAtMs_ = 0;
bool ledOn_ = false;
uint32_t alertedId_ = 0;