Failure of python select.select() call on LibreElec

  • Hi,

    I'm trying to create a Kodi addon that uses USB touchpanel input to make choices about what video to play.

    I have python code that reads the touchpanel events and extracts raw x and y values.

    To make it non-blocking, I use select.select() to first test to see if there is a touch event to read, and to set a timeout.

    Everything works fine when I test it on Armbian, but when I embed the code into my Kodi addon, I never see any touchpanel events.

    The program below represents my code.
    On Armbian, the print (r) statement returns a data structure that points to the USB device file, whenever there is a touch event to read.

    On LibreElec, the print [r] statement always returns []

    Is there something stripped out of LibreElec that is making select.select not work right?

    Note: from a python shell, "import select" succeeds, so I don't think it is a missing library.

    Are there any other LibreElec restrictions that would inhibit a direct read of an input device?

    Configuration:

    Rock64 4GB

    LibreELEC/Kodi (LibreELEC 9.1.002)

    Confluence skin

    Thanks,

    -Jeff


  • What is your value for FORMAT and EVENT_SIZE?

    Try to attach keyboard and using appropriate event from /dev/input/. And check if you get r[] and print code and value (there is no x/y with keyboard).

    Last time I played with input system it worked (few years back).

  • Really? Can you clarify more? Any links maybe?

    This guy wanted to make RS232 work over USB, but it only worked sometimes:

    CH340/CH341 USB to RS232 not working

    Of course, if you use standard hardware like a memory stick, then USB works fine.

    If you use non-standard hardware with unusual protocols, then stay away from USB, and use a GPIO protocol.

    PS: I'm not a kernel hacker, but I think we have to split USB in two levels: USB transmission standard, and the protocols, which are using it. At the protocol level, it seems like some protocols have low priority, so data can get lost, even if the kernel driver is present.

  • vpeter:

    Great suggestion on testing select.select() with keyboard input. I wrote another test program (even simpler than before) to test this out, as well as testing with mouse and keyboard events.

    I tested this, but failed for both keyboard and mouse events, too.

    On Armbian, print (r) will correctly print out a data structure when I use the device, for touchpanel, keyboard, and mouse.

    On LibreELEC, I only get a stream of [ ] printed out.

    To reply to the other comments:

    Whoops! I snipped out too much in my original example code when I was posting it. I used the following:

    FORMAT = 'llHHI'
    EVENT_SIZE = struct.calcsize(FORMAT)
    But, the code never got to the read statement, due to the select.select() problem, so I didn't notice.

    Interesting note about USB reliability vs. GPIO. Unfortunately I have 22 of these type of cheap touchpanels, and I can't change at this point. (This is for interactive displays at a charity haunted house)

  • Hey JeffR , what's up? :)

    If you want to read more about LE touchscreen experience, click the last link of vpeter 's signature.

    Quote

    Interesting note about USB reliability vs. GPIO. Unfortunately I have 22 of these type of cheap touchpanels, and I can't change at this point. (This is for interactive displays at a charity haunted house)

    Maybe you can reverse-engineer those panels, and use the connectivity before the USB controller.

  • What about using evtest program? Do you get data there or it fails too? If everything working there then there could be some python/le issue.

    I didn't test with LE but on other 2 char distro where this python sample works and evtest too. And using iPazzPort keyboard with USB receiver.

  • JeffR, I was thinking: Do you have Kodi running when you execute your Python script? Because Kodi grabs input devices and other userspace programs can't use them at the same time. Maybe that's the reason for your problem and it has nothing to do with USB (which I don't believe from start). In this case you need to run your Python program before Kodi is started.This way Kodi can't grab this specific input device.

  • Yes, this is running while Kodi is running. My plan was to use this for a Kodi addon to switch videos based on the location of the touch.

    I tried to do an evtest test per vPeter's suggestion, but LibreELEC has blocked apt-get, so I can't install the package.

    If Kodi on LibreELEC has really completely blocked access to input devices, it sounds like I'm out of luck using LibreELEC.
    I'll try a clean install of Armbian and Kodi on my Rock64 and see how far I get.

    It's a shame, I really liked how smoothly Kodi was running on LibreELEC.

  • Come on, at least for USB keyboard Kodi IS the issue because it grabs input device. Not just on RPi but on every device (and here RPi is not even used). I bet touchscreen is also grabbed.

    And there is no data loss: there is no data because other process blocks to read it. Try using evtest with keyboard and you will see what I'm talking about.

    Wondering why USB memory stick works on RPi? Maybe someone should make GPIO based memory stick to make it safer :S

  • Also, does Kodi also needs to read touchscreen events? If yes then you need to create another input device with Python and pass read data from touchscreen to this new input Kodi will be using.

    I'm just wondering: why do you even need this external python script? Can't you handle touchscreen in Kodi itself?

  • vpeter:
    Once again, some great suggestions.

    Thanks for the pointer to system tools.

    evtest does see the touchscreen and correctly identifies the touchscreen and properties.
    But, it also notes that "The device is grabbed by another process". Which confirms your earlier assumption that Kodi grabs control of all IO. I guess that makes sense from a performance point of view.

    Your code is a little difficult for me to digest all at once. I do see in the .sh script that you kill Kodi to launch the calibrate.py, and then restart Kodi.
    This seems to confirm that Kodi runs with exclusive access to device input.

    I'll have to research your suggestion to "create another input device in Python". I'm not sure how to do that, but I can look into it.

    Your suggestion to run a background program with autostart interesting. I assume I could try to exclusively grab the input before Kodi starts (I don't need Kodi to have access to the touchpanel inputs).
    I assume that the program would read the touchscreen events and send the data to my python addon (through a fifo pipe or file I/O?).
    Is that what you had in mind?

    Da Flex: interesting suggestion, but no, changing the "Enable mouse and touch screen support" setting has no effect.

  • JeffR, can you explain why you need python script to read data? What exactly are you trying to do?

    I do have some experience with touchscreen and kodi. When I was doing my touch daemon/addon I learned a thing or two.