Qt multitouch
=============

To use multitouch in Qt applications you can use qTUIO plugin. This is one of possibile solutions. This plugin requires others packages to work. Sintetically, the firmware sends usb frames with events multitouchscreen, the driver reads and sends these event to device file (/dev/input/eventX). Tslib reads these events and sends they to mtdev2tuio. This application (that uses liblo and mtdev libraries) sends the multitouch event by ethernet (localhost:3333). qTUIO reads from the ethernet the coordinates. There are some compilable examples in qTUIO folder to see how Qt works with this plugin.

firmware ----> driver ----> tslib ----> mtdev2tuio ----> qtuio & Qt

In these instruction is explained how crosscompile, configure and install all these packages. I have used a virtual machine and I have created a folder named "exported" where I put all the file installation to copy in the rootfs of linux embedded.

change the path "/home/pengwyn" with yours and the path CC and CXX with your tollchain path.


+++++++++++++++
UPLOAD FIRMWARE
+++++++++++++++
With this procedure the RSR941 is seen from the PC how a mass memory storage. You can copy the firmware in that memory. Only one file named firmware.bin.
1. Power off the board
2. Connect miniusb CN2 to PC
3. In CN3 shortcicruite pin 3 with pin 5 and power on the board (CN1 pin1,2 +24V; pin 3,4 GND)
4. Substitute the old firmware (if exist) with the new.

++++++++++++
BUILD DRIVER
++++++++++++
extract driver_release.zip

Here you have a makefile to compile the driver how a module to load with modprobe. It require linux-header sources. I use this in ubuntu for test the driver quickly and I use evtest application to see the events sended by the multitouch driver. Install.sh is a script to install the driver easly in ubuntu.
There is a folder evtest, here there is the source of evtest compilable for raspberry (change CXX and CC path).

Normally in order to use the RSR941 you need compile the kernel with usbtouchscreen module. This option is in menuconfig “device drivers → Input device support → Touchscreen → USB Touchscreen driver”.
Substitute drivers/input/touchscreen/usbtouchscreen.c with the new modified (driver_release/usbtouchscreen.c).
Now build the Kernel with the driver.

++++++++++++++++++
COMPILING PACKAGES
++++++++++++++++++

TSLIB
=====
require: sudo apt-get install libtool

extract tslib.tgz

sudo ./autogen-clean.sh
sudo ./autogen.sh
export ac_cv_func_malloc_0_nonnull=yes
export PATH=`pwd`:$PATH
./configure CC=/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc CXX=/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ --host=arm-linux --prefix=/usr/local/tslib --enable-shared=yes --enable-static=yes
sudo make
sudo make install
mkdir /home/pengwyn/Desktop/exported
mkdir /home/pengwyn/Desktop/exported/usr
mkdir /home/pengwyn/Desktop/exported/usr/bin
mkdir /home/pengwyn/Desktop/exported/etc
mkdir /home/pengwyn/Desktop/exported/lib
mkdir /home/pengwyn/Desktop/exported/lib/pkgconfig
mkdir /home/pengwyn/Desktop/exported/lib/ts
sudo cp /usr/local/tslib/bin/* /home/pengwyn/Desktop/exported/usr/bin/
sudo cp /usr/local/tslib/etc/ts.conf /home/pengwyn/Desktop/exported/etc/
sudo cp -r /usr/local/tslib/lib/ts /home/pengwyn/Desktop/exported/usr/lib
sudo cp -r /usr/local/tslib/lib/* /home/pengwyn/Desktop/exported/lib/
sudo vim /home/pengwyn/Desktop/exported/etc/ts.conf (uncomment input-raw)

liblo-0.26
==========
extract liblo-0.26.tar.gz

export SKIP_RMDIR_CHECK=yes
./configure CC=/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc CXX=/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ --prefix=/usr/local/lib/liblo --host=arm
make clean
make
sudo make install
cd /usr/local/lib/liblo
sudo cp bin/* /home/pengwyn/Desktop/exported/usr/bin/
sudo cp lib/liblo.a /home/pengwyn/Desktop/exported/usr/bin/
sudo cp lib/liblo.la /home/pengwyn/Desktop/exported/usr/bin/

mtdev 1.1.2
===========
extract mtdev-1.1.2.tar.gz

./configure CC=/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc CXX=/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ --prefix=/usr/local/lib/mtdev --host=arm
make clean
make
sudo make install
cd /usr/local/lib/mtdev
sudo cp bin/* /home/pengwyn/Desktop/exported/usr/bin/
sudo cp lib/libmtdev.a /home/pengwyn/Desktop/exported/usr/bin/
sudo cp lib/libmtdev.la /home/pengwyn/Desktop/exported/usr/bin/

mtdev2tuio
==========
extract mtdev2tuio.tgz

change Makefile with the correct path CC and CXX.
make

or
/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -o test -L/usr/local/lib/mtdev/lib/ -L/usr/local/lib/liblo/lib/ -I/usr/local/lib/liblo/include/ -I/usr/local/lib/mtdev/include/ mtdev2tuio.c
or
/opt/poky/1.2.1/sysroots/i686-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -o test mtdev2tuio.c /usr/local/lib/mtdev/lib/libmtdev.a /usr/local/lib/liblo/lib/liblo.a -I/usr/local/lib/liblo/include/ -I/usr/local/lib/mtdev/include/

cp mtdev2tuio /home/pengwyn/Desktop/exported/usr/bin/

qTUIO
=====

extract qTUIO.tgz

compile the project "src/qTUIO.pro" with QtCreator
go to qTUIO/lib
sudo mkdir -p /usr/local/lib/qTUIO
sudo cp -r ../lib/* /usr/local/lib/qTUIO
sudo cp -r /usr/local/lib/qTUIO/* /home/pengwyn/Desktop/exported/usr/lib/


qTUIO demo
==========
In qTUIO/examples you can compile the demo to test the multitouch. I have tested it with pinchzoom example. It is compilable with qtcreator.

+++++++++++++++++++
CONFIGURATION FILES
+++++++++++++++++++

touchscreen.rules
=================
mkdir -p /home/pengwyn/Desktop/exported/etc/udev/rules.d
put here the touchscreen.rules file.


source ./startup.sh
===================
these are enviroment variables that must be see from all application on raspberry.

export TSLIB_TSEVENTTYPE=INPUT
export TSLIB_TSDEVICE=/dev/input/touchscreen0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/lib/ts
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CONSOLEDEVICE=none
export QWS_MOUSE_PROTO=tslib:/dev/input/touchscreen0
export PATH=$PATH:/usr/bin

also you need launch this demon:
mtdev2tuio /dev/input/touchscreen0 osc.udp://127.0.0.1:3333/ &

++++++++++++
INSTALLATION
++++++++++++
- Copy your kernel image with usbtouchscreen module in sdcard
- Copy the files of exported folder in your rootfs
- Create a script to export the environment variables and launches mtdev2tuio
- Copy a qTUIO example

When you plug the usb touschscreen cable to raspberry the udev demon create the file device /dev/input/touchscreen0. 
The enviroment variables must be exported. The first time calibrate the touchscreen with ts_calibrate application. As you finished to calibrate the ts_calibrate will create /etc/pointercal file.
Before to launch a qt-qtuio demo, you must launch "mtdev2tuio /dev/input/touchscreen0 osc.udp://127.0.0.1:3333/ &".


++++
NOTE
++++
- This system is compatible with the programs that use only single touch. Works normally because they use only the tslib application ignoring mtdev2tuio.
- If after the calibration (ts_calibrate) you don't see the pointercal file then most probably the enviroment variable are not setted correctly (or not visible to ts_calibrate).

