refactor(hid): Move hid logic into hid.c
Move the logic for picking the correct hid function into hid.c.
This commit is contained in:
parent
6150ad65c4
commit
57fca34dc0
3 changed files with 33 additions and 30 deletions
|
@ -133,6 +133,7 @@ int zmk_hid_register_mods(zmk_mod_flags_t explicit_modifiers);
|
|||
int zmk_hid_unregister_mods(zmk_mod_flags_t explicit_modifiers);
|
||||
int zmk_hid_implicit_modifiers_press(zmk_mod_flags_t implicit_modifiers);
|
||||
int zmk_hid_implicit_modifiers_release();
|
||||
|
||||
int zmk_hid_keyboard_press(zmk_key_t key);
|
||||
int zmk_hid_keyboard_release(zmk_key_t key);
|
||||
void zmk_hid_keyboard_clear();
|
||||
|
@ -141,5 +142,8 @@ int zmk_hid_consumer_press(zmk_key_t key);
|
|||
int zmk_hid_consumer_release(zmk_key_t key);
|
||||
void zmk_hid_consumer_clear();
|
||||
|
||||
int zmk_hid_press(uint32_t usage);
|
||||
int zmk_hid_release(uint32_t usage);
|
||||
|
||||
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
|
||||
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();
|
||||
|
|
|
@ -176,6 +176,26 @@ int zmk_hid_consumer_release(zmk_key_t code) {
|
|||
return 0;
|
||||
};
|
||||
|
||||
int zmk_hid_press(uint32_t usage) {
|
||||
switch (ZMK_HID_USAGE_PAGE(usage)) {
|
||||
case HID_USAGE_KEY:
|
||||
return zmk_hid_keyboard_press(ZMK_HID_USAGE_ID(usage));
|
||||
case HID_USAGE_CONSUMER:
|
||||
return zmk_hid_consumer_press(ZMK_HID_USAGE_ID(usage));
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int zmk_hid_release(uint32_t usage) {
|
||||
switch (ZMK_HID_USAGE_PAGE(usage)) {
|
||||
case HID_USAGE_KEY:
|
||||
return zmk_hid_keyboard_release(ZMK_HID_USAGE_ID(usage));
|
||||
case HID_USAGE_CONSUMER:
|
||||
return zmk_hid_consumer_release(ZMK_HID_USAGE_ID(usage));
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); }
|
||||
|
||||
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report() {
|
||||
|
|
|
@ -21,22 +21,11 @@ static int hid_listener_keycode_pressed(const struct zmk_keycode_state_changed *
|
|||
|
||||
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
|
||||
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
|
||||
switch (ev->usage_page) {
|
||||
case HID_USAGE_KEY:
|
||||
err = zmk_hid_keyboard_press(ev->keycode);
|
||||
err = zmk_hid_press(ZMK_HID_USAGE(ev->usage_page, ev->keycode));
|
||||
if (err < 0) {
|
||||
LOG_ERR("Unable to press keycode");
|
||||
LOG_DBG("Unable to press keycode");
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
case HID_USAGE_CONSUMER:
|
||||
err = zmk_hid_consumer_press(ev->keycode);
|
||||
if (err < 0) {
|
||||
LOG_ERR("Unable to press keycode");
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
explicit_mods_changed = zmk_hid_register_mods(ev->explicit_modifiers);
|
||||
implicit_mods_changed = zmk_hid_implicit_modifiers_press(ev->implicit_modifiers);
|
||||
if (ev->usage_page != HID_USAGE_KEY &&
|
||||
|
@ -56,21 +45,11 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed
|
|||
|
||||
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
|
||||
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
|
||||
switch (ev->usage_page) {
|
||||
case HID_USAGE_KEY:
|
||||
err = zmk_hid_keyboard_release(ev->keycode);
|
||||
err = zmk_hid_release(ZMK_HID_USAGE(ev->usage_page, ev->keycode));
|
||||
if (err < 0) {
|
||||
LOG_ERR("Unable to release keycode");
|
||||
LOG_DBG("Unable to release keycode");
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
case HID_USAGE_CONSUMER:
|
||||
err = zmk_hid_consumer_release(ev->keycode);
|
||||
if (err < 0) {
|
||||
LOG_ERR("Unable to release keycode");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
explicit_mods_changed = zmk_hid_unregister_mods(ev->explicit_modifiers);
|
||||
// There is a minor issue with this code.
|
||||
|
|
Loading…
Reference in a new issue