【问题标题】:Virtual touchscreen device did not report support for X or Y axis?虚拟触摸屏设备未报告对 X 或 Y 轴的支持?
【发布时间】:2013-10-04 12:29:46
【问题描述】:

下午好,

我正在尝试在有根的 Android 手机中使用 uinput 创建一个虚拟触摸屏。

即使我能够创建设备,

   New device: id=88, fd=170, path='/dev/input/event6', name='uinput-eve', 
   classes=0x4, configuration='', keyLayout='', keyCharacterMap='', 
   builtinKeyboard=false, usingSuspendBlockIoctl=true, usingClockIoctl=false

   Touch device 'uinput-eve' did not report support for X or Y axis!  
   The device will be inoperable.

   Device added: id=88, name='uinput-eve', sources=0x00002002

由于设备无法操作,我无法正确创建它。正在跳跃任何人都可以揭示一些光。

这是我的许多尝试之一,总是导致该消息。

struct uinput_user_dev uidev;
struct input_event ev;
int dx, dy;

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, "uinput-eve");
uidev.id.bustype = BUS_VIRTUAL;
uidev.id.vendor = 0x1;
uidev.id.product = 0x1;
uidev.id.version = 1;

if (write(fd, &uidev, sizeof(uidev)) < 0) {
    die("error: write");
}
 /* touch screen event */
    ioctl(fd, UI_SET_EVBIT, EV_ABS);
    ioctl(fd, UI_SET_ABSBIT, ABS_X);
    ioctl(fd, UI_SET_ABSBIT, ABS_Y);
    ioctl(fd, UI_SET_EVBIT, EV_KEY);
   ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);


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

编辑1: 挖得更深一点,问题是显然没有设置 mRawPointerAxes,任何人 知道如何设置它们吗?以下代码来自 services/input/InputReader.cpp。

// Ensure we have valid X and Y axes.
if (!mRawPointerAxes.x.valid || !mRawPointerAxes.y.valid) {
    LOGW(INDENT "Touch device '%s' did not report support for X or Y axis!  "
            "The device will be inoperable.", getDeviceName().string());
    mDeviceMode = DEVICE_MODE_DISABLED;
    return;
}

提前感谢您的宝贵时间。

【问题讨论】:

标签: android input touch linux-device-driver


【解决方案1】:

对于绝对轴,您需要在结构 uinput_user_dev 中定义它们的范围。如果 absmin 和 absmax 相等,Android 将拒绝轴为无效。 (参见 EventHub.cpp EventHub::getAbsoluteAxisInfo)

由于您没有定义 absmax 或 absmin,所以它们都是 0。尝试添加:

uidev.absmax[ABS_X] = 1024; 
uidev.absmax[ABS_Y] = 1024;

将 1024 更改为您想要的实际分辨率。

【讨论】:

  • 谢谢你的工作,我现在有一个不同的问题。我似乎无法将事件注入此虚拟设备。我像在真正的触摸屏上一样注入触摸,它根本不会复制触摸。有什么想法吗?
  • 你需要用SYN_REPORT结束一个序列,否则什么都不处理。有关详细信息,请参阅kernel.org/doc/Documentation/input/multi-touch-protocol.txt
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多