2

We have devices with touchscreens that we calibrate using xinput_calibrator, then apply the settings in a launch script for our application, along the lines of

xinput set-int-prop "Microchip Technology Inc. AR1100 HID-MOUSE" "Evdev Axis Calibration" 32 109 3841 161 3973
xinput set-int-prop "Microchip Technology Inc. AR1100 HID-MOUSE" "Evdev Axes Swap" 8 1
xinput set-int-prop "Microchip Technology Inc. AR1100 HID-MOUSE" "Evdev Axis Calibration" 32 3852 112 3970 159

This works well - sometimes. At other times, following a power cycle, the calibration will not take effect - the axes are swapped, in particular, and scaling seems off, though that's harder to say. A couple more power cycles and it will work again, then not.

We're new to X11 and aren't sure why this is happening. It's as though our xinput statements are being processed sometimes and ignored other times, though nothing has changed other than rebooting.

Any thoughts on how to address this are appreciated.

SixDegrees
  • 781
  • 1
  • 8
  • 19
  • How is your script started exactly (at startup or manually, before or after X11 server starts)? On reboots where calibration/swap haven't been applied, does it help to run the script again? Is a full restart really required, or maybe re-running the script and restarting X11 server is sufficient? – Dmitry Grigoryev Mar 25 '15 at 10:12
  • Script is launched during init, explicitly after the x server has been started. I have not tried running the script a second time; this is on an embedded system, and it's difficult to halt our application in order to relaunch it, as everything is set up to launch automatically, once, on boot. – SixDegrees Mar 25 '15 at 10:24
  • Well, you could add a `sleep 60` in your script to make sure everything settles down before you run it. You could also run the "Axes Swap" line twice (with a small interval) to account for the cases where the command isn't taken into account the first time. Finally, you may log the output of `xinput --list --long` and the end of your script and compare the logs corresponding to successful and failed configurations. – Dmitry Grigoryev Mar 25 '15 at 10:40
  • Adding a delay does seem to fix the problem. But 1) we don't understand why - what is "settling" during that period? and 2) we are under tight time constraints to bring the first screen up as quickly as possible, and any delays at all are going to be frowned upon. Is there a way to check and guarantee that X is "settled"? – SixDegrees Mar 26 '15 at 08:56

1 Answers1

2

Since there seems to be a race condition between X11 server startup process and xinput call, you will have to wait for the startup process to complete. I suggest you check this answer for hints on how to detect that X server is running normally.

If that doesn't work, you should try to check the return code of xinput and wait for a success before configuring the touchscreen. For example:

ts_dev="Microchip Technology Inc. AR1100 HID-MOUSE"
ts_calibrate="Evdev Axis Calibration"
ts_swap="Evdev Axes Swap"

# repeat until xinput returns success for the first time
while ! xinput set-int-prop "$ts_dev" "$ts_calibrate" 32 109 3841 161 3973
do
    sleep 1
done
xinput set-int-prop "$ts_dev" "$ts_swap" 8 1
xinput set-int-prop "$ts_dev" "$ts_calibrate" 32 3852 112 3970 159

You may need to adapt the script for the values that xinput returns on your system.

Community
  • 1
  • 1
Dmitry Grigoryev
  • 3,156
  • 1
  • 25
  • 53
  • Tried this, and it seems to be working just fine. I added a loop counter, and found that it was taking between 0 to 2 seconds before the commands would succeed - which still seems strange, but I haven't seen any failures at all using this approach. Thanks. – SixDegrees Mar 26 '15 at 13:02