-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: pointer movement/scrolling #2027
base: main
Are you sure you want to change the base?
Feature: pointer movement/scrolling #2027
Conversation
8b2dc31
to
bd9210d
Compare
app/src/mouse/key_listener.c
Outdated
k_work_submit_to_queue(zmk_mouse_work_q(), &mouse_tick); | ||
} | ||
|
||
K_TIMER_DEFINE(mouse_timer, mouse_timer_cb, mouse_clear_cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part that initially made me bang my head against the wall with all this is the fact that Zephyr sometimes seems to de-prioritize these timers if the system is under load.
This is (as far as I was able to understand) the primary cause of the instability with mouse movement - reports can be sent out at random intervals or dropped entirely.
I was exploring re-writing this system to use a dedicated thread, but I wasn't skilled enough at C at the time.
I'm not sure this basis for the tick system is robust enough for general use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... timers should be using the hardware timers to trigger, and happen in ISR context. The queue has a certain priority, can be preempted, etc. Tweaking that thread priority might help, but I'll play a bit to see what I can determine. Thanks for the insight!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is most certainly not definitive - it's a half-remembered conclusion from an investigation I wasn't skilled enough to perform two years ago, just food for thought. I distinctly remember reports being delayed or dropped and that causing instability. hog.c:335
might also be worth taking a look at.
bd9210d
to
eab4709
Compare
|
||
/* Mouse move behavior */ | ||
#define MOVE_Y(vert) ((vert)&0xFFFF) | ||
#define MOVE_Y_DECODE(encoded) (int16_t)((encoded)&0x0000FFFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might make sense to move these decode defines outside the dt-bindings header, and to either plain mouse.h or the corresponding event headers they are used in.
32ed133
to
c2bf21b
Compare
c2bf21b
to
07c181d
Compare
Could you please change the target to https://github.com/petejohanson/zmk/tree/core/zephyr-3.5-update here? The review is unnecessarily cluttered. |
Unfortunately, that will move the PR into a different GH fork, and make a bit of a mess. I recommend reviewing each commit for clarity for now, until the Zephyr 3.5 bits are merged into ZMK |
505343b
to
d837c95
Compare
d837c95
to
a95b68b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are some missed updates for the rebase to account for 36eda571b
* Remove now-unused mouse work queue and related mouse main file. * Move ticks config into a DTS property on the two axis input behavior.
* Corrected logging for two-axis input timestamps.
* Buffer data from input devices and only surface to HID once synd'd.
0122169
to
f446ab4
Compare
* Always import mouse keys behavior and their associated listeners. * Tweak listener code to only add listener nodes when listener and the associated input device are enabled.
1d06bda
to
fbb82b7
Compare
* Dedicated mouse source directory. * Split mouse HID into dedicated USB endpoint and HoG service. * Enable composite USB device automatically, tweak the various default sizes.
fbb82b7
to
dbbeb70
Compare
Final update: it looks like this is caused by some Kernel bug in Ubuntu 22.04. In Ubuntu 21.04 and 24.04, mouse emulation works without any problems. Presumably after this commit, all mouse buttons stopped working over BT but keep working fine over USB on my Ubuntu 22.04.1 machine. I tried clearing profiles and re-pairing a number of times, even flashed the reset firmware a couple of times, but to no avail. I even manually purged the cache ( At the same time, on Macbook Pro, everything works perfectly. All mouse buttons (press, scroll, move) are available over BT. Any ideas how to debug what went wrong on Ubuntu after that commit? Edit: Just connected another keyboard with older firmware (which excludes that commit) to the same Ubuntu machine and mouse keys work fine over BT. Edit2: Mouse buttons also stopped working on Android with the newer firmware and keep working with the older one. The keyboard with a newer firmware (after the commit; non-working mouse buttons):
dmesg on connect:
bluetoothd on pairing:
btmon (Left Mouse Click):
The keyboard with an older firmware (before the commit; working mouse buttons):
dmesg on connect:
bluetoothd on pairing (also logs similar messages but much less):
btmon (Left Mouse Key Click):
|
| `MOVE_UP` | Move up | | ||
| `MOVE_DOWN` | Move down | | ||
| `MOVE_LEFT` | Move left | | ||
| `MOVE_RIGHT` | Move right | | ||
|
||
### Examples | ||
|
||
The following will send a scroll down event to the host when pressed/held: | ||
|
||
``` | ||
&msc MOVE_DOWN | ||
``` | ||
|
||
The following will send a scroll left event to the host when pressed/held: | ||
|
||
``` | ||
&msc MOVE_LEFT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is what's actually meant, right? At any rate this seems to work where MOVE_* did not...
| `MOVE_UP` | Move up | | |
| `MOVE_DOWN` | Move down | | |
| `MOVE_LEFT` | Move left | | |
| `MOVE_RIGHT` | Move right | | |
### Examples | |
The following will send a scroll down event to the host when pressed/held: | |
``` | |
&msc MOVE_DOWN | |
``` | |
The following will send a scroll left event to the host when pressed/held: | |
``` | |
&msc MOVE_LEFT | |
| `SCRL_UP` | Scroll up | | |
| `SCRL_DOWN` | Scroll down | | |
| `SCRL_LEFT` | Scroll left | | |
| `SCRL_RIGHT` | Scroll right | | |
### Examples | |
The following will send a scroll down event to the host when pressed/held: | |
&msc SCRL_DOWN
The following will send a scroll left event to the host when pressed/held:
&msc SCRL_LEFT
Very excited by the recent work on this. I can barely wait for the day we can have a single ZMK primary 'dongle' talking to 3 zmk peripherals - split keyboard left, split keyboard right, and wireless trackball (e.g. variant of Ploopy Adept). |
Mouse scroll keys work with key presses, but cannot be used by encoders. I defined several sensor behaviors like this: behaviors {
volume_encoder: volume_encoder {
compatible = "zmk,behavior-sensor-rotate";
#sensor-binding-cells = <0>;
bindings = <&kp C_VOL_UP>, <&kp C_VOL_DN>;
};
scroll_encoder: scroll_encoder {
compatible = "zmk,behavior-sensor-rotate";
#sensor-binding-cells = <0>;
bindings = <&msc SCRL_UP>, <&msc SCRL_DOWN>;
};
rgb_encoder: rgb_encoder {
compatible = "zmk,behavior-sensor-rotate";
#sensor-binding-cells = <0>;
bindings = <&rgb_ug RGB_BRI>, <&rgb_ug RGB_BRD>;
};
}; Both |
This is because the duration × move speed of the scroll behavior isn't enough for the OS to trigger a scroll. You need to either
I'd probably try a combination of the two; e.g. try a tap-ms of 50 and see if scroll speed needs increasing. |
Adding |
while adding While using this branch I found out that if I use scroll with an encoder and I scroll too fast, the scroll is never released (infinite scroll) and I have to disconnect my keyboard. |
Has @petejohanson abandoned this PR? Or is it awaiting review? (If abandoned I might try to pick it up in a follow-on PR but not if @petejohanson is still working on it) |
This isn't abandoned, I am guessing Studio work is getting more priority right now. Pete mentioned on Discord that he is planning to refactor the endpoints a bit (the current split one has some issues on some OS, like Ubuntu 22.04). Meanwhile if anyone needs a rebased branch in the very near future, you can cherry-pick from https://github.com/caksoylar/zmk/commits/caksoylar/experimental. |
Continuation of the incremental integration of the great work from @krikun98 in #778 with the movement and scrolling pieces next. Based on the rebased work from @caksoylar and and the split acceleration from @bryanforbes
TODO