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:
133
App/app_set_clock.c
Normal file
133
App/app_set_clock.c
Normal file
@@ -0,0 +1,133 @@
|
||||
#include "app_manager.h"
|
||||
#include "clock.h"
|
||||
#include "xtell.h"
|
||||
#include "ui.h"
|
||||
#include "rgb.h"
|
||||
#include "event.h"
|
||||
#include "system.h"
|
||||
#include "../Drivers/pcf8563.h"
|
||||
|
||||
// 外部引用的全局系统状态变量
|
||||
extern SystemState current_state;
|
||||
extern volatile u16 ms_tick;
|
||||
|
||||
// 本应用私有的时间编辑状态
|
||||
static u8 time_edit_field = 1; // 标识当前聚焦在哪一个参数上进行微调 (1:修改小时, 2:修改分钟)
|
||||
static u8 time_edit_blink_on = 1; // 时钟修改时光标闪烁周期状态位
|
||||
|
||||
// 声明本应用的生命周期回调函数
|
||||
static void SetClockApp_OnStart(void);
|
||||
static void SetClockApp_onRun(void);
|
||||
static void SetClockApp_onClose(void);
|
||||
static EventResult SetClockApp_onEvent(SystemEvent *evt);
|
||||
|
||||
// 实体化定义时间设置应用控制块 (从 menu_app 的"HORLOGE"选项进入)
|
||||
WristbandApp set_clock_app = {
|
||||
APP_ID_SET_CLOCK,
|
||||
"SetClock",
|
||||
SetClockApp_OnStart,
|
||||
SetClockApp_onRun,
|
||||
SetClockApp_onClose,
|
||||
SetClockApp_onEvent
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief SetClockApp 启动回调
|
||||
*/
|
||||
static void SetClockApp_OnStart(void)
|
||||
{
|
||||
time_edit_field = 1;
|
||||
time_edit_blink_on = 1;
|
||||
current_state = STATE_SET_TIME; // 系统切入时间设置状态
|
||||
|
||||
// FCOB 幻彩灯条双灯珠均显示蓝色常亮 (R=0, G=0, B=180),进行模式视觉区分
|
||||
RGB_Send(0, 0, 180, 0, 0, 180);
|
||||
|
||||
// 振动马达单次短震 50 毫秒,提供触觉反馈
|
||||
MOTOR = 1;
|
||||
Delay_ms(50);
|
||||
MOTOR = 0;
|
||||
|
||||
// 渲染显示时间编辑界面,默认高亮编辑小时字段,消隐位开启
|
||||
UI_ShowSetTimePage(current_hour, current_min, time_edit_field, 1);
|
||||
XTELL_LOG("[SetClockApp] Started\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SetClockApp 轮询主回调
|
||||
*/
|
||||
static void SetClockApp_onRun(void)
|
||||
{
|
||||
// ====== 时间设置闪烁动画 (周期 500ms) ======
|
||||
u8 blink = (ms_tick / 500) % 2;
|
||||
if (blink != time_edit_blink_on)
|
||||
{
|
||||
time_edit_blink_on = blink;
|
||||
// 每次闪烁状态发生变化,重新刷写屏幕数值
|
||||
UI_ShowSetTimePage(current_hour, current_min, time_edit_field, time_edit_blink_on);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SetClockApp 退出清理回调
|
||||
*/
|
||||
static void SetClockApp_onClose(void)
|
||||
{
|
||||
RGB_Send(0, 0, 0, 0, 0, 0); // 关闭灯条
|
||||
XTELL_LOG("[SetClockApp] Closed\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SetClockApp 接收按键事件处理回调
|
||||
*/
|
||||
static EventResult SetClockApp_onEvent(SystemEvent *evt)
|
||||
{
|
||||
if (evt->key_event == KEY_EVENT_UP_CLICK)
|
||||
{
|
||||
// 短按 ▲ 键增加数值 (小时/分钟循环相加)
|
||||
if (time_edit_field == 1) {
|
||||
current_hour = (current_hour + 1) % 24;
|
||||
} else {
|
||||
current_min = (current_min + 1) % 60;
|
||||
}
|
||||
UI_ShowSetTimePage(current_hour, current_min, time_edit_field, 1);
|
||||
return EVENT_HANDLED;
|
||||
}
|
||||
if (evt->key_event == KEY_EVENT_DOWN_CLICK)
|
||||
{
|
||||
// 短按 ▼ 键减小数值
|
||||
if (time_edit_field == 1) {
|
||||
current_hour = (current_hour == 0) ? 23 : (current_hour - 1);
|
||||
} else {
|
||||
current_min = (current_min == 0) ? 59 : (current_min - 1);
|
||||
}
|
||||
UI_ShowSetTimePage(current_hour, current_min, time_edit_field, 1);
|
||||
return EVENT_HANDLED;
|
||||
}
|
||||
if (evt->key_event == KEY_EVENT_CONFIRM_LONG)
|
||||
{
|
||||
// 长按 ■ 确认键切换调节字段 (在修改小时与修改分钟间跳转)
|
||||
if (time_edit_field == 1) {
|
||||
time_edit_field = 2;
|
||||
} else {
|
||||
time_edit_field = 1;
|
||||
}
|
||||
UI_ShowSetTimePage(current_hour, current_min, time_edit_field, 1);
|
||||
return EVENT_HANDLED;
|
||||
}
|
||||
if (evt->key_event == KEY_EVENT_CONFIRM_CLICK)
|
||||
{
|
||||
// 短按 ■ 确认键保存最新时钟配置,退出到主菜单 (父 App)
|
||||
current_state = STATE_PAIR_MENU;
|
||||
|
||||
// 同步将最新时间 (hour, min, 0秒) 写入 PCF8563 芯片寄存器
|
||||
PCF8563_WriteTime(current_hour, current_min, 0);
|
||||
|
||||
// 退出短振反馈
|
||||
MOTOR = 1; Delay_ms(50); MOTOR = 0;
|
||||
|
||||
AppManager_SwitchToForeground(&menu_app);
|
||||
return EVENT_HANDLED;
|
||||
}
|
||||
return EVENT_HANDLED; // 在时间设置模式下屏蔽拦截其他一切无关按键事件
|
||||
}
|
||||
Reference in New Issue
Block a user