userspace touchscreen support

Peter Hutterer peter.hutterer at who-t.net
Thu Jan 28 16:55:42 PST 2016


On Thu, Jan 28, 2016 at 08:12:36AM -0500, Trevor Woerner wrote:
> Hi,
> 
> I have one of those 7" touchscreens that has both an HDMI port and a USB
> port. I'm writing code in userspace to handle the touch events:

I'm not sure I understand why you are writing userspace code to handle the
touch events. Why not use the kernel HID MT drivers? Your last paragraph
says it doesn't work OOTB so I'm CC-ing Benjamin, if there is a quirk needed
for this specific device, he's likely to know.

> 1. using libudev to detect/find the device and its associated device
> node (/dev/hidrawX)
> 
> 2. creating a virtual uinput device to send the interpreted touch events
> to the OS
> 
> When I plug in the screen's USB port to my system I get:
> 
> hid-generic 0003:0EEF:0005.0004: hiddev0,hidraw2: USB HID v1.10 Device
> [RPI_TOUCH By ZH851] on usb-0000:00:14.0-2/input0
> 
> Reading and interpreting the touch events works great. I barely have to
> touch the screen with anywhere from 1 to 5 fingers, I receive the events
> and are able to interpret them just fine.
> 
> The odd part is sending them to the uinput side. Sending just one set of
> events for any one touch is never enough. I always have to touch and
> hold for about half-a-second before the cursor moves, which means about
> 7-10 events are generated and sent. Sometimes the cursor will move with
> as few as 3-4 events, but usually more are needed. Originally I had
> added code to detect and ignore duplicates, but I had to remove that
> code since things won't work if only one event set is generated.
> 
> Here's what one touch event set looks like:
> 
> {hdmi-usb-touch.c:0797} aa 01 00 ed 01 38 bb 01 00 00 00 00 00 00 00 00
> 00 00 00 00 00 00 00 00 cc
> {hdmi-usb-touch.c:0837} x0:237   y0:312   
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_ABS 
> code:ABS_MT_SLOT          value:0
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_ABS 
> code:ABS_MT_TRACKING_ID   value:0
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_ABS 
> code:ABS_MT_POSITION_X    value:237
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_ABS 
> code:ABS_MT_POSITION_Y    value:312
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_SYN 
> code:SYN_MT_REPORT        value:0

if you use slots, don't use SYN_MT_REPORT. just update the slots
independently and send a normal SYN_REPORT at the end of the frame.  see
Documentation/input/multi-touch-protocol.txt for more info.

Cheers,
   Peter


> {hdmi-usb-touch.c:0306}
> {hdmi-usb-touch.c:0797} aa 00 00 00 00 00 bb 01 01 e0 03 20 01 e0 03 20
> 01 e0 03 20 01 e0 03 20 cc
> {hdmi-usb-touch.c:0837} x0:0     y0:0     
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_SYN 
> code:SYN_MT_REPORT        value:0
> {hdmi-usb-touch.c:0306}
> {hdmi-usb-touch.c:0797} aa 00 00 00 00 00 bb 00 00 00 00 00 00 00 00 00
> 00 00 00 00 00 00 00 00 00
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_ABS 
> code:ABS_MT_SLOT          value:0
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_ABS 
> code:ABS_MT_TRACKING_ID   value:-1
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_SYN 
> code:SYN_MT_REPORT        value:0
> {hdmi-usb-touch.c:0306}
> {hdmi-usb-touch.c:0797} aa 00 00 00 00 00 bb 00 00 00 00 00 00 00 00 00
> 00 00 00 00 00 00 00 00 00
> {hdmi-usb-touch.c:0425}   => (duplicate)
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_SYN 
> code:SYN_MT_REPORT        value:0
> {hdmi-usb-touch.c:0306}
> {hdmi-usb-touch.c:0797} aa 00 00 00 00 00 bb 00 00 00 00 00 00 00 00 00
> 00 00 00 00 00 00 00 00 00
> {hdmi-usb-touch.c:0425}   => (duplicate)
> {hdmi-usb-touch.c:0262} => uinput event: type:EV_SYN 
> code:SYN_MT_REPORT        value:0
> {hdmi-usb-touch.c:0306}
> 
> The above, of course, wouldn't be successful. In order to succeed the
> first 8 lines would need to be repeated several more times, followed by
> the rest of the above block.
> 
> Here are some of the components I'm running:
>     libudev0_182
>     xserver-xorg_2:1.18.0
>     xf86-video-intel_2:2.99.917
>     xf86-input-evdev_2:2.10.1
>     xinput_1.6.2
>     metacity_2.34.13
> 
> I have other questions but I'll just ask the one for now. I realize this
> issue might be related to a number of different pieces of code, but
> hopefully someone has some ideas?
> 
> The USB data from some such 7" displays masquerade as mouse events (e.g.
> one of the screens from Adafruit). Those displays work "out of the box"
> with Linux; just plug and play. Mine, however, doesn't; mine shows up as
> hidraw.
> 
> Thanks and best regards,
>     Trevor


More information about the xorg mailing list