refactor(app): App-per-screen navigation, remove menu_level entirely
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).
This commit is contained in:
85
App/app_ipc_bind.c
Normal file
85
App/app_ipc_bind.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "app_manager.h"
|
||||
#include "xtell.h"
|
||||
#include "ui.h"
|
||||
#include "rgb.h"
|
||||
#include "event.h"
|
||||
#include "system.h"
|
||||
#include "../Drivers/rf.h"
|
||||
|
||||
// 外部引用的全局系统状态变量
|
||||
extern SystemState current_state;
|
||||
extern volatile u16 ms_tick;
|
||||
|
||||
// 本应用私有变量
|
||||
static u16 last_bind_tx_ms = 0; // 记录上一次绑定发射的时间戳
|
||||
|
||||
// 声明本应用的生命周期回调函数
|
||||
static void IpcBindApp_OnStart(void);
|
||||
static void IpcBindApp_onRun(void);
|
||||
static void IpcBindApp_onClose(void);
|
||||
static EventResult IpcBindApp_onEvent(SystemEvent *evt);
|
||||
|
||||
// 实体化定义摄像头一键绑定应用控制块 (从 menu_app 的"LIAISON"选项进入)
|
||||
WristbandApp ipc_bind_app = {
|
||||
APP_ID_IPC_BIND,
|
||||
"IpcBind",
|
||||
IpcBindApp_OnStart,
|
||||
IpcBindApp_onRun,
|
||||
IpcBindApp_onClose,
|
||||
IpcBindApp_onEvent
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief IpcBindApp 启动回调
|
||||
*/
|
||||
static void IpcBindApp_OnStart(void)
|
||||
{
|
||||
last_bind_tx_ms = ms_tick; // 记录初始发射时间
|
||||
current_state = STATE_IPC_BIND; // 系统设为 IPC 绑定状态
|
||||
UI_ShowBindingPage(CLONED_ADDR); // 绘制相机绑定信息页
|
||||
XTELL_LOG("[IpcBindApp] Started\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IpcBindApp 轮询主回调
|
||||
*/
|
||||
static void IpcBindApp_onRun(void)
|
||||
{
|
||||
// ====== 控制青色双灯珠同步呼吸效果 (呼吸周期 1000ms) ======
|
||||
u16 breath = ms_tick % 1000;
|
||||
u8 val = (breath < 500) ? (breath * 2 / 5) : ((1000 - breath) * 2 / 5); // 亮度映射 0~200
|
||||
RGB_Send(0, val, val, 0, val, val); // 渲染青色 (G+B)
|
||||
|
||||
// ====== 控制无线发射,每 500ms 广播一次配对数据 ======
|
||||
if (ms_tick - last_bind_tx_ms >= 500 || ms_tick < last_bind_tx_ms)
|
||||
{
|
||||
last_bind_tx_ms = ms_tick; // 备份当前时间戳
|
||||
RF_SetMode(2); // 暂时切换射频芯片为发射调制模式
|
||||
EV1527_Transmit(CLONED_ADDR, 0x01); // 调制发射手环克隆 ID + 绑定数据码 0x01
|
||||
RF_SetMode(0); // 切回关闭状态,避免产生噪声
|
||||
XTELL_LOG("[IpcBindApp] Binding frame emitted\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IpcBindApp 退出清理回调
|
||||
*/
|
||||
static void IpcBindApp_onClose(void)
|
||||
{
|
||||
RGB_Send(0, 0, 0, 0, 0, 0); // 熄灭 RGB
|
||||
XTELL_LOG("[IpcBindApp] Closed\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IpcBindApp 接收按键事件处理回调
|
||||
*/
|
||||
static EventResult IpcBindApp_onEvent(SystemEvent *evt)
|
||||
{
|
||||
// 长按 ■ 确认键,取消绑定,退出发射并返回主菜单 (父 App)
|
||||
if (evt->key_event == KEY_EVENT_CONFIRM_LONG) {
|
||||
current_state = STATE_PAIR_MENU;
|
||||
AppManager_SwitchToForeground(&menu_app);
|
||||
return EVENT_HANDLED;
|
||||
}
|
||||
return EVENT_IGNORED;
|
||||
}
|
||||
Reference in New Issue
Block a user