转自:
http://www.ptrackapp.com/apclassys-notes/embedded-linux-multitouch/
This tutorial describes how to set up multi-touch and single-touch touchscreen input
for Qt for embedded Linux. I assume that you received a driver from your touchscreenmanufacturer or there is an existing one you can use in the Kernel source.First things first, locate your driver ( usually /drivers/input/touchscreen/* ), and ensure that you have every event type being defined that is required by tslib. So, specifically you need EV_SYN, EV_ABS, and EV_KEY. My driver did not define EV_KEY, and even though it does not report that event type, I still had to define it in the driver source for tslib to work with the input from the driver.set_bit(EV_SYN, aura.input_dev->evbit);set_bit(EV_ABS, aura.input_dev->evbit);set_bit(EV_KEY, aura.input_dev->evbit); # I had to add this line so that tslib was happyNow build the Kernel with your driver ( either as module or driver ) and fire up yourboard.My input device is called 'touchscreen'. Yours will probably be event1 or event0 dependingon serveral possible reasons.See what the device is with:# ls -rlt /dev/input/touchscreen lrwxrwxrwx 1 root root 6 Jan 17 21:06 /dev/input/touchscreen -> event1# chmod 777 /dev/input/touchscreen # chmod 777 /dev/input/event1 You can see more information with:# cat /sys/devices/virtual/input/input1/uevent PRODUCT=0/0/0/0NAME="aura-touchscreen"PROP=0EV=9ABS=650000 0MODALIAS=input:b0000v0000p0000e0000-e0,3,kra30,32,35,36,mlsfwTo ensure that your driver is working do the following command and then move your finger around the screen. You should see output herewhen you finger is touching the screen.# cat /dev/input/touchscreen | hexdump0000000 9011 3883 565f 0001 0003 0030 0001 00000000010 9011 3883 565f 0001 0003 0032 0001 00000000020 9011 3883 565f 0001 0003 0035 04c9 00000000030 9011 3883 565f 0001 0003 0036 0c3f 00000000040 9011 3883 565f 0001 0000 0002 0000 00000000050 9011 3883 565f 0001 0000 0000 0000 00000000060 9011 3883 90a9 0001 0003 0030 0001 00000000070 9011 3883 90a9 0001 0003 0032 0001 0000Go back to your host machine and download the tslib src from here --> .Enter the tslib source directory ( cd tslib/plugins ) and edit the input-raw.c file.Replace any occurences of ABS_X / Y with ABS_MT_POSITION_X / Y. These are the namesof the multi-touch event type variables produces by a multitouch driver.Now that everything is in order, build tslib and deploy using the following commandsto your exported nfs ( root file system ) for the board:sudo ./autogen-clean.shsudo ./autogen.shsudo export ac_cv_func_malloc_0_nonnull=yessudo export PATH=`pwd`:$PATHsudo ./configure CC=/home/user/toolchain/linaro/bin/arm-linux-gnueabi-gccCXX=/home/user/toolchain/linaro/bin/arm-linux-gnueabi-g++--host=arm-linux--prefix=/usr/local/tslib--enable-shared=yes--enable-static=yessudo makesudo make installsudo cp /usr/local/tslib/bin/* /home/user/exported-nfs/usr/bin/sudo cp /usr/local/tslib/etc/ts.conf /home/user/exported-nfs/etc/sudo cp -r /usr/local/tslib/lib/ts /home/user/exported-nfs/usr/libsudo cp /usr/local/tslib/lib/* /home/user/exported-nfs/lib/sudo vim /home/user/exported-nfs/etc/ts.confWhen ts.conf opens for editing, uncomment the 'input raw' line ( the very first commented out module ).Now log back into your embedded machine and export the following environmentvariables:export TSLIB_TSEVENTTYPE=INPUTexport TSLIB_TSDEVICE=/dev/input/touchscreenexport TSLIB_CALIBFILE=/etc/pointercalexport TSLIB_CONFFILE=/etc/ts.confexport TSLIB_PLUGINDIR=/usr/lib/tsexport TSLIB_FBDEVICE=/dev/fb0export TSLIB_CONSOLEDEVICE=noneexport TSTS_INFO_FILE=/sys/devices/virtual/input/input1/ueventexport QWS_MOUSE_PROTO=tslib:/dev/input/touchscreenexport PATH=$PATH:/usr/binNow we are ready to calibrate. Go to /usr/bin and launch the calibrationutility. You should now see a calibration image on the screen requestingyou to touch a few crosshairs. Go ahead and do that until it stops. Thenyour screen is calibrated! The calibration parameters are stored in the/etc/pointercal file. (you may have to first increase the brightnessof your screen with --> echo 127 > /sys/class/backlight/generic-bl/brightness) # ts_calibrate xres = 640, yres = 480Took 5 samples...Top left : X = 3817 Y = 3912Took 6 samples...Top right : X = 269 Y = 3822Took 5 samples...Bot right : X = 356 Y = 550Took 5 samples...Bot left : X = 3732 Y = 614Took 6 samples...Center : X = 2202 Y = 2216643.068298 -0.155621 -0.000056491.792572 0.002567 -0.115674Calibration constants: 42144124 -10198 -3 32230118 168 -7580 65536 You can also test the touchscreen mouse input by running:ts_testGreat! Now you have single mouse input with tslib ready to go!Now let's move on to multi-touch.Download the following packages to enable multitouch events with Qt. Export your cross-compiler and toolchain:export CC=/home/user/toolchain/linaro/bin/arm-linux-gnueabi-gccexport CXX=/home/user/toolchain/linaro/bin/arm-linux-gnueabi-g++Enter the liblo source code directory and build and deploy with: cd /home/user/Desktop/QTUIO/liblo-0.26export SKIP_RMDIR_CHECK=yes./configure --prefix=/usr/local/lib/liblo --host=armmake cleanmakesudo make installcd /usr/local/lib/liblosudo cp bin/* /home/user/exported-nfs/usr/bin/sudo cp lib/liblo.a /home/user/exported-nfs/usr/bin/sudo cp lib/ /home/user/exported-nfs/usr/bin/Enter the mtdev source code directory and build and deploy with:cd /home/user/Desktop/QTUIO/mtdev-1.1.2./autogen.sh./configure --prefix=/usr/local/lib/mtdev --host=armmake cleanmakesudo make installcd /usr/local/lib/mtdevsudo cp bin/* /home/user/exported-nfs/usr/bin/sudo cp lib/libmtdev.a /home/user/exported-nfs/usr/bin/sudo cp lib/ /home/user/exported-nfs/usr/bin/Enter the mtdev2tuio bridge source code directory and build and deploy with:cd /home/user/Desktop/QTUIO/mtdev2tuiomake cleanmakesudo cp mtdev2tuio /home/user/exported-nfs/usr/bin/Enter the qTUIO source directory and build and deploy with:cd /home/user/Desktop/QTUIO/qTUIOsudo rm -rf /home/user/Desktop/QTUIO/qTUIO/lib/*cd src//home/user/output/buildroot/host/usr/bin/qmakemake cleanmakecd ../libmv libqTUIO_d.so.1.0.0 libqTUIO.so.1.0.0sudo rm -rf *libqT*_d*so*sudo ln -sf libqTUIO.so.1.0.0 libqTUIO.so.1.0sudo ln -sf libqTUIO.so.1.0.0 libqTUIO.so.1sudo ln -sf libqTUIO.so.1.0.0 libqTUIO.sosudo mkdir -p /usr/local/lib/qTUIOsudo cp -r ../lib/* /usr/local/lib/qTUIOsudo cp -r /usr/local/lib/qTUIO/* /home/user/exported-nfs/usr/lib/Now kick off the server that will take multi-touch events input frommtdev and feed that as TUIO packets to Qt:# ./mtdev2tuio /dev/input/touchscreen osc.udp://Sending OSC/TUIO packets to osc.udp://Also, ensure that you exported your Qt mouse pointer input environmentvariable as follows:export QWS_MOUSE_PROTO=tslib:/dev/input/touchscreenNow use Qt Creator or some other IDE to build and deploy the pinchzoomexample found in the qTUIO examples directory to the board.On the board ( or from Qt Creator ) run the application like:cd /home/test ; export QWS_MOUSE_PROTO=Tslib:/dev/input/touchscreen ; ./pinchzoom -qwsOutput should look like:Connecting to device...Killing remote process(es)...Starting remote process ...Remote process started.graphicsview initialized listening to TUIO messages on UDP port 3333The application will launch on your screen and you should be able to use your fingeras a mouse but also pinch and zoom ( gestures ) at the same time!Happy coding :)Feel free to leave feedback - happy coding