2020-07-08, 03:37 PM
(This post was last modified: 2021-05-04, 10:00 PM by abarrow.
Edit Reason: Changed some edits to "sudo"
)
All,
I recently got a new touchscreen, and was upset that I couldn't get multi-touch to work on it. After some research, I discovered a program called "twofing" which gives two-finger right-click and two-finger zoom. I've created a how-to for you guys.
Credit to JimmyN on raspberrypi.org. I made this a bit more generic, from his original post: https://www.raspberrypi.org/forums/viewt...p?t=138575
This modification will give two-finger right-click and two finger zoom. It does work on OpenCPN and on the web browser. I used the latest update of OpenPlotter with the most recent updates of Stretch.
First we'll need to fetch the files, I created a temp directory to work in, and afterward it can be deleted. So open a terminal and get started.
That should report that "twofing-0.1.2.tar.gz" was saved.
Now we'll add some needed packages, if any of these are already installed it's OK. We'll update first, and then install them with the following commands.
Now that those are in place we can extract the downloaded twofing-0.1.2.tar.bz file and compile the binary using "make".
It that is successful,
This will do a few things. It will put a new executable called "twofing" into "/usr/bin/". It will also place a new file in "/etc/udev/rules.d" called "70-touchscreen-egalax.rules". We'll do some editing on that one in a moment.
Now, we need to discover the name of the multi-touch display you are using, and the USB ID. From your display (not from a remote terminal) run:
Mine looked like this:
The name of my touch pointer is "G2Touch Multi-Touch by G2TSP". Yours may vary. Save this name, whatever it is.
Next, you need the USB ID of your pointer. Run:
Mine looked like this:
It took a little trial and error, but I discovered that the one unnamed USB device is actually my touch device. Yours might have a name. What you want is the USB ID for it, which in my case is "2a94:564d". You'll also need this info.
Next we are going to edit the file that was installed when you did "make install" above. The name of the file isn't important, the number at the beginning is. I just left mine with "egalax" in the name, even though I don't have an egalax touch controller.
Edit the file with:
It's going to look like this when you open it:
The first line and the last line need to be edited with the information you collected previously with xinput and lsusb. On the first line, replace the "idVendor" identifier with the first part of the USB ID you collected with lsusb (the part before the ":") and the "idProduct" identifier with the second part (the part after the ":").
On the last line, replace the "ATTRS{name}" part with the touch controller name you got when you did xinput.
The second line in this file is for another touch controller. I'm not sure why it's there, but it doesn't hurt anything. I suppose if someone were ambitious they could create a "one file to rule them all" file that would identify all touch controllers.
EDIT: it turns out, all you need is the USBID. I commented out the last two lines and mine still works fine.
You are done with this file. Save with CTRL-X, Y.
Now reboot and then we can give it a test.
Test it using the debug switch. If you have no errors you'll get a calibration screen, press <CTRL> C to exit.
If that went OK then start twofing again, without the debug switch, and touching two fingers on the window titlebar should give you a "right click" dropdown menu.
Now you'll probably want to start it up when the desktop starts, so let's add it to the autostart file. In the original instructions they identified a file in ~/.config/lxsession/LXDE-pi/ called "autostart". It wasn't there in my implementation. I editied the autostart file in "/etc/xdg/lxsession/LXDE-pi"
Scroll down to the bottom and add this line.
EDIT: You may find that twofing doesn't start reliably on startup. In my case, I discovered a few second delay was needed before twofing was run. I did this with a bash script, that called twofing after delay. The script looks like this:
which I saved to /usr/local/bin/two-finger.sh. You'll need to make it executable with "sudo chmod +x /usr/local/bin/two-finger.sh.
If yo do this, the entry in /etc/xdg/lxsession/LXDE-pi/autostart needs to be:
Save the change, reboot again, and it should be working. If so you can delete the /temp directory and everything in it.
That should do it. As I said, I now have two-finger zoom with OpenCPN, and two-finger right-click.
I recently got a new touchscreen, and was upset that I couldn't get multi-touch to work on it. After some research, I discovered a program called "twofing" which gives two-finger right-click and two-finger zoom. I've created a how-to for you guys.
Credit to JimmyN on raspberrypi.org. I made this a bit more generic, from his original post: https://www.raspberrypi.org/forums/viewt...p?t=138575
This modification will give two-finger right-click and two finger zoom. It does work on OpenCPN and on the web browser. I used the latest update of OpenPlotter with the most recent updates of Stretch.
First we'll need to fetch the files, I created a temp directory to work in, and afterward it can be deleted. So open a terminal and get started.
Code:
mkdir ~/temp
cd ~/temp
wget http://plippo.de/dwl/twofing/twofing-0.1.2.tar.gz
That should report that "twofing-0.1.2.tar.gz" was saved.
Now we'll add some needed packages, if any of these are already installed it's OK. We'll update first, and then install them with the following commands.
Code:
sudo apt-get update
sudo apt-get install build-essential libx11-dev libxtst-dev libxi-dev x11proto-randr-dev libxrandr-dev
Now that those are in place we can extract the downloaded twofing-0.1.2.tar.bz file and compile the binary using "make".
Code:
tar -xvzf twofing-0.1.2.tar.gz
cd twofing-0.1.2
make
It that is successful,
Code:
sudo make install
This will do a few things. It will put a new executable called "twofing" into "/usr/bin/". It will also place a new file in "/etc/udev/rules.d" called "70-touchscreen-egalax.rules". We'll do some editing on that one in a moment.
Now, we need to discover the name of the multi-touch display you are using, and the USB ID. From your display (not from a remote terminal) run:
Code:
xinput
Mine looked like this:
Code:
pi@openplotter:~ $ xinput
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech K400 id=9 [slave pointer (2)]
⎜ ↳ G2Touch Multi-Touch by G2TSP id=8 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ C-Media Electronics Inc. USB Audio Device id=6 [slave keyboard (3)]
↳ Logitech K400
The name of my touch pointer is "G2Touch Multi-Touch by G2TSP". Yours may vary. Save this name, whatever it is.
Next, you need the USB ID of your pointer. Run:
Code:
lsusb
Mine looked like this:
Code:
Bus 002 Device 002: ID 174c:0857 ASMedia Technology Inc.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 011: ID 2a94:564d
Bus 001 Device 010: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Bus 001 Device 009: ID 1546:01a7 U-Blox AG [u-blox 7]
Bus 001 Device 008: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 007: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 001 Device 006: ID 0d8c:0014 C-Media Electronics, Inc. Audio Adapter (Unitek Y-247A)
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
It took a little trial and error, but I discovered that the one unnamed USB device is actually my touch device. Yours might have a name. What you want is the USB ID for it, which in my case is "2a94:564d". You'll also need this info.
Next we are going to edit the file that was installed when you did "make install" above. The name of the file isn't important, the number at the beginning is. I just left mine with "egalax" in the name, even though I don't have an egalax touch controller.
Edit the file with:
Code:
sudo nano /etc/udev/rules.d/70-touchscreen-egalax.rules
It's going to look like this when you open it:
Code:
SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="event*",ATTRS{idVendor}=="0eef",ATTRS{idProduct}=="480d",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="event*",ATTRS{idVendor}=="0486",ATTRS{idProduct}=="0186",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
KERNEL=="event*",ATTRS{name}=="eGalaxTouch Virtual Device for Multi",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
The first line and the last line need to be edited with the information you collected previously with xinput and lsusb. On the first line, replace the "idVendor" identifier with the first part of the USB ID you collected with lsusb (the part before the ":") and the "idProduct" identifier with the second part (the part after the ":").
On the last line, replace the "ATTRS{name}" part with the touch controller name you got when you did xinput.
The second line in this file is for another touch controller. I'm not sure why it's there, but it doesn't hurt anything. I suppose if someone were ambitious they could create a "one file to rule them all" file that would identify all touch controllers.
EDIT: it turns out, all you need is the USBID. I commented out the last two lines and mine still works fine.
You are done with this file. Save with CTRL-X, Y.
Now reboot and then we can give it a test.
Test it using the debug switch. If you have no errors you'll get a calibration screen, press <CTRL> C to exit.
Code:
twofing --debug
If that went OK then start twofing again, without the debug switch, and touching two fingers on the window titlebar should give you a "right click" dropdown menu.
Code:
twofing
Now you'll probably want to start it up when the desktop starts, so let's add it to the autostart file. In the original instructions they identified a file in ~/.config/lxsession/LXDE-pi/ called "autostart". It wasn't there in my implementation. I editied the autostart file in "/etc/xdg/lxsession/LXDE-pi"
Code:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Scroll down to the bottom and add this line.
Code:
@/usr/bin/twofing
EDIT: You may find that twofing doesn't start reliably on startup. In my case, I discovered a few second delay was needed before twofing was run. I did this with a bash script, that called twofing after delay. The script looks like this:
Code:
#!/bin/bash
sleep 10
/usr/bin/twofing
If yo do this, the entry in /etc/xdg/lxsession/LXDE-pi/autostart needs to be:
Code:
@/usr/local/bin/two-finger.sh
Save the change, reboot again, and it should be working. If so you can delete the /temp directory and everything in it.
Code:
rm -r ~/temp
That should do it. As I said, I now have two-finger zoom with OpenCPN, and two-finger right-click.