diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/include/zmk/hid.h | 2 | ||||
-rw-r--r-- | app/src/endpoints.c | 12 | ||||
-rw-r--r-- | app/src/hid.c | 4 |
3 files changed, 17 insertions, 1 deletions
diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index 744de98..04b12e1 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -165,9 +165,11 @@ int zmk_hid_register_mods(zmk_mod_flags modifiers); int zmk_hid_unregister_mods(zmk_mod_flags modifiers); int zmk_hid_keypad_press(zmk_key key); int zmk_hid_keypad_release(zmk_key key); +void zmk_hid_keypad_clear(); int zmk_hid_consumer_press(zmk_key key); int zmk_hid_consumer_release(zmk_key key); +void zmk_hid_consumer_clear(); struct zmk_hid_keypad_report *zmk_hid_get_keypad_report(); struct zmk_hid_consumer_report *zmk_hid_get_consumer_report(); diff --git a/app/src/endpoints.c b/app/src/endpoints.c index 4f56aa5..3acaba6 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -126,11 +126,21 @@ static enum endpoint get_selected_endpoint() { return ENDPOINT_USB; } +static void disconnect_current_endpoint() { + zmk_hid_keypad_clear(); + zmk_hid_consumer_clear(); + + zmk_endpoints_send_report(USAGE_KEYPAD); + zmk_endpoints_send_report(USAGE_CONSUMER); +} + static int endpoint_listener(const struct zmk_event_header *eh) { enum endpoint new_endpoint = get_selected_endpoint(); if (new_endpoint != current_endpoint) { - // TODO: send null report on previous endpoint + /* Cancel all current keypresses so keys don't stay held on the old endpoint. */ + disconnect_current_endpoint(); + current_endpoint = new_endpoint; LOG_INF("Endpoint changed: %d", current_endpoint); } diff --git a/app/src/hid.c b/app/src/hid.c index f80906c..8f6c388 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -94,6 +94,8 @@ int zmk_hid_keypad_release(zmk_key code) { return 0; }; +void zmk_hid_keypad_clear() { memset(&kp_report.body, 0, sizeof(kp_report.body)); } + int zmk_hid_consumer_press(zmk_key code) { TOGGLE_CONSUMER(0U, code); return 0; @@ -104,6 +106,8 @@ int zmk_hid_consumer_release(zmk_key code) { return 0; }; +void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); } + struct zmk_hid_keypad_report *zmk_hid_get_keypad_report() { return &kp_report; } |