让qt应用程序支持触摸

一.设备驱动

我的触摸屏是usb接口的
可以参考下这2篇文件
http://blog.csdn.net/paomadi/article/details/8754783 usb触摸屏
http://blog.csdn.net/paomadi/article/details/8309861 输入子系统

不是usb接口的或者自己想写多一个也可以(需要我的源码的请留邮箱说下,我贴一部分)
usb子系统部分关键在于urb的数据传递

input子系统部分关键在于事件的设置及上报

#define M //多点触摸点数
在初始化init或者probe方法中
input_dev=input_allocate_device();//分配初始化输入设备
//(最好构建一个对象结构体,包含input设备和usb设备,或其他设备,将各个子系统的设备捆绑到一个对象中去)

set_bit(EV_KEY, input_dev->evbit);	//设置事件类型标志位
set_bit(EV_ABS, input_dev->evbit);

set_bit(BTN_TOUCH, input_dev->keybit);	//设置按键类型标志

#if M
//多点的这么设置参数(我的屏只支持单点,so没亲测)
input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,1920, 0, 0);
input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,1080, 0, 0);
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
#else
//单点的参数设置
input_set_abs_params(input_dev, ABS_X, 0, 0x7FFF, 0, 0);	//设置参数
input_set_abs_params(input_dev, ABS_Y, 0, 0x7FFF, 0, 0);
input_set_abs_params(input_dev, ABS_PRESSURE, 0, 1, 0, 0);
#endif
	
在接收到数据之后上报事件给input子系统
#if M
	//input_report_abs(touch->input, ABS_MT_TOUCH_MAJOR, 0);
	for(i=0;i<M;i++){
		input_report_abs(touchkit->input, ABS_MT_TRACKING_ID,0);
		input_report_key(touchkit->input, BTN_TOUCH, touchkit->press);
		input_report_abs(touchkit->input, ABS_MT_POSITION_X, touchkit->x);
		input_report_abs(touchkit->input, ABS_MT_POSITION_Y, touchkit->y);
		input_report_abs(touchkit->input, ABS_PRESSURE, touchkit->press);
		input_mt_sync(touchkit->input);	
	}
#else
	input_report_abs(input_dev, ABS_X, touchkit->x);
	input_report_abs(input_dev, ABS_Y, touchkit->y);
	input_report_key(input_dev, BTN_TOUCH,touchkit->press);
	input_report_abs(input_dev, ABS_PRESSURE, touchkit->press);
#endif
	input_sync(input_dev);

usb能匹配直接用hid子系统那是极好的

可以这样调试hid的设备
mkidr /tmp/debugfs
mount -t debugfs debugfs /tmp/debugfs
cd /tmp/debugfs
cd hid
cd 进对应的hid设备文件夹
cat event

其他的一些调试查看方法

ls -l /dev/input查看输入input设备
其中可以看到 lrwxrwxrwx    1 root     root            6 Jan  1  2000 touchscreen0 -> event1
/dev/input/touchscreen0是链接文件,链接到对应的触摸屏event1设备

查看event1是否触摸设备
cd /sys/class/input
cd event1
cd device
cat name
或者
cat /proc/bus/input/devices
比较Handlers和Name

 

cat /dev/input/touchscreen|hexdump 点击触摸屏查看接收到的数据


二.tslib

升级工具
sudo apt-get install autoconf
sudo apt-get install automake
sudo apt-get install libtool

解压tslib
tar xzf tslib-1.4.tar.gz
cd tslib
生产configure文件
./autogen.sh
创建安装目录
mkdir tmp
配置生成makefile文件
echo "ac_cv_func_malloc_0_nonnull=yes" >arm-none-linux-gnueabi.cache
./configure --host=arm-none-linux-gnueabi --cache-file=arm-none-linux-gnueabi.cache --prefix=$(pwd)/tmp
编译tslib
make
安装tslib
make install

安装完成后生成4个目录
/bin 目录包含ts_calibrate ts_test ts_harvest ts_print ts_print_raw测试执行文件
/etc 目录包含ts.conf配置文件
/include 目录包含 tslib.h头文件
/lib 目录包含 pkgconfig目录和ts目录和*.so(libts.so等)动态链接库

检验文件是否用交叉工具链编译的
file ts_calibrate查看打印的信息

文件系统配置
将/bin目录的和/etc目录下的文件复制到目标板文件系统的同样目录下
/include和/lib目录复制到目标板文件系统的/usr目录下

配置ts.conf
module_raw input
module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear

配置环境变量
打开目标板文件系统/etc/profile文件
export LD_LIBRARY_PATH=/usr/lib/    --库文件目录
export TSLIB_ROOT=/usr/       --tslib库文件/头文件根目录
export TSLIB_TSDEVICE=/dev/input/touchscreen0 --触摸屏设备文件路径
export TSLIB_CALIBFILE=/etc/pointercal   --校正文件路径 运行ts_calibrates会自动生成
export TSLIB_CONFFILE=/etc/ts.conf    --配置文件路径
export TSLIB_CONSOLEDEVICE=none     --
export TSLIB_FBDEVICE=/dev/fb0     --fb显示设备文件路径
export TSLIB_TSEVENTTYPE=INPUT     --触摸事件类型 input子系统
export TSLIB_PLUGINDIR=/usr/lib/ts 

  • 5
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 26
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值