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:
@@ -13,6 +13,12 @@
|
||||
extern SystemState current_state;
|
||||
extern volatile u16 ms_tick;
|
||||
|
||||
// 待机时钟界面闲置多久自动进入低功耗休眠的门限 (秒)
|
||||
#define HOME_IDLE_SLEEP_SEC 10
|
||||
|
||||
// 本应用私有变量:累计未按任何键的秒数 (由 KEY_EVENT_SECOND_TICK 驱动,任意按键事件清零)
|
||||
static u8 home_idle_sec = 0;
|
||||
|
||||
// 声明本应用的生命周期回调函数
|
||||
static void HomeApp_OnStart(void);
|
||||
static void HomeApp_onRun(void);
|
||||
@@ -34,6 +40,7 @@ WristbandApp home_app = {
|
||||
*/
|
||||
static void HomeApp_OnStart(void)
|
||||
{
|
||||
home_idle_sec = 0; // 重新进入待机主页 (开机/从菜单退回/休眠唤醒) 都清零闲置计数
|
||||
current_state = STATE_NORMAL; // 系统切入正常待机状态
|
||||
RF_SetMode(1); // 开启天线并置为接收模式,监听无线探测器
|
||||
|
||||
@@ -80,6 +87,21 @@ static void HomeApp_onClose(void)
|
||||
*/
|
||||
static EventResult HomeApp_onEvent(SystemEvent *evt)
|
||||
{
|
||||
// 0. 整秒滴答:累计闲置秒数,达到门限就进入低功耗休眠
|
||||
if (evt->key_event == KEY_EVENT_SECOND_TICK) {
|
||||
home_idle_sec++;
|
||||
if (home_idle_sec >= HOME_IDLE_SLEEP_SEC) {
|
||||
home_idle_sec = 0;
|
||||
current_state = STATE_SLEEP; // 系统置为休眠状态
|
||||
Enter_Low_Power_Sleep(); // 阻塞函数,MCU 在此挂起,唤醒后自动继续往下执行
|
||||
AppManager_SwitchToForeground(&home_app); // 强制重新走一遍 OnStart,刷新画面和背光
|
||||
}
|
||||
return EVENT_HANDLED;
|
||||
}
|
||||
|
||||
// 收到任意其它按键事件,说明用户仍在活动,清零闲置计数
|
||||
home_idle_sec = 0;
|
||||
|
||||
// 1. 长按 ■ 确认键,打开设置主菜单 MenuApp
|
||||
if (evt->key_event == KEY_EVENT_CONFIRM_LONG) {
|
||||
AppManager_SwitchToForeground(&menu_app);
|
||||
|
||||
Reference in New Issue
Block a user