forked from zmkfirmware/zmk
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use input system for pointer events.
- Loading branch information
1 parent
18c62cd
commit fc6f0ad
Showing
7 changed files
with
109 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2020 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/input/input.h> | ||
#include <zephyr/dt-bindings/input/input-event-codes.h> | ||
|
||
#include <zmk/mouse.h> | ||
#include <zmk/endpoints.h> | ||
#include <zmk/hid.h> | ||
|
||
void handle_rel_code(struct input_event *evt) { | ||
switch (evt->code) { | ||
case INPUT_REL_X: | ||
zmk_hid_mouse_movement_update(evt->value, 0); | ||
break; | ||
case INPUT_REL_Y: | ||
zmk_hid_mouse_movement_update(0, evt->value); | ||
break; | ||
case INPUT_REL_WHEEL: | ||
zmk_hid_mouse_scroll_update(0, evt->value); | ||
break; | ||
case INPUT_REL_HWHEEL: | ||
zmk_hid_mouse_scroll_update(evt->value, 0); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void handle_key_code(struct input_event *evt) { | ||
|
||
switch (evt->code) { | ||
case INPUT_BTN_0: | ||
case INPUT_BTN_1: | ||
case INPUT_BTN_2: | ||
case INPUT_BTN_3: | ||
case INPUT_BTN_4: | ||
int8_t btn = evt->code - INPUT_BTN_0; | ||
if (evt->value > 0) { | ||
zmk_hid_mouse_button_press(btn); | ||
} else { | ||
zmk_hid_mouse_button_release(btn); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void input_handler(struct input_event *evt) { | ||
switch (evt->type) { | ||
case INPUT_EV_REL: | ||
handle_rel_code(evt); | ||
break; | ||
case INPUT_EV_KEY: | ||
handle_key_code(evt); | ||
} | ||
|
||
if (evt->sync) { | ||
zmk_endpoints_send_mouse_report(); | ||
} | ||
} | ||
|
||
INPUT_CALLBACK_DEFINE(NULL, input_handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters