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
This commit is contained in:
2026-10-06 10:08:10 +02:00
co-authored by Claude Opus 5.5
parent 4ab873e9f8
commit c868977f1c
3 changed files with 22 additions and 4 deletions
+4 -1
View File
@@ -10,7 +10,10 @@ bool PowerPolicy::activity(uint32_t nowMs) {
} }
ScreenState PowerPolicy::update(uint32_t nowMs) { ScreenState PowerPolicy::update(uint32_t nowMs) {
uint32_t idle = nowMs - lastActivityMs_; // 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; state_ = idle >= offMs_ ? ScreenState::Off : idle >= dimMs_ ? ScreenState::Dimmed : ScreenState::On;
if (notifying_) { if (notifying_) {
if (static_cast<int32_t>(nowMs - notifyUntilMs_) >= 0) if (static_cast<int32_t>(nowMs - notifyUntilMs_) >= 0)
+8 -3
View File
@@ -224,10 +224,15 @@ def interactive(sock):
sys.stdout.write(data.decode(errors="replace")) sys.stdout.write(data.decode(errors="replace"))
sys.stdout.flush() sys.stdout.flush()
if sys.stdin in ready: if sys.stdin in ready:
line = sys.stdin.readline() # Straight from the descriptor: readline() takes every waiting line into Python's own
if not line: # buffer and hands over one, and select() then sees nothing more to read. Piped input
# written while we were still connecting got stuck until the next line came.
data = os.read(sys.stdin.fileno(), 4096)
if not data:
return return
sock.sendall(line.encode()) sock.setblocking(True)
sock.sendall(data)
sock.setblocking(False)
def main(): def main():
+10
View File
@@ -31,6 +31,15 @@ void test_key_on_off_screen_only_wakes() {
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(70001))); TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(70001)));
} }
// A key stamped a few milliseconds after the time the same pass updates with must not read as
// 49 days of idleness: the screen stays on, and the next key acts.
void test_activity_stamped_after_the_pass_time_keeps_the_screen_on() {
PowerPolicy p(30000, 60000);
TEST_ASSERT_FALSE(p.activity(10003));
TEST_ASSERT_TRUE(p.update(10000) == ScreenState::On);
TEST_ASSERT_FALSE(p.activity(10050));
}
void test_new_timeouts_apply_immediately() { void test_new_timeouts_apply_immediately() {
PowerPolicy p(30000, 60000); PowerPolicy p(30000, 60000);
p.activity(0); p.activity(0);
@@ -91,6 +100,7 @@ int main() {
RUN_TEST(test_screen_dims_then_turns_off_after_inactivity); RUN_TEST(test_screen_dims_then_turns_off_after_inactivity);
RUN_TEST(test_key_on_dimmed_screen_wakes_and_still_acts); RUN_TEST(test_key_on_dimmed_screen_wakes_and_still_acts);
RUN_TEST(test_key_on_off_screen_only_wakes); RUN_TEST(test_key_on_off_screen_only_wakes);
RUN_TEST(test_activity_stamped_after_the_pass_time_keeps_the_screen_on);
RUN_TEST(test_new_timeouts_apply_immediately); RUN_TEST(test_new_timeouts_apply_immediately);
RUN_TEST(test_notification_lights_an_off_screen_dimmed_until_it_ends); RUN_TEST(test_notification_lights_an_off_screen_dimmed_until_it_ends);
RUN_TEST(test_notification_does_not_count_as_activity); RUN_TEST(test_notification_does_not_count_as_activity);