Public Access
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
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include "notifier.h"
|
|
|
|
#include <M5Cardputer.h>
|
|
|
|
namespace roro {
|
|
|
|
namespace {
|
|
constexpr int kLedPin = 21; // WS2812, powered with the backlight rail (G38)
|
|
}
|
|
|
|
Notifier::Notifier(EventBus& bus, const Settings& settings) : settings_(settings) {
|
|
bus.subscribe(EventType::Notification, [this](const Event& e) {
|
|
toasts_.push(e.text, static_cast<NotificationLevel>(e.a), millis());
|
|
});
|
|
}
|
|
|
|
void Notifier::alert(NotificationLevel level, uint32_t nowMs) {
|
|
if (!settings_.getBool(Setting::Sound)) return;
|
|
M5Cardputer.Speaker.tone(level == NotificationLevel::Warning ? 880 : 1760, 60);
|
|
switch (level) {
|
|
case NotificationLevel::Warning: rgbLedWrite(kLedPin, 40, 16, 0); break;
|
|
case NotificationLevel::Message: rgbLedWrite(kLedPin, 0, 40, 0); break;
|
|
default: rgbLedWrite(kLedPin, 0, 16, 40); break;
|
|
}
|
|
ledOn_ = true;
|
|
ledOffAtMs_ = nowMs + 150;
|
|
}
|
|
|
|
void Notifier::update(uint32_t nowMs) {
|
|
const Toast* shown = toasts_.current(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);
|
|
ledOn_ = false;
|
|
}
|
|
}
|
|
|
|
} // namespace roro
|