首页 > 技术知识 > 正文

嵌入式QT程序需要支持触屏和鼠标同时使用,一般会使用tslib库(tslib和qt编译请参照网上其他帖子)

qt和tslib配置如下:

注意替换库文件路径和对应的设备文件路径

LIB_ROOT=/usr QT_DIR=${LIB_ROOT}/qt4.8.6 TS_DIR=${LIB_ROOT}/tslib-1.8 export LD_LIBRARY_PATH=${LIB_ROOT}/lib:${QT_DIR}/lib:${TS_DIR}/lib:${ShellPath} export QT_QWS_FONTDIR=${QT_DIR}/lib/fonts export QWS_DISPLAY=”LinuxFb:/dev/fb1″ export QWS_MOUSE_PROTO=”mouseman:/dev/input/mice tslib:/dev/input/touchscreen0″ export TSLIB_TSDEVICE=”/dev/input/touchscreen0″ export TSLIB_CONFFILE=${TS_DIR}/etc/ts.conf export POINTERCAL_FILE=${TS_DIR}/etc/pointercal export TSLIB_CALIBFILE=${TS_DIR}/etc/pointercal export TSLIB_CONSOLEDEVICE=none export TSLIB_FBDEVICE=/dev/fb1 export TSLIB_PLUGINDIR=${TS_DIR}/lib/ts

使用这个配置时,鼠标可以正常操作,触屏操作就显得有些魔性了…

解决思路:这个问题是由于触屏设备在input子系统注册的时候,会被视为一个mouse设备。/dev/input/mice这个设备会连接所有的mouse设备,导致触屏设备上报坐标变化时,/dev/input/mice也会上报,此时mice上报的数据点不准确。

2个解决办法(推荐使用第二种):

在配置中不使用mice,将指定鼠标的event handler固定(如固定为event1,配置时将mice替换为event1即可)。

参照另一个帖子固定event handler. 点我传送

修改内核源码中的drivers/input/mousedev.c文件。在将鼠标设备连接到mice的时候,忽略触屏设备,使触屏设备与mice互相独立,互不影响。修改如下:

文件顶部头文件添加

#include <linux/string.h>

mousedev_connect 、 mousedev_disconnect 函数修改(此处我的触屏设备名为touchScreen)

static int mousedev_connect(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id) { struct mousedev *mousedev; int minor; int error; // add by wx: ignore touch screen static const char* tsname = “touchScreen”; printk(KERN_INFO “%s: %s”, __func__, dev->name); for (minor = 0; minor < MOUSEDEV_MINORS; minor++) if (!mousedev_table[minor]) break; if (minor == MOUSEDEV_MINORS) { printk(KERN_ERR “mousedev: no more free mousedev devicesn”); return -ENFILE; } mousedev = mousedev_create(dev, handler, minor); if (IS_ERR(mousedev)) return PTR_ERR(mousedev); // add by wx: (mixdev_add_device) ignore touch screen if (!strcmp(dev->name, tsname)) return 0; error = mixdev_add_device(mousedev); if (error) { mousedev_destroy(mousedev); return error; } return 0; }
<
static void mousedev_disconnect(struct input_handle *handle) { struct mousedev *mousedev = handle->private; // modify by wx: (mixdev_remove_device) ignore touch screen static const char* tsname = “touchScreen”; printk(KERN_INFO “%s: %s”, __func__, handle->dev->name); if (strcmp(handle->dev->name, tsname)) mixdev_remove_device(mousedev); mousedev_destroy(mousedev); }

猜你喜欢