Exclusive use of touchscreen by my addon

  • I want to create an addon that uses simple touchscreen events (x y location of a touch) to control video interactions, such as sending seeks to different locations in a video.

    And, I want Kodi to ignore the touchscreen events

    evtest identifies my touchscreen as using event 1.

    But Libreelec/Kodi seems to have grabbed exclusive access to /dev/input/event1, and evtest can't read the events. A simple python event reader program can't read any events.

    I installed the Touchscreen addon, which gives Kodi access to the touchscreen, but evtest says that the events are still not available.

    I've looked through the Touchscreen addon, but I can't quite figure out what is going on, let alone figure out how to modify it to do what I want.

    Any suggestions?

    Thanks,

    -Jeff

  • vpeter:

    Thanks for the response. Funny enough, you pointed me to my original post on this topic 3 years ago.

    At the time, I was unable to figure out how to do some of the things suggested.

    But, I just re-read the thread, and I'm going to try some of the suggestions again. Maybe my programming skills are better now.

  • vpeter:

    I tried to follow your 2019 suggestion

    JeffR, you just need to run python script before kodi is started. Make a service like I did for touchscreen addon: LibreELEC.tv/service.touchscreen.service at master · LibreELEC/LibreELEC.tv · GitHub

    Based on your service.touchscreen.service example, I created mytouch.service in /storage/.config/system.d
    I replaced your commands with: ExecStart=-/bin/sh -c "exec /bin/sh /storage/mytouch.sh service"

    And my mstouch.sh was:

    $!/usr/bin/sh

    echo "Starting touch.py from mytouch.sh"

    python /storage/3touch.py >>3touch.out 2>&1 &

    3touch.py tries to open the USB device, read events, and print out the event, which should be captured to 3touch.out

    I enabled the service and systemctl is-active mytouch.service shows that it is running after rebooting.

    But neither mytouch.sh or 3touch.py shows up with a ps listing.

    Oh, and I disabled your Touchscreen addon and service, to make it cleaner..

    I also tried HiassofT's suggestion of creating a udev rule using LIBINPUT_IGNORE_DEVICE, but again, I am not familiar with this at all, and again failed.

    My current thought is to explore /dev/usb/hiddev0. I can detect events, but they don't decode like event0 events, so I'm a little stuped right now.

    Like 3 years ago, I'm pretty stumped.

  • Update:

    After some iteration, I have a working service based on the service.touchscreen.service example, as vpeter suggested.

    (Yeah, I had little errors all over the place when I made the previous post. Sorry about that)

    The service launches my updated touch.py reader program, which reads from the touch panel and logs the results to a file.

    If I touch the screen during bootup, the log shows about 6 seconds of touchpanel reads, and then stops.

    While kodi is running, it does not log any touchscreen events.

    If I systemctl stop kodi, the log starts reporting touches again.

    The touch.py program opens the event file, but does not close it.

    I had hoped that by opening the event file first, it would prevent Kodi from doing an exclusive grab, but no luck.

    I also tried adding this command after opening the event file, with no change in behavior.

    fcntl.flock(fd, fcntl.LOCK_EX)

  • SOLVED!!!!

    I found an example of an exclusive IO grab in python in PythonUSBBarcodeScanner.py written by Richard Aplin https://gist.github.com/raplin

    The key lines of code are:

    definitions of IOW and IOC functions up front

    EVIOCGRAB = lambda len: IOW(ord('E'), 0x90, ctypes.c_int)

    fcntl.ioctl(fd, EVIOCGRAB(1), True) #add this line to right after the event file is opened

    As noted earlier, I created a service to launch the python program before Kodi.

    I now log all touch X Y data to a text file that can be read by my Kodi addon.

    Kodi never sees the touch events, so the "Now Playing" popup doesn't pop up.