Files
roro9stack/lib/services/src/power_policy.cpp
T
twislaandClaude Opus 5.5 c868977f1c A key sent through the Debug Console could turn the screen "off" for a tick
The `key` command stamps the power timer from millis(); the power tick
then compared with its pass's older time, and the unsigned difference read
as 49 days without a key. The screen state went Off for one tick, and the
next key was swallowed as a wake-up: about one remote key in twenty-five.
Keys from the keyboard pass the loop's own time and were never affected.
The same shape as #46. PowerPolicy::update now treats a stamp from the
future as "just now", with a test.

rdbg.py: piped lines written while it was still connecting stayed in
Python's read buffer until the next line arrived (readline() behind
select()). It reads the descriptor directly now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-06 10:08:10 +02:00

46 lines
1.5 KiB
C++

#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<int32_t>(nowMs - lastActivityMs_);
uint32_t idle = since < 0 ? 0 : static_cast<uint32_t>(since);
state_ = idle >= offMs_ ? ScreenState::Off : idle >= dimMs_ ? ScreenState::Dimmed : ScreenState::On;
if (notifying_) {
if (static_cast<int32_t>(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