#include "notifier.h" #include 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(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(nowMs - ledOffAtMs_) >= 0) { rgbLedWrite(kLedPin, 0, 0, 0); ledOn_ = false; } } } // namespace roro