feat: 添加设置模块和相关UI功能

- 新增settings_module.c实现设置菜单逻辑,包括蓝牙配对槽位管理和主题颜色选择
- 添加settings_mode_event.h/.c和settings_view_event.h/.c事件定义用于设置模式切换
- 创建settings_ui.h定义设置界面状态结构体和页面枚举
- 修改display_module.c集成设置UI显示逻辑,支持主界面和设置界面切换
- 在keyboard_core_module.c中添加设置活动状态检查,避免设置模式下键盘输入冲突
- 更新CMakeLists.txt包含新的源文件:settings_module.c、ui_settings.c及新事件文件
- 修改prj.conf调整LVGL内存池大小从16KB到32KB以支持更复杂UI渲染
- 移除BLE配对擦除相关配置选项并增加长按检测时间到1500毫秒
- 更新ui_main.c添加可见性控制函数用于界面切换
This commit is contained in:
2026-04-23 15:12:29 +08:00
parent 6a03df1b39
commit fbdc5426be
14 changed files with 1181 additions and 8 deletions

View File

@@ -18,9 +18,13 @@
#include "hid_led_event.h"
#include "module_lifecycle.h"
#include "mode_switch_event.h"
#include "settings_mode_event.h"
#include "settings_ui.h"
#include "settings_view_event.h"
#include "theme_rgb_update_event.h"
#include "theme_color.h"
#include "ui/ui_main.h"
#include "ui/ui_settings.h"
LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
@@ -34,6 +38,9 @@ struct display_module_ctx {
const struct device *backlight_dev;
uint32_t backlight_idx;
struct ui_main_model ui_model;
struct settings_ui_state settings_ui;
bool settings_active;
bool settings_ui_valid;
bool lvgl_initialized;
char date_text[DATETIME_EVENT_DATE_TEXT_LEN];
char time_text[DATETIME_EVENT_TIME_TEXT_LEN];
@@ -127,6 +134,7 @@ static int do_start(void)
lvgl_lock();
ui_main_init(&ctx.ui_model, ctx.date_text, ctx.time_text);
ui_settings_init(NULL);
lvgl_unlock();
}
@@ -167,8 +175,16 @@ static void refresh_ui(void)
return;
}
if (ctx.settings_active && !ctx.settings_ui_valid) {
return;
}
lvgl_lock();
ui_main_refresh_all(&ctx.ui_model, ctx.date_text, ctx.time_text);
if (ctx.settings_active) {
ui_settings_refresh(&ctx.settings_ui, true);
} else {
ui_main_refresh_all(&ctx.ui_model, ctx.date_text, ctx.time_text);
}
lvgl_unlock();
}
@@ -207,6 +223,47 @@ static bool app_event_handler(const struct app_event_header *aeh)
ctx.ui_model.theme_color = (lv_color_t)LV_COLOR_MAKE(event->theme.r,
event->theme.g,
event->theme.b);
ctx.settings_ui.accent = event->theme;
refresh_ui();
return false;
}
if (is_settings_mode_event(aeh)) {
const struct settings_mode_event *event =
cast_settings_mode_event(aeh);
ctx.settings_active = event->active;
ctx.settings_ui_valid = false;
if (!ctx.lvgl_initialized) {
return false;
}
lvgl_lock();
if (!ctx.settings_active) {
ui_settings_set_visible(false);
ui_main_set_visible(true);
ui_main_refresh_all(&ctx.ui_model, ctx.date_text,
ctx.time_text);
}
lvgl_unlock();
return false;
}
if (is_settings_view_event(aeh)) {
const struct settings_view_event *event =
cast_settings_view_event(aeh);
ctx.settings_ui = event->state;
ctx.settings_ui_valid = true;
if (ctx.settings_active && ctx.lvgl_initialized) {
lvgl_lock();
ui_settings_refresh(&ctx.settings_ui, false);
ui_main_set_visible(false);
ui_settings_set_visible(true);
lvgl_unlock();
return false;
}
refresh_ui();
return false;
}
@@ -257,6 +314,8 @@ APP_EVENT_SUBSCRIBE(MODULE, datetime_event);
APP_EVENT_SUBSCRIBE(MODULE, hid_led_event);
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);
APP_EVENT_SUBSCRIBE(MODULE, mode_switch_event);
APP_EVENT_SUBSCRIBE(MODULE, settings_mode_event);
APP_EVENT_SUBSCRIBE(MODULE, settings_view_event);
APP_EVENT_SUBSCRIBE(MODULE, theme_rgb_update_event);
APP_EVENT_SUBSCRIBE_EARLY(MODULE, power_down_event);
APP_EVENT_SUBSCRIBE(MODULE, wake_up_event);