login
Header Space

 
 

Linux Input driver - setting scaling/resolution on USB mouse

August 23, 2008 - 10:37pm
Submitted by CorruptDB on August 23, 2008 - 10:37pm.
Linux

I have a robotics project that uses the encoder wheels on a ball mouse to keep track of the rotation of some motors. Under the 2.4 kernel I used a PS2 mouse and the /dev/psaux interface to read the values from the mouse. The interface allowed me to set the resolution of the mouse by sending an 0xE8 control command followed by the resolution. Once I upgraded to a 2.6 kernel (still using a PS2 mouse) I started using the /dev/input/mouse* interface for the same function and everything worked the same way as it did using the psaux interface. The resolution and scaling for the mouse could be set using the standard PS2 command set.

Recently I changed the encoders to a USB mouse rather than the PS2 mouse due to the failure of the old mouse. My existing code seems to work properly with the new mouse accessing the device through /dev/input/mouse0 with 1 exception, the code setting the resolution and scaling no longer seems to work. The command is written successfully to the port and the device does not return an error, but the resolution remains the same, it is always stuck on resolution 8 (4 ticks per encoder wheel spoke, using quadrature encoding). This is a big problem for me since I can only read the mouse at a certain speed and it can only output values up to 127 before it overflows. With the PS2 mouse I was able to just change the resolution to a lower level (a 2:1 or 1:1 ratio with the encoder wheels) to be able to read fast enough that the mouse didn't overflow, but with the USB mouse I am unable to do so.

My question: does anybody know how to set the resolution on a USB mouse using the input/usbmouse drivers? It was my understanding that the /dev/input/mouse* devices are designed to emulate a PS2 mouse to maintain application compatability, but obviously it is not completely emulating the full command set for all devices. I have been searching for weeks for a solution to this problem, but documentation on this driver is quite sparse (there are a couple of .txt files in the kernel source that have some very generic information, the project web page at http://linuxconsole.sourceforge.net/input/input.html hasn't been updated in 8 years and input.h doesn't seem to have info specific to setting mouse parameters). Does anybody have information on how to accomplish what I am trying to do, or at least a pointer to some documentation on the topic?

evdev

August 24, 2008 - 2:14am

why don't you use the evdev devices /dev/input/event* (consult the by-id or by-path subdirectories created by udev or look into /proc/bus/input/devices to find the one corresponding to your mouse)? they send the data in a general format which is not prone to overflow, and you can control the device via ioctls.

i always forget where to find the documentation (i once found a man page i think), but you can look at struct input_event in /usr/include/linux/input.h or include/linux/input.h in the linux sources or at http://www.frogmouth.net/hid-doco/x401.html or google for input_event.

Thanks

August 25, 2008 - 10:28pm

Thanks a ton, I appreciate the reply. Although the documentation is also quite sparse, after much hacking and printf()ing I was able to produce some event interface code that seems to work replacing my current PS2 code. Sometimes you just need a nudge in the right direction, thanks again.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary