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:
22
App/event.c
22
App/event.c
@@ -117,12 +117,12 @@ void Event_Dispatcher_Loop(void)
|
||||
return;
|
||||
}
|
||||
|
||||
inactivity_timer = 0; // 捕获到有效事件,清零休眠计时器,重置闲置超时
|
||||
|
||||
// 串口打印调试信息
|
||||
XTELL_LOG("[EVENT] key=");
|
||||
XTELL_LOG_HEX8((u8)evt.key_event);
|
||||
XTELL_LOG("\r\n");
|
||||
// 串口打印调试信息 (整秒滴答事件每秒都会触发一次,不打印以免刷屏)
|
||||
if (evt.key_event != KEY_EVENT_SECOND_TICK) {
|
||||
XTELL_LOG("[EVENT] key=");
|
||||
XTELL_LOG_HEX8((u8)evt.key_event);
|
||||
XTELL_LOG("\r\n");
|
||||
}
|
||||
|
||||
// SOS 按键紧急处理:若当前前台不为 SOS 应用,接收到 SOS 键动作,立即强行切入到 SOS_APP 并执行求救
|
||||
if ((evt.key_event == KEY_EVENT_SOS_CLICK || evt.key_event == KEY_EVENT_SOS_LONG) &&
|
||||
@@ -181,16 +181,6 @@ void Event_KeyScan_Poll(void)
|
||||
}
|
||||
}
|
||||
|
||||
// 检测到有任意按键处于下压状态,立即将无操作闲置休眠计时器归零
|
||||
if (raw_up || raw_down || raw_confirm || raw_sos) {
|
||||
inactivity_timer = 0;
|
||||
} else {
|
||||
// 如果在常态下(非休眠、非报警、非紧急求救),累加闲置时间
|
||||
if (current_state != STATE_SLEEP && current_state != STATE_ALARM && current_state != STATE_SOS_EMITTED) {
|
||||
inactivity_timer++;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认将派发事件重置为空
|
||||
evt.key_event = KEY_EVENT_NONE;
|
||||
evt.priority = EVENT_PRIORITY_NORMAL;
|
||||
|
||||
Reference in New Issue
Block a user