#include "power_policy.h" namespace roro { bool PowerPolicy::activity(uint32_t nowMs) { bool swallow = state_ == ScreenState::Off; lastActivityMs_ = nowMs; state_ = ScreenState::On; return swallow; } ScreenState PowerPolicy::update(uint32_t nowMs) { // Activity stamped from a clock read after this pass's nowMs (the Debug Console's `key`) is in // the future, not 49 days ago: unsigned, the screen went off for a tick and ate the next key. int32_t since = static_cast(nowMs - lastActivityMs_); uint32_t idle = since < 0 ? 0 : static_cast(since); state_ = idle >= offMs_ ? ScreenState::Off : idle >= dimMs_ ? ScreenState::Dimmed : ScreenState::On; if (notifying_) { if (static_cast(nowMs - notifyUntilMs_) >= 0) notifying_ = false; else if (state_ == ScreenState::Off) state_ = ScreenState::Dimmed; } return state_; } ButtonAction PowerButton::update(bool pressed, uint32_t nowMs) { if (pressed && !pressed_) { pressed_ = true; longFired_ = false; pressedAtMs_ = nowMs; return ButtonAction::None; } if (pressed && !longFired_ && nowMs - pressedAtMs_ >= longMs_) { longFired_ = true; return ButtonAction::LongPress; } if (!pressed && pressed_) { pressed_ = false; return longFired_ ? ButtonAction::None : ButtonAction::ShortPress; } return ButtonAction::None; } } // namespace roro