|
|
@ -16,46 +16,44 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
|
|
|
#include <dt-bindings/zmk/hid_usage_pages.h> |
|
|
|
#include <dt-bindings/zmk/hid_usage_pages.h> |
|
|
|
#include <zmk/endpoints.h> |
|
|
|
#include <zmk/endpoints.h> |
|
|
|
|
|
|
|
|
|
|
|
static int hid_listener_keycode_pressed(uint16_t usage_page, uint32_t keycode, |
|
|
|
static int hid_listener_keycode_pressed(const struct keycode_state_changed *ev) { |
|
|
|
zmk_mod_flags_t implicit_modifiers) { |
|
|
|
|
|
|
|
int err; |
|
|
|
int err; |
|
|
|
LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", usage_page, keycode, |
|
|
|
LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", ev->usage_page, ev->keycode, |
|
|
|
implicit_modifiers); |
|
|
|
ev->implicit_modifiers); |
|
|
|
switch (usage_page) { |
|
|
|
switch (ev->usage_page) { |
|
|
|
case HID_USAGE_KEY: |
|
|
|
case HID_USAGE_KEY: |
|
|
|
err = zmk_hid_keyboard_press(keycode); |
|
|
|
err = zmk_hid_keyboard_press(ev->keycode); |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
LOG_ERR("Unable to press keycode"); |
|
|
|
LOG_ERR("Unable to press keycode"); |
|
|
|
return err; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case HID_USAGE_CONSUMER: |
|
|
|
case HID_USAGE_CONSUMER: |
|
|
|
err = zmk_hid_consumer_press(keycode); |
|
|
|
err = zmk_hid_consumer_press(ev->keycode); |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
LOG_ERR("Unable to press keycode"); |
|
|
|
LOG_ERR("Unable to press keycode"); |
|
|
|
return err; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
zmk_hid_implicit_modifiers_press(implicit_modifiers); |
|
|
|
zmk_hid_implicit_modifiers_press(ev->implicit_modifiers); |
|
|
|
return zmk_endpoints_send_report(usage_page); |
|
|
|
return zmk_endpoints_send_report(ev->usage_page); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int hid_listener_keycode_released(uint16_t usage_page, uint32_t keycode, |
|
|
|
static int hid_listener_keycode_released(const struct keycode_state_changed *ev) { |
|
|
|
zmk_mod_flags_t implicit_modifiers) { |
|
|
|
|
|
|
|
int err; |
|
|
|
int err; |
|
|
|
LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", usage_page, keycode, |
|
|
|
LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", ev->usage_page, ev->keycode, |
|
|
|
implicit_modifiers); |
|
|
|
ev->implicit_modifiers); |
|
|
|
switch (usage_page) { |
|
|
|
switch (ev->usage_page) { |
|
|
|
case HID_USAGE_KEY: |
|
|
|
case HID_USAGE_KEY: |
|
|
|
err = zmk_hid_keyboard_release(keycode); |
|
|
|
err = zmk_hid_keyboard_release(ev->keycode); |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
LOG_ERR("Unable to release keycode"); |
|
|
|
LOG_ERR("Unable to release keycode"); |
|
|
|
return err; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case HID_USAGE_CONSUMER: |
|
|
|
case HID_USAGE_CONSUMER: |
|
|
|
err = zmk_hid_consumer_release(keycode); |
|
|
|
err = zmk_hid_consumer_release(ev->keycode); |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
LOG_ERR("Unable to release keycode"); |
|
|
|
LOG_ERR("Unable to release keycode"); |
|
|
|
return err; |
|
|
|
return err; |
|
|
@ -67,16 +65,16 @@ static int hid_listener_keycode_released(uint16_t usage_page, uint32_t keycode, |
|
|
|
// Solving this would require keeping track of which key's implicit modifiers are currently
|
|
|
|
// Solving this would require keeping track of which key's implicit modifiers are currently
|
|
|
|
// active and only releasing modifiers at that time.
|
|
|
|
// active and only releasing modifiers at that time.
|
|
|
|
zmk_hid_implicit_modifiers_release(); |
|
|
|
zmk_hid_implicit_modifiers_release(); |
|
|
|
return zmk_endpoints_send_report(usage_page); |
|
|
|
return zmk_endpoints_send_report(ev->usage_page); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int hid_listener(const zmk_event_t *eh) { |
|
|
|
int hid_listener(const zmk_event_t *eh) { |
|
|
|
const struct zmk_keycode_state_changed *ev = as_zmk_keycode_state_changed(eh); |
|
|
|
const struct zmk_keycode_state_changed *ev = as_zmk_keycode_state_changed(eh); |
|
|
|
if (ev) { |
|
|
|
if (ev) { |
|
|
|
if (ev->state) { |
|
|
|
if (ev->state) { |
|
|
|
hid_listener_keycode_pressed(ev->usage_page, ev->keycode, ev->implicit_modifiers); |
|
|
|
hid_listener_keycode_pressed(ev); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
hid_listener_keycode_released(ev->usage_page, ev->keycode, ev->implicit_modifiers); |
|
|
|
hid_listener_keycode_released(ev); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|