Posts 触摸屏校准
Post
Cancel

触摸屏校准

树莓派,使用 tslib 校准 egalax 触摸屏。

添加egalax USB触摸屏驱动

需要为树莓派编译内核:

1
2
3
4
5
6
7
8
9
sudo apt-get install git-core gcc-4.7-arm-linux-gnueabi
sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-4.7 /usr/bin/arm-linux-gnueabi-gcc
mkdir raspberrypi
cd raspberrypi
git clone https://github.com/raspberrypi/tools.git
git clone https://github.com/raspberrypi/linux.git
cd linux
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
1
2
3
4
5
Device Drivers  --->
	Input device support  --->
		[*]   Touchscreens  --->
		<*>   USB Touchscreen Driver
		[*]   eGalax, eTurboTouch CT-410/510/700 device support (NEW)
1
2
3
4
5
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
mkdir ../modules
make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules
cd ../tools/mkimage/
./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

插入内存卡,使用上述步骤产生的kernel.img替换内存卡上boot分区内的kernel.img(自行补全目录):

1
2
sudo rm /media/boot-partition-uuid/kernel.img
sudo cp kernel.img /media//boot/

替换掉内存卡上/lib目录下面modules/及firmware/(自行补全目录):

1
2
3
4
5
sudo rm -rf /media//lib/modules/
sudo rm -rf /media//lib/firmware/
cd ../../modules/
sudo cp -a lib/modules/ /media//lib/
sudo cp -a lib/firmware/ /media//lib/

更新:

1
sync

安装tslib

删除预装的tslib:

1
sudo apt-get purge libts-0.0-0

安装tslib:

1
sudo dpkg -i tslib_1-1_armhf.deb

创建运行脚本:

1
vim ts_calib.sh

文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash

export LD_LIBRARY_PATH=/usr/local/lib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
#NOTE: Change '/dev/input/event0', to find event# use 'ls -l /dev/input/by-id'
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/usr/local/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/local/lib/ts

ts_calibrate

校准:

1
sudo sh ts_calib.sh

使用手写笔进行校准。

测试:

1
2
3
4
5
6
7
8
export LD_LIBRARY_PATH=/usr/local/lib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/usr/local/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/local/lib/ts
ts_test

点击Draw即可在屏幕上涂划。

运行qt程序前设置环境变量(注意选择正确的event,同运行脚本),方便起见,将内容写入.profile文件:

1
vim .profile

在文件末尾添加以下内容:

1
2
3
4
5
6
7
8
export LD_LIBRARY_PATH=/usr/local/lib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/usr/local/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/local/lib/ts
export QWS_MOUSE_PROTO=Tslib:/dev/input/event0

然后使其生效:

1
source .profile

检测工具

1
evtest /dev/input/event0

如果出现“segmentation fault”提示,很可能是编译qt/embedded未成功添加触摸屏支持造成的。 可以使用如下命令解决,但是触摸屏仍然不能正常使用,建议重新编译qt/embedded。

1
2
3
sudo su
echo 2 > /proc/cpu/alignment
sudo su pi

参考:

  1. Raspberry Pi, RaspBMC & eGalax touchscreen
  2. Qt for Embedded Linux Pointer Handling
This post is licensed under CC BY 4.0 by the author.