Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i am trying to find resources on how to access mouse movement values through C, without using GPM. I am developing in an embedded environment, and I have verified that the mouse is spitting back data by 'cat /dev/input/mice', however, I cannot find out how to interpret this data.
i am trying to find resources on how to access mouse movement values through C, without using GPM. I am developing in an embedded environment, and I have verified that the mouse is spitting back data by 'cat /dev/input/mice', however, I cannot find out how to interpret this data.
Anyone?
Interesting problem. A preliminary look tells us that data is transferred three bytes at a time (on my machine). This was found through the output of
Code:
$ xxd -b -c 3 /dev/input/mice
Snooping around the kernel, we find this interesting function in linux/drivers/input/mousedev.c
As one can clearly see, a default ps/2 mouse will have three bytes, the first of which seems to describe the buttons, the deltax, and deltay. The second and third look like absolute x and y positions on the console.
Thanks for your reply! When investigating myself before, I did an 'cat /dev/input/mice > ./testfile', and then did a hexdump on the ./testfile. Unfortunately, nothing in there seemed to look like absolute coordinates. Are we looking at the same thing?
First: if you try using xxd (i prefer this to hexdump) live (as you are moving around the mouse), how many columns of bytes is your data transmitted in? If what I think is correct, then it should be either 3 or 4 (mine is 3).
Also, I was wrong about the absolute coordinates. That should be `deltas' or coordinates relative to previous position (with an upper bound of 127). I am still not sure what coordinate space the kernel is using (I have a guess that it's the resolution set during the Configure -> Device Drivers -> Input device support -> Generic input layer -> Mouse interface (1024x768).
Alright, I think I have most of it (if all you care about is two buttons and change in location). The data is distributed as three or four bytes at a time. The first byte is a bunch of flags:
Code:
0 0 0 0 1 0 0 0
^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | |
a b c d e f g h
I do not know what bits a and b do. Bit e is always 1 and is used as a marker for the `first byte' of a message. Bit h is 1 if the left button is down and 0 if it is up. Likewise, bit g is for the right mouse button, and bit f is for the middle mouse button. Bit d is 1, iff the value stored in the next byte is negative. Bit c is 1, iff the value stored in the third byte is negative.
If you haven't already guessed, the second byte holds dx (the change in x). The format is tricky (a signed char). The third bit holds dy (as a signed char). There is no danger of overflow, since dx and dy are made sure not to exceed 127 in magnitude.
My guess is that the fourth byte (if it exists) is for a scroll wheel (dz).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.