开发者

fread from mouseevent returns 3 bytes instead of 16, sizeof(input_event)

Following the tutorial on using mouse input for robot odometry (http://web.me.com/haroldsoh/tutorials/technical-skills/using-optical-mice-for-othe-2/) I created a udev rule to identify the mouse as a custom input device, and I call it /dev/odoml & /dev/odomr.

/etc/udev/rules.d/90-odom.rules:

SUBSYSTEMS=="input" ATTRS{phys}=="usb-0000:开发者_运维问答00:1d.2-1/input0", NAME="odoml"

the usb port identifies the mouse. Now i try to read the mouse input in c:

int f = open("dev/odoml", O_RDONLY);

input_event ev;

int read_byes = (f, &ev, sizeof(input_event));

My problem is that most of the time i am getting incomplete 3 instead of the expected 16 bytes of input_event. Unplugging the mouse seems to change things: every 10 times the mouse works as expected. Once the mouse is plugged and read() correctly reads 16 bytes, the mouse remains working between executions of the program. If the mouse doesn't work, it won't start working until i replug it and have luck -- 1 out of ~10. I can't see any regularity in how it fails.

The file opens correctly every time. cat /dev/odoml displays less data when the mouse stops working. Opening the device with O_DIRECT fails. O_ASYNC, O_NDELAY don't help -- it's either -1 or 3. I checked it on 4 different mice, 3 of them behaved in this erroneous way.

Please help or point in the right direction.


The input subsystem provides several interfaces. The one you're reading from is the legacy mouse interface, which provides a /dev/psaux-style mouse device. (These are usually created as /dev/input/mouse* devices).

The one you want is the event interface for the mouse, which is usually created as /dev/input/event*. That's the one that provides the 16-byte struct input_event frames.

You'll have to tweak your udev rule to pick up the "event" device rather than the "mouse" device. Try adding this condition:

KERNEL=="event[0-9]*"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