refactor(event): replace global 60s inactivity timer with per-second tick event

Adds KEY_EVENT_SECOND_TICK, generated once per real second from
Clock_IncMS() via a new second_tick_flag and pushed through the normal
event queue, so every foreground App's onEvent() receives it and
decides independently whether to act. Removes the old global
inactivity_timer (60s sleep from anywhere) entirely. HomeApp now
accumulates its own idle-second counter and sleeps after 10s idle
specifically while on the home screen; MenuApp's existing 10s
auto-close is converted from onRun() polling to the same tick+reset
pattern for consistency. Any non-tick key event resets each app's own
counter to 0.
This commit is contained in:
edisondeng
2026-07-31 18:49:03 +08:00
parent cbd480eea3
commit 2a83079007
8 changed files with 70 additions and 54 deletions

View File

@@ -6,6 +6,7 @@ u8 current_hour = 10; // 系统软时钟:小时 (默认初
u8 current_min = 35; // 系统软时钟:分钟 (默认初始化为 35 分)
u8 current_sec = 0; // 系统软时钟:秒
volatile u8 clock_updated = 0; // 分钟跳变标志位,置位后用于驱动 UI 刷新时间显示
volatile bit second_tick_flag = 0; // 整秒滴答标志位,每次秒进位置 1由主循环转换为 KEY_EVENT_SECOND_TICK 事件
// 毫秒计数器 (Timer1 每 1ms 累加)
static u16 ms_cnt = 0;
@@ -20,6 +21,7 @@ void Clock_IncMS(void)
if (ms_cnt >= 1000) {
ms_cnt = 0; // 1秒时间到
current_sec++;
second_tick_flag = 1; // 整秒滴答,通知主循环生成 KEY_EVENT_SECOND_TICK 事件
if (current_sec >= 60) {
current_sec = 0; // 1分钟时间到
current_min++;