refactor: 提升 HID 按键发送逻辑的可重用性

- 将发送 HID 按键的逻辑提取到 send_hid_combo_or_warn 函数中
- 更新 on_boot_press 函数以使用新的发送逻辑
- 在按钮点击事件处理函数中调用 send_hid_combo_or_warn,简化代码并增强可读性
This commit is contained in:
2026-07-02 08:57:55 +08:00
parent 68dd7e95ab
commit e056a113a2
2 changed files with 12 additions and 2 deletions
+10 -2
View File
@@ -9,15 +9,20 @@
static const char *TAG = "ui_handlers"; static const char *TAG = "ui_handlers";
static void on_boot_press(void) static void send_hid_combo_or_warn(uint8_t modifier, uint8_t keycode)
{ {
if (ble_hid_ready()) { if (ble_hid_ready()) {
ble_hid_send_combo(0, HID_KEY_C); ble_hid_send_combo(modifier, keycode);
} else { } else {
ESP_LOGW(TAG, "HID not ready"); ESP_LOGW(TAG, "HID not ready");
} }
} }
static void on_boot_press(void)
{
send_hid_combo_or_warn(0, HID_KEY_C);
}
void ui_handlers_init(void) void ui_handlers_init(void)
{ {
boot_button_init(on_boot_press); boot_button_init(on_boot_press);
@@ -31,14 +36,17 @@ void update_year_action(lv_event_t * e)
void click_button_two(lv_event_t * e) void click_button_two(lv_event_t * e)
{ {
(void)e; (void)e;
send_hid_combo_or_warn(HID_MOD_LCTRL, HID_KEY_C);
} }
void click_button_three(lv_event_t * e) void click_button_three(lv_event_t * e)
{ {
(void)e; (void)e;
send_hid_combo_or_warn(HID_MOD_LCTRL, HID_KEY_V);
} }
void click_button_one(lv_event_t * e) void click_button_one(lv_event_t * e)
{ {
(void)e; (void)e;
send_hid_combo_or_warn(HID_MOD_LCTRL, HID_KEY_X);
} }
+2
View File
@@ -9,6 +9,8 @@
#define HID_MOD_LGUI 0x08 #define HID_MOD_LGUI 0x08
#define HID_KEY_C 0x06 #define HID_KEY_C 0x06
#define HID_KEY_V 0x19
#define HID_KEY_X 0x1B
#define HID_KEY_F5 0x3E #define HID_KEY_F5 0x3E
typedef void (*ble_hid_status_cb_t)(bool connected); typedef void (*ble_hid_status_cb_t)(bool connected);