Script to install usb touchscreen

Hello.
I want to install a usb 1024X600 touch panel with a script on OSMC. This script was for XBIAN but it can run on OSMC with somemodification (xbian-touch/install.sh at master · brantje/xbian-touch · GitHub).

#!/bin/bash
echo "XBian touch installer by brantje"
if [ ! -f /etc/pointercal ]; then
	echo  "Listing event devices"
	ls -l /dev/input/by-id | grep event
	echo "What is the event number of the touchscreen? eg: event0 then you type 0, followed by [ENTER]"
	read inputnumber
	sudo systemctl stop mediacenter
	echo "Getting tslib"
	wget --no-check -O tslib_1-1_armhf.deb "https://github.com/brantje/xbian-touch/raw/master/tslib_1-1_armhf.deb"
	echo "Installing tslib"
	dpkg -i tslib_1-1_armhf.deb
	export LD_LIBRARY_PATH=/usr/local/lib
	export TSLIB_CONSOLEDEVICE=none
	export TSLIB_FBDEVICE=/dev/fb0
	export TSLIB_TSDEVICE=/dev/input/event$inputnumber
	export TSLIB_CALIBFILE=/etc/pointercal
	export TSLIB_CONFFILE=/usr/local/etc/ts.conf
	export TSLIB_PLUGINDIR=/usr/local/lib/ts
	echo "Please follow the instructions on the display..."
	ts_calibrate
	echo "Getting uimapper..."
	wget --no-check -O uimapper.tar.gz "https://github.com/brantje/xbian-touch/raw/master/uimapper.tar.gz"
	echo "Installing uimapper..."
	sudo mkdir -p /scripts && sudo tar -zxf uimapper.tar.gz  -C /scripts

	echo "Generating config file"
	echo "#!upstart
	description \"uimapper\"


	env UIMAPPER_DEV=\"/dev/input/event$inputnumber\"
	env UIMAPPER_CONF=\"configs/touchscreen.py\"
	env UIMAPPER_DIR=\"/scripts/uinput-mapper\"

	start on (input-device-added SUBSYSTEM=input)

	stop on input-device-removed

	nice -10

	kill timeout 1

	expect fork

	script
		chdir \$UIMAPPER_DIR
		exec ./input-read.py \$UIMAPPER_DEV -D | ./input-create.py \$UIMAPPER_CONF &
	end script
	respawn" >> uimapper.conf
	echo "Moving config..."
	sudo mv uimapper.conf /etc/init
	sudo chmod +x /scripts/uinput-mapper/input-create.py
	sudo chmod +x /scripts/uinput-mapper/input-read.py

	echo "Cleaning up..."
	rm uimapper.tar.gz
	rm tslib_1-1_armhf.deb > /dev/null #Silent error
	sudo start uimapper
	sudo systemctl start mediacenter
	echo "Installation done!"
else
	echo "Already installed... Recalibrating"
	echo  "Listing event devices"
	ls -l /dev/input/by-id | grep event
	echo "What is the event number of the touchscreen? eg: event0 then you type 0, followed by [ENTER]"
	read inputnumber
	sudo systemctl stop mediacenter
	sudo stop uimapper
	export LD_LIBRARY_PATH=/usr/local/lib
	export TSLIB_CONSOLEDEVICE=none
	export TSLIB_FBDEVICE=/dev/fb0
	export TSLIB_TSDEVICE=/dev/input/event$inputnumber
	export TSLIB_CALIBFILE=/etc/pointercal
	export TSLIB_CONFFILE=/usr/local/etc/ts.conf
	export TSLIB_PLUGINDIR=/usr/local/lib/ts
	sleep 3
	echo "Please follow the instructions on the display..."
	ts_calibrate
	sudo start uimapper
	sudo systemctl start mediacenter
fi

After some modifications on the script i am stuck on line number 36 (start on (input-device-added SUBSYSTEM=input)). Before this moment i can calibrate my touchscreen but after the script stop on the line 36. It seem that OSMC don’t recognize this command. So, is there someone who can help me to progress with this script ?
Thank you.

Hi,

It would make things easier if you told us the make and model of the touch panel, its very unlikely this script will run on the current xbian (the script is 9 years old) or osmc.

Also I’ve edited your post to make the script easier to read.

Regards Tom.

So, this is a 1024*600 usb touch panel with a egalax driver that i want to install on OSMC_TGT_rbp2_20221101

This is a raw translation of your old script, with newer deb packages, most of the vital code has gone through conversion from Python2 to Python3,

Okey let’s try this then:

