feat(menu): auto-close main menu after 10s idle
menu_app now tracks the last key-activity timestamp (via current_sec, same wraparound-safe pattern already used in pair_app) and switches back to home_app if no key event arrives for 10 seconds, using the AppManager's existing per-frame onRun() callback as the check point.
This commit is contained in:
@@ -6,14 +6,22 @@
|
||||
#include "system.h"
|
||||
#include "database.h"
|
||||
#include "language.h"
|
||||
#include "clock.h"
|
||||
#include "../Drivers/rf.h"
|
||||
|
||||
// 外部全局变量引用
|
||||
extern SystemState current_state;
|
||||
extern u8 menu_select;
|
||||
|
||||
// 菜单闲置自动关闭超时 (秒):无任何按键操作达到这个时长,自动退出菜单返回时钟主页
|
||||
#define MENU_IDLE_TIMEOUT_SEC 10
|
||||
|
||||
// 本应用私有变量:记录最近一次按键活动时的秒计时快照
|
||||
static u8 menu_idle_start_sec = 0;
|
||||
|
||||
// 声明本应用的生命周期回调函数
|
||||
static void MenuApp_OnStart(void);
|
||||
static void MenuApp_onRun(void);
|
||||
static void MenuApp_onClose(void);
|
||||
static EventResult MenuApp_onEvent(SystemEvent *evt);
|
||||
|
||||
@@ -22,7 +30,7 @@ WristbandApp menu_app = {
|
||||
APP_ID_MENU,
|
||||
"Menu",
|
||||
MenuApp_OnStart,
|
||||
NULL,
|
||||
MenuApp_onRun,
|
||||
MenuApp_onClose,
|
||||
MenuApp_onEvent
|
||||
};
|
||||
@@ -33,6 +41,7 @@ WristbandApp menu_app = {
|
||||
static void MenuApp_OnStart(void)
|
||||
{
|
||||
menu_select = 0;
|
||||
menu_idle_start_sec = current_sec;
|
||||
current_state = STATE_PAIR_MENU; // 系统运行状态设为对码配置菜单
|
||||
RF_SetMode(0); // 关闭射频接收芯片,防止接收杂波干扰屏幕绘制
|
||||
UI_ShowMainMenu(menu_select); // 绘制主菜单
|
||||
@@ -40,6 +49,20 @@ static void MenuApp_OnStart(void)
|
||||
XTELL_LOG("[MenuApp] Started\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MenuApp 轮询主回调:检测闲置超时,无操作达到 MENU_IDLE_TIMEOUT_SEC 秒自动退出
|
||||
*/
|
||||
static void MenuApp_onRun(void)
|
||||
{
|
||||
u8 elapsed = (current_sec >= menu_idle_start_sec)
|
||||
? (current_sec - menu_idle_start_sec)
|
||||
: (60 + current_sec - menu_idle_start_sec);
|
||||
if (elapsed >= MENU_IDLE_TIMEOUT_SEC) {
|
||||
XTELL_LOG("[MenuApp] Idle timeout, closing.\r\n");
|
||||
AppManager_SwitchToForeground(&home_app);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MenuApp 退出清理回调
|
||||
*/
|
||||
@@ -55,6 +78,8 @@ static void MenuApp_onClose(void)
|
||||
*/
|
||||
static EventResult MenuApp_onEvent(SystemEvent *evt)
|
||||
{
|
||||
menu_idle_start_sec = current_sec; // 任意按键活动都刷新闲置计时起点
|
||||
|
||||
if (evt->key_event == KEY_EVENT_UP_CLICK) {
|
||||
// 短按 ▲ 键向上移动焦点,允许循环切换 (到顶绕到底)
|
||||
menu_select = (menu_select == 0) ? 3 : (menu_select - 1);
|
||||
|
||||
Reference in New Issue
Block a user