#pragma once #include "power_policy.h" #include "service.h" #include "settings.h" namespace roro { // Screen dimming/off from user activity and G0 handling. A long G0 press powers off (deep sleep, // woken by G0); Services stop with it. class PowerService : public Service { public: explicit PowerService(const Settings& settings); const char* name() const override { return "power"; } uint32_t tickIntervalMs() const override { return 50; } void start() override; void tick(uint32_t nowMs) override; // 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: void applyScreen(ScreenState state); void powerOff(); const Settings& settings_; PowerPolicy policy_; PowerButton button_{2000}; ScreenState applied_ = ScreenState::On; int appliedBrightness_ = -1; }; } // namespace roro