Android虚拟触摸屏设备多点触控协议

时间:2014-02-08 11:24:34

标签: android multi-touch

早上好,

我可以在root用户手机中使用uinput创建虚拟触摸屏。使用以下jni代码:

static int startDevice(const char *touchdevice) {

 struct uinput_user_dev uidev;
 int fd;

 fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
 if (fd < 0) {
    die("error: open");
 }
 memset(&uidev, 0, sizeof(uidev));

 snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "%s",touchdevice);


 uidev.id.bustype = 0;
 uidev.id.vendor = 0x0;
 uidev.id.product = 0x0;
 uidev.id.version = 0;
 uidev.absmax[ABS_MT_POSITION_X] = 1280;
 uidev.absmax[ABS_MT_POSITION_Y] = 800;

 if (write(fd, &uidev, sizeof(uidev)) < 0) {
    die("error: write");
 }
 ioctl(fd, UI_SET_EVBIT, EV_ABS);


 ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_X);
 ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_Y);
 ioctl(fd, UI_SET_ABSBIT, ABS_MT_PRESSURE);
 ioctl(fd, UI_SET_ABSBIT, ABS_MT_TOUCH_MAJOR);
 ioctl(fd, UI_SET_ABSBIT, ABS_MT_SLOT);
 ioctl(fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);

 ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);


 if (ioctl(fd, UI_DEV_CREATE, 0) < 0) {
    die("error: ioctl");
 }

 idVirtualTouch = fd;

 return 55;
}

调用方法时,我给 touchdevice ,同名的默认android触摸屏。因此,当它创建触摸设备时,它将加载默认触摸屏的配置文件(.idc)。

问题是它创建的虚拟设备可以回答多点触控协议A而不是B(https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt)。

我目前正在使用带有android 4.1.2的Galaxy tab2,如果我将默认设备(协议b)事件转发到虚拟驱动器,它需要协议A事件,因此它无法正常工作。

默认触摸屏没有.idc,所以我只创建了一个:

touch.deviceType = touchScreen
touch.internal = 1

所以我的问题是我的触摸驱动程序使用协议B需要做些什么?问题是我的.idc还是设备的初始化?

感谢您的时间

1 个答案:

答案 0 :(得分:0)

发现问题,忘了定义插槽和跟踪ID

uidev.absmax[ABS_MT_TRACKING_ID] = 65535;
uidev.absmax[ABS_MT_SLOT] = 9;