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.
40 lines
1.6 KiB
C
40 lines
1.6 KiB
C
#include "clock.h"
|
||
#include "xtell.h"
|
||
|
||
// 软时钟基础计时变量
|
||
u8 current_hour = 10; // 系统软时钟:小时 (默认初始化为 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;
|
||
|
||
/**
|
||
* @brief 系统软时钟毫秒递增更新 (在 1ms 中断中调用)
|
||
* @details 负责由定时器 1ms 驱动递增软时钟,并在分钟发生跳变时将 clock_updated 置位
|
||
*/
|
||
void Clock_IncMS(void)
|
||
{
|
||
ms_cnt++;
|
||
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++;
|
||
if (current_min >= 60) {
|
||
current_min = 0; // 1小时时间到
|
||
current_hour++;
|
||
if (current_hour >= 24) {
|
||
current_hour = 0; // 小时循环
|
||
}
|
||
}
|
||
clock_updated = 1; // 分钟跳变,标志位置位,前台待机 App 会捕获以刷新 UI
|
||
XTELL_LOG("[CLOCK] Time updated!\r\n");
|
||
}
|
||
}
|
||
}
|