sudo apt-get update
sudo apt-get install libts-bin libts-dev libts0
sudo mv /etc/ts.conf /etc/ts.conf.org
sudo nano /etc/ts.conf

PASTE THIS TEXT:

module_raw input
module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear

CTRL+X, Y , [ENTER]

cd ~
mkdir tempo_20230112_0040
cd tempo_20230112_0040
nano osmc_touch_installer.sh

PASTE THIS TEXT:

#!/bin/bash
echo "OSMC touch installer v. 0.01"
if [ ! -f /etc/pointercal ]; then
	sudo touch /etc/pointercal
        sudo chmod 766 /etc/pointercal
	echo  "Listing event devices"
	ls -l /dev/input/by-id | grep event
	echo "What is the event number of the touchscreen? eg: event0 then you type 0, followed by [ENTER]"
	read inputnumber
	sudo systemctl stop mediacenter
        export TSLIB_CONSOLEDEVICE=none
        export TSLIB_FBDEVICE=/dev/fb0
        export TSLIB_TSDEVICE=/dev/input/event$inputnumber
        export TSLIB_CALIBFILE=/etc/pointercal
        export TSLIB_CONFFILE=/etc/ts.conf
        export TSLIB_PLUGINDIR=/usr/lib/arm-linux-gnueabihf/ts0
        echo "Please follow the instructions on the display..."
        ts_calibrate
        echo "Getting uimapper..."
        wget https://github.com/whitelynx/uinput-mapper/archive/refs/heads/master.zip
        unzip master.zip 
        mv uinput-mapper-master/ uinput-mapper/
        cd uinput-mapper/
        gcc -E -dM /usr/include/linux/input.h | egrep ' (EV|SYN|KEY|BTN|REL|ABS|MSC|LED|SND|REP|SW)_[A-Za-z0-9_]+' | ( echo "#include <linux/input.h>" ; echo "input_constants_dict = {" ; sed -r 's/[^ ]+ +([^ ]+).*/"1" : 1,/' ; echo "}" ) | gcc -E -o /dev/stdout - | grep 'input_constants_dict = {' -A 100000 > uinputmapper/uinput_gen.py
        rm COPYING Makefile README.rst doc/ gentoo/ -R
        sudo mkdir -p /scripts/uinput-mapper && mv * /scripts/uinput-mapper -R
        echo "Generating config file"
	echo "#!upstart
	description \"uimapper\"
	env UIMAPPER_DEV=\"/dev/input/event$inputnumber\"
	env UIMAPPER_CONF=\"configs/touchscreen.py\"
	env UIMAPPER_DIR=\"/scripts/uinput-mapper\"
	start on (input-device-added SUBSYSTEM=input)
	stop on input-device-removed
	nice -10
	kill timeout 1
	expect fork
	script
		chdir \$UIMAPPER_DIR
		exec ./input-read.py \$UIMAPPER_DEV -D | ./input-create.py \$UIMAPPER_CONF &
	end script
	respawn" >> uimapper.conf
	echo "Moving config..."
	sudo mv uimapper.conf /etc/init
	sudo chmod +x /scripts/uinput-mapper/input-create.py
	sudo chmod +x /scripts/uinput-mapper/input-read.py
	echo "Cleaning up..."
	sudo start uimapper
	sudo systemctl start mediacenter
	echo "Installation done!"
else
	echo "Already installed... Recalibrating"
	echo  "Listing event devices"
	ls -l /dev/input/by-id | grep event
	echo "What is the event number of the touchscreen? eg: event0 then you type 0, followed by [ENTER]"
	read inputnumber
	sudo systemctl stop mediacenter
	sudo stop uimapper
	export TSLIB_CONSOLEDEVICE=none
	export TSLIB_FBDEVICE=/dev/fb0
	export TSLIB_TSDEVICE=/dev/input/event$inputnumber
	export TSLIB_CALIBFILE=/etc/pointercal
	export TSLIB_CONFFILE=/etc/ts.conf
	export TSLIB_PLUGINDIR=/usr/lib/arm-linux-gnueabihf/ts0
	sleep 3
	echo "Please follow the instructions on the display..."
	ts_calibrate
	sudo start uimapper
	sudo systemctl start mediacenter
fi

CTRL+X, Y , [ENTER]

chmod +x osmc_touch_installer.sh
./osmc_touch_installer.sh

Since I dont have any touch screen I can’t test it, there could be some spelling mistakes in the installer script, but i tried to keep it as close to the old source as posible.

Try and reboot, good luck =) If it works, you should be able to delete tempo_20230112_0040 folder, with all it’s contents.

Edit: For those that know better then me about these things, is python-uinput better/replacement for uinput-mapper, which was first built with C but has step over to the darkside (python)?

1 Like

Thanks. I will try tonight after work.

Did you have time to try it?? Love to hear any feedback

Hello.
Sorry for the late answer.

After test f your script it give:
osmc@osmc:~/tempo_20230112_0040$ sh osmc_touch_installer.sh
OSMC touch installer v. 0.01
Already installed… Recalibrating
Listing event devices
lrwxrwxrwx 1 root root 9 19 janv. 08:10 usb-2188_USB_OPTICAL_MOUSE-event-mouse → …/event0
lrwxrwxrwx 1 root root 9 19 janv. 08:10 usb-eGalax_Inc._USB_TouchController-event-if00 → …/event2
lrwxrwxrwx 1 root root 9 19 janv. 08:10 usb-eGalax_Inc._USB_TouchController-event-mouse → …/event1
What is the event number of the touchscreen? eg: event0 then you type 0, followed by [ENTER]
2
sudo: stop : commande introuvable
Please follow the instructions on the display…
xres = 1280, yres = 800
Took 1 samples…
Top left : X = 567 Y = 3827
Took 1 samples…
Top right : X = 467 Y = 315
Took 2 samples…
Bot right : X = 3614 Y = 311
Took 6 samples…
Bot left : X = 3620 Y = 3836
Took 2 samples…
Center : X = 2118 Y = 2080
1334.931763 0.000271 -0.335372
-61.790649 0.225708 -0.003400
Calibration constants: 87486088 17 -21978 -4049512 14792 -222 65536
open: Permission denied
sudo: start : commande introuvable
osmc@osmc:~/tempo_20230112_0040$

I think there is some fail but i dont now where.

thank you, well it’s a start anyway.

Now when you ran it again, I doubt you had a clean system? My thought is that if you just run my script, while you had old leftovers from the former script it might have interfered.

As I said before I have no touchscreen, and haven’t worked with them for a long time, but as I understood it, isn’t the touch mouse the event you want?`

The open and stop error, seems to be related to the script, which I haven’t really check out properly. I just got ahold of a “python3 ported version”. I can try to invest more time into this, but either there is a problem in finding the script that is asked, via sudo to open or stop. So a “where is the file problem”?

Still just “remote diagnosis”, I have no way to check it. Good Luck

Ps. Just did a little tweak, changed file permissions on the calibration file. Next step would be to rewrite the init.conf files to a service file instead. But I will have to get back to you there.

clearly an init issue, the start and stop command is for init.d? And If I remember correctly Debian was heading away form that and into services/systemd. So if this is time sensitive I would look for someone to rewrite the part of the scripts that echoes a few lines into uimapper.conf

That is, edit the line that echoes into a .conf file and instead echo into a uimapper.service file (with a correct syntax, differs from init.conf files), I would if I could test it between edits, but doing it blindly takes to much time away from other joys of life, like the monsters I’ve spawned.

Thank you for all the time you have given to my problem joakim_s.

Next step would be to read-up on how-to convert a “upstart”-script to systemd-service. Upstart seem to be some old Ubuntu-thing. removed around v.16.*. Have found some links describeing, but I don’t belive I have the time to learn upstart enough to translate it into .service file. There is forking mentioned and I have no idea if that is simple or forked in service-file. And I cant find a simple translation matrix.

Upstart was Canonicals’ Not Invented Here (NIH) approach to an init system and a stab at sysvinit before systemd became the defacto init system.

We used it in Raspbmc and it was pretty good.

It shouldn’t be hard to convert it in to a systemd unit.

Figured as much, but it’s the fork-bit in the script vs. simple or forked in .service. Didn’t find a simple, “this is how”. But If i get some extra time i might be able to check it out.

“Cut & pasted” upstart script:

#!upstart
description \"uimapper\"
env UIMAPPER_DEV=\"/dev/input/event$inputnumber\"
env UIMAPPER_CONF=\"configs/touchscreen.py\"
env UIMAPPER_DIR=\"/scripts/uinput-mapper\"
start on (input-device-added SUBSYSTEM=input)
stop on input-device-removed
nice -10
kill timeout 1
expect fork
script
   chdir \$UIMAPPER_DIR
   exec ./input-read.py \$UIMAPPER_DEV -D | ./input-create.py \$UIMAPPER_CONF &
end script
respawn

If someone knowledgeable feels up to it, it’s the expect fork I’m uncertain about.