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:
@@ -20,6 +20,7 @@
|
||||
#include "keyboard_core.h"
|
||||
#include "keyboard_hid_report_event.h"
|
||||
#include "module_lifecycle.h"
|
||||
#include "settings_mode_event.h"
|
||||
#include "set_protocol_event.h"
|
||||
#include "transport_policy_event.h"
|
||||
|
||||
@@ -94,6 +95,7 @@ struct keyboard_core_module_ctx {
|
||||
enum keyboard_protocol_mode transport_protocol_modes[HID_TRANSPORT_COUNT];
|
||||
enum hid_transport_policy current_transport;
|
||||
bool mode_valid;
|
||||
bool settings_active;
|
||||
};
|
||||
|
||||
static int do_init(void);
|
||||
@@ -130,6 +132,7 @@ static struct keyboard_core_module_ctx ctx = {
|
||||
#define transport_protocol_modes ctx.transport_protocol_modes
|
||||
#define current_transport ctx.current_transport
|
||||
#define mode_valid ctx.mode_valid
|
||||
#define settings_active ctx.settings_active
|
||||
#define running module_lifecycle_is_running(&ctx.lc)
|
||||
|
||||
static bool policy_to_transport(enum hid_transport_policy policy,
|
||||
@@ -364,6 +367,7 @@ static void submit_consumer_fifo_frame(uint16_t usage_id)
|
||||
enum mode_switch_mode mode;
|
||||
|
||||
if (!running || !mode_valid ||
|
||||
settings_active ||
|
||||
!transport_policy_to_mode(current_transport, &mode) ||
|
||||
(protocol_mode == KEYBOARD_PROTOCOL_MODE_BOOT)) {
|
||||
return;
|
||||
@@ -414,6 +418,10 @@ static void emit_keys_report(bool force)
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (protocol_mode == KEYBOARD_PROTOCOL_MODE_BOOT) {
|
||||
build_boot_report(report_buf);
|
||||
report_size = KEYBOARD_BOOT_REPORT_SIZE;
|
||||
@@ -445,6 +453,7 @@ static void emit_consumer_report(bool force)
|
||||
enum mode_switch_mode mode;
|
||||
|
||||
if (!mode_valid || !transport_policy_to_mode(current_transport, &mode) ||
|
||||
settings_active ||
|
||||
(protocol_mode == KEYBOARD_PROTOCOL_MODE_BOOT)) {
|
||||
return;
|
||||
}
|
||||
@@ -518,6 +527,7 @@ static int do_init(void)
|
||||
reports_cache_invalidate();
|
||||
function_usage_mask_clear();
|
||||
mode_valid = false;
|
||||
settings_active = false;
|
||||
transport_protocol_modes[HID_TRANSPORT_USB] =
|
||||
KEYBOARD_PROTOCOL_MODE_REPORT;
|
||||
transport_protocol_modes[HID_TRANSPORT_BLE] =
|
||||
@@ -562,6 +572,10 @@ static bool handle_button_event(const struct button_event *event)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (settings_active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
entry = keymap_get(event->key_id);
|
||||
if (!entry) {
|
||||
LOG_WRN("Unmapped key id 0x%04x", event->key_id);
|
||||
@@ -639,6 +653,10 @@ static bool handle_encoder_event(const struct encoder_event *event)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (settings_active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (event->detents > 0) {
|
||||
submit_consumer_pulse_frames(KEYBOARD_CONSUMER_CTRL_VOLUME_UP,
|
||||
(uint8_t)event->detents);
|
||||
@@ -703,6 +721,27 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
cast_transport_policy_event(aeh));
|
||||
}
|
||||
|
||||
if (is_settings_mode_event(aeh)) {
|
||||
const struct settings_mode_event *event =
|
||||
cast_settings_mode_event(aeh);
|
||||
|
||||
if (settings_active == event->active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
settings_active = event->active;
|
||||
if (settings_active) {
|
||||
if (mode_valid) {
|
||||
emit_release_reports(current_transport);
|
||||
}
|
||||
emit_function_state_event();
|
||||
keyboard_state_clear();
|
||||
reports_cache_invalidate();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_module_state_event(aeh)) {
|
||||
const struct module_state_event *event = cast_module_state_event(aeh);
|
||||
|
||||
@@ -738,6 +777,7 @@ APP_EVENT_SUBSCRIBE(MODULE, button_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, encoder_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, function_bitmap_update_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, set_protocol_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, settings_mode_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, transport_policy_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);
|
||||
APP_EVENT_SUBSCRIBE_EARLY(MODULE, power_down_event);
|
||||
|
||||
Reference in New Issue
Block a user