Files
roro9stack/lib/services/src/power_policy.h
twislaandClaude Opus 5.5 9218a34c3e 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
2026-10-02 11:35:13 +02:00

58 lines
1.6 KiB
C++

#pragma once
#include <cstdint>
namespace roro {
enum class ScreenState : uint8_t { On, Dimmed, Off };
// Screen power from user activity. Services keep running whatever the screen does.
class PowerPolicy {
public:
PowerPolicy(uint32_t dimAfterMs, uint32_t offAfterMs) : dimMs_(dimAfterMs), offMs_(offAfterMs) {}
void setTimeouts(uint32_t dimAfterMs, uint32_t offAfterMs) {
dimMs_ = dimAfterMs;
offMs_ = offAfterMs;
}
// Records a key press. Returns true if the key only woke an Off screen and must not reach the App.
bool activity(uint32_t nowMs);
// A Notification is showing until untilMs: an Off screen lights up Dimmed meanwhile. It's not
// user activity, so it doesn't restart the timeouts.
void notify(uint32_t nowMs, uint32_t untilMs) {
(void)nowMs;
notifyUntilMs_ = untilMs;
notifying_ = true;
}
ScreenState update(uint32_t nowMs);
ScreenState state() const { return state_; }
private:
uint32_t dimMs_;
uint32_t offMs_;
uint32_t lastActivityMs_ = 0;
uint32_t notifyUntilMs_ = 0;
bool notifying_ = false;
ScreenState state_ = ScreenState::On;
};
enum class ButtonAction : uint8_t { None, ShortPress, LongPress };
// G0 button: a long press fires as soon as the hold time is reached (power off); a short press on release.
class PowerButton {
public:
explicit PowerButton(uint32_t longPressMs) : longMs_(longPressMs) {}
ButtonAction update(bool pressed, uint32_t nowMs);
private:
uint32_t longMs_;
bool pressed_ = false;
bool longFired_ = false;
uint32_t pressedAtMs_ = 0;
};
} // namespace roro