Splits the ad-hoc menu_level state machine into standalone Apps with a uniform parent/child exit convention (long-press CONFIRM -> parent): clock_app renamed to home_app (boot-default), new set_clock_app extracted from home_app's time-edit mode, new ipc_bind_app extracted from menu_app's old level-2 screen, and the sensor-type selection step merged into pair_app as its new initial state. menu_app now only holds the 4-item top-level list (language toggle inline). Also makes both menu_app and pair_app's up/down navigation cyclic (wraps at both ends).
98 lines
3.5 KiB
C
98 lines
3.5 KiB
C
#include "app_manager.h"
|
||
#include "xtell.h"
|
||
#include "ui.h"
|
||
#include "rgb.h"
|
||
#include "event.h"
|
||
#include "system.h"
|
||
#include "database.h"
|
||
#include "language.h"
|
||
#include "../Drivers/rf.h"
|
||
|
||
// 外部全局变量引用
|
||
extern SystemState current_state;
|
||
extern u8 menu_select;
|
||
|
||
// 声明本应用的生命周期回调函数
|
||
static void MenuApp_OnStart(void);
|
||
static void MenuApp_onClose(void);
|
||
static EventResult MenuApp_onEvent(SystemEvent *evt);
|
||
|
||
// 实体化定义菜单应用控制块 (顶层 4 项列表:语言切换/时间设置/传感器配对/摄像头绑定)
|
||
WristbandApp menu_app = {
|
||
APP_ID_MENU,
|
||
"Menu",
|
||
MenuApp_OnStart,
|
||
NULL,
|
||
MenuApp_onClose,
|
||
MenuApp_onEvent
|
||
};
|
||
|
||
/**
|
||
* @brief MenuApp 启动回调
|
||
*/
|
||
static void MenuApp_OnStart(void)
|
||
{
|
||
menu_select = 0;
|
||
current_state = STATE_PAIR_MENU; // 系统运行状态设为对码配置菜单
|
||
RF_SetMode(0); // 关闭射频接收芯片,防止接收杂波干扰屏幕绘制
|
||
UI_ShowMainMenu(menu_select); // 绘制主菜单
|
||
RGB_Send(0, 0, 0, 0, 0, 0); // 熄灭所有灯条
|
||
XTELL_LOG("[MenuApp] Started\r\n");
|
||
}
|
||
|
||
/**
|
||
* @brief MenuApp 退出清理回调
|
||
*/
|
||
static void MenuApp_onClose(void)
|
||
{
|
||
RGB_Send(0, 0, 0, 0, 0, 0); // 熄灭 RGB
|
||
RF_SetMode(1); // 重新开启无线接收模式
|
||
XTELL_LOG("[MenuApp] Closed\r\n");
|
||
}
|
||
|
||
/**
|
||
* @brief MenuApp 接收按键与控制事件回调 (0-语言切换, 1-HORLOGE, 2-APPAIRAGE, 3-LIAISON)
|
||
*/
|
||
static EventResult MenuApp_onEvent(SystemEvent *evt)
|
||
{
|
||
if (evt->key_event == KEY_EVENT_UP_CLICK) {
|
||
// 短按 ▲ 键向上移动焦点,允许循环切换 (到顶绕到底)
|
||
menu_select = (menu_select == 0) ? 3 : (menu_select - 1);
|
||
UI_ShowMainMenu(menu_select);
|
||
return EVENT_HANDLED;
|
||
}
|
||
if (evt->key_event == KEY_EVENT_DOWN_CLICK) {
|
||
// 短按 ▼ 键向下移动焦点,允许循环切换 (到底绕到顶)
|
||
menu_select = (menu_select == 3) ? 0 : (menu_select + 1);
|
||
UI_ShowMainMenu(menu_select);
|
||
return EVENT_HANDLED;
|
||
}
|
||
if (evt->key_event == KEY_EVENT_CONFIRM_CLICK) {
|
||
// 短按 ■ 确认键,进入选定功能的子页面
|
||
if (menu_select == 0) {
|
||
// 功能 0:语言切换。原地在 FR/EN 间切换,立即保存并用新语言重绘当前菜单
|
||
Language new_lang = (Lang_Current() == LANG_FR) ? LANG_EN : LANG_FR;
|
||
Lang_Set(new_lang);
|
||
Save_Database(); // 语言字节与传感器数据库共用同一扇区持久化
|
||
MOTOR = 1; Delay_ms(50); MOTOR = 0; // 短震反馈,与其它确认操作风格一致
|
||
UI_ShowMainMenu(menu_select);
|
||
} else if (menu_select == 1) {
|
||
// 功能 1:设置时间。切换到独立的时间设置子 App
|
||
AppManager_SwitchToForeground(&set_clock_app);
|
||
} else if (menu_select == 2) {
|
||
// 功能 2:传感器学习。切换到独立的对码子 App (类型选择是它的第一个状态)
|
||
AppManager_SwitchToForeground(&pair_app);
|
||
} else if (menu_select == 3) {
|
||
// 功能 3:相机配对。切换到独立的摄像头绑定子 App
|
||
AppManager_SwitchToForeground(&ipc_bind_app);
|
||
}
|
||
return EVENT_HANDLED;
|
||
}
|
||
if (evt->key_event == KEY_EVENT_CONFIRM_LONG) {
|
||
// 长按 ■ 确认键,退出设置菜单直接返回待机主页
|
||
AppManager_SwitchToForeground(&home_app);
|
||
return EVENT_HANDLED;
|
||
}
|
||
return EVENT_IGNORED;
|
||
}
|