Rotary encoder & Qt Events?
-
Currently i'm having a rotary encoder hooked up to my Linux Platform. Its listed as input under: /dev/input/event0
Its generating the following output:
Testing ... (interrupt to exit) Event: time 1325378916.979387, type 2 (EV_REL), code 0 (REL_X), value 1 Event: time 1325378916.979387, -------------- SYN_REPORT ------------ Event: time 1325378917.328441, type 2 (EV_REL), code 0 (REL_X), value 1 Event: time 1325378917.328441, -------------- SYN_REPORT ------------ Event: time 1325378919.692222, type 2 (EV_REL), code 0 (REL_X), value -1 Event: time 1325378919.692222, -------------- SYN_REPORT ------------ Event: time 1325378919.760467, type 2 (EV_REL), code 0 (REL_X), value -1
Im trying to get input from the rotary in Qt with the following software in Qml
Keys.onPressed: (event)=> { print(event.key); /* Print out key */ print(event); /* Print event */
Its responding to keyboard input and buttons on the Platform. But its not reacting on the rotary encoder.
Output from buttons on the pcb:
qml: 48 qml: QQuickKeyEvent(0xa3550) qml: 48 qml: QQuickKeyEvent(0xa3550) qml: 49
What is the right way to achieve communicating with the rotary encoder?
-
Found the solution.
Using
QT_QPA_GENERIC_PLUGINS=evdevmouse:/dev/input/event0
Forced to use event0 as mouse.
-
Hi and welcome to devnet,
Is that encoder seen as a proper keyboard ?
How do you make it known to your application ? -
Hi and welcome to devnet,
Is that encoder seen as a proper keyboard ?
How do you make it known to your application ?Currently the rotary encoder is installed in the kernel under the device tree.
rotary@0 { compatible = "rotary-encoder"; gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */ linux,axis = <0>; /* REL_X */ rotary-encoder,encoding = "gray"; rotary-encoder,relative-axis; };
Its working with evtest (as well as the keyboard). But Qt does not seems to react on its event's like it does on buttons on the platform and keyboard.
-
It seems like that Qml needs to react on mouse events. Is there an handler provided for mouse events in Qml?
-
It seems like that Qml needs to react on mouse events. Is there an handler provided for mouse events in Qml?
@DrWhoozy
the 2 ways I know of are:- Installing an event filter on your QApplication and forwarding that to your qml instance
- using a MouseArea Item with hoverEnabled -> mouseX and mouseY
-
@DrWhoozy
the 2 ways I know of are:- Installing an event filter on your QApplication and forwarding that to your qml instance
- using a MouseArea Item with hoverEnabled -> mouseX and mouseY
@J-Hilk
Thanks for your response. Currently im experiencing some issues with Qt ignoring my rotary input. I've printed every event that Qt handles and it seems that it listens to USB mouse input and not my rotary. The events from an USB mouse and Rotary are looking the same...
When using the mouse on "every event" the result fom Qt is
Event: QEvent::MouseMove Watched: "" Event: QEvent::HoverMove Watched: "" X: 242 Y: 301
But it keeps quiet on the rotary event's.......
When putting on evtest im retreiving the following input from my mouse:
Event: time 1325455622.178946, type 2 (EV_REL), code 0 (REL_X), value 1 Event: time 1325455622.178946, type 2 (EV_REL), code 1 (REL_Y), value -2 Event: time 1325455622.178946, -------------- SYN_REPORT ------------ Event: time 1325455622.186938, type 2 (EV_REL), code 0 (REL_X), value 1 Event: time 1325455622.186938, type 2 (EV_REL), code 1 (REL_Y), value -3
And from the rotary
Event: time 1325455664.958945, type 2 (EV_REL), code 0 (REL_X), value -1 Event: time 1325455664.958945, -------------- SYN_REPORT ------------ Event: time 1325455664.966906, type 2 (EV_REL), code 0 (REL_X), value -1 Event: time 1325455664.966906, -------------- SYN_REPORT ------------ Event: time 1325455665.545176, type 2 (EV_REL), code 0 (REL_X), value 1 Event: time 1325455665.545176, -------------- SYN_REPORT ------------ Event: time 1325455665.548966, type 2 (EV_REL), code 0 (REL_X), value 1 Event: time 1325455665.548966, -------------- SYN_REPORT ------------
So we can more likely conclude that the rotary is acting like a mouse device. However Qt thinks different...
When using strace on the Qt Application it calls the input0
openat(12, "input0", O_RDONLY|O_LARGEFILE|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 11 fstat64(11, {st_mode=S_IFLNK|0777, st_size=0, ...}) = 0 readlinkat(12, "input0", "../../devices/platform/rotary/in"..., 4096) = 42
I tried to force it by setting some environment variables such as:
QT_LOGGING_RULES="qt.qpa.*=true" // For Logging TSLIB_TSDEVICE="/dev/input/event0"
But somehow the events are not coming through.
-
Found the solution.
Using
QT_QPA_GENERIC_PLUGINS=evdevmouse:/dev/input/event0
Forced to use event0 as mouse.