LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-15-2007, 08:21 AM   #1
alexandre_fs
LQ Newbie
 
Registered: Oct 2006
Distribution: kubuntu 6.06
Posts: 18

Rep: Reputation: 0
Static USB mouse device file?


Hello.

I am developping an application that uses 2 usb mouse devices for movement tracking (replacing the need of an encoder). But one problem that i have now is that it would help that Linux atributes a fixed device file for each mouse.

For example, I need that the mouse in the left wheel becomes always /dev/input/mouse1

I found a guide that could help me doing this, by changing UDEV rules here: http://gentoo-wiki.com/HOWTO_static_USB_mouse

but, unfortunetly i found that none of the information that it displays of each mouse is unique. What i mean is, I need to find any kind of information about each mouse that identifies it, so that i can create a rule that attributes /dev/input/mouseX to one specific mouse. The mice are exactly the same, same vendor, same product_id..... i was hoping that there is some kind of hash number or mac address (whatever) that identifies uniquely the product.

One other method would be that Linux atributes by order, one by one, each mouse device, so if I have them plugged always in same physical usb port, they would always have the same device file. However from the tests i made, this is not true. At least with the standard configurations of UDEV and xorg.conf

my distr is Kubuntu 6.06 with the latest kernel.

any suggestions?

thank you very much for reading this
 
Old 03-15-2007, 11:08 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,096

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
There must be a way to distinguish between these two "identical" mice!
That's what udev is all about!
Try this:

Unplug both mice.
Plug mouse A in. Do dmesg. Look for the bit about a mouse being detected. For me(today) it says "logitech mouse ...... as /class/input/input2"
OK so now we know that mouse is at /class/input/input2, so now do:
udevinfo -a -p /sys/class/input/input2 > foo_mouseA

Repeat for mouse B, plugged into a different port, but this time do
udevinfo -a -p /sys/class/input/inputwhatever B's number is > foo_mouseB

Now a diff foo_mouseA foo_mouseB
You'll see the differences, as seen by udev. Obviously, they'll have different "input" numbers, but this is useless to you. But I also see the following differences, which may well be useful:
ID=="2-1"
ID=="3-1"
ID=="usb2"
ID=="usb3"
SYSFS{serial}=="0000.00.1d.1"
SYSFS{serial}=="0000.00.1d.2"

Edit: Furthermore, unplugging "Mouse B", and plugging it back in again, then doing udevinfo -a -p /sys/class/input/inputwhatever B's latestnumber is > foo_mouseB_again then diff foo_mouseB foo_mouseB_again reveals that "ID==3-1" stays the same, so that must be the part you need, and it is found "looking at the device chain '/sys/devices/pci0000:00/0000:00:1d.2/usb3/3-1':30c30.

So I expect that's where to start.

This is a popular link for writing USB rules:
http://reactivated.net/udevrules.php

Last edited by tredegar; 03-15-2007 at 11:21 AM.
 
Old 03-16-2007, 08:05 AM   #3
alexandre_fs
LQ Newbie
 
Registered: Oct 2006
Distribution: kubuntu 6.06
Posts: 18

Original Poster
Rep: Reputation: 0
thank you for your answer.

I took your idea and made some tests. I restarted the computer a million times (i wanted to prove that those IDs 2-1,3-1 are permanent to each USB physical port even after reboot) and I found like you said that they don't change.

I tried every possible combination and the one thing that stays permanent is that a certain USB port always have the same ID. In my case, i have 3: 1-1 ; 2-2 ; 3-1

So, instead of trying to identify each mouse, i identify each port, knowing that a certain mouse is always plugged in the same place. Thank you for your suggestion, I am almost sure that I'll be able to solve my problem now.

I'll look for the UDEV rules, and when i get it right, i'll post it here for any possible interested
 
Old 03-16-2007, 02:37 PM   #4
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,096

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Quote:
I tried every possible combination and the one thing that stays permanent is that a certain USB port always have the same ID. In my case, i have 3: 1-1 ; 2-2 ; 3-1
I am very pleased to hear that you have been experimenting and made some progress!

Also good news is that you have confirmed that there is a way to differentiate between two physically identical mice by referencing which sockets they are plugged into.

The difficult part (as I expect you have discovered by now) will be adding the correct line to one of those udev.rules files.

I am no expert at udev (<= to your level I suspect!), but realise it will be useful to know more about it, so please keep me / this board informed of your progress, and I'll help where I can.

Remember that I think you may need to let udev know that you have changed the rules with /etc/init.d/udev restart (you'll need to be root) for your changes to take effect. This should be faster & easier than rebooting all the time.

Persevere and you will solve this problem!
 
Old 03-19-2007, 11:10 AM   #5
alexandre_fs
LQ Newbie
 
Registered: Oct 2006
Distribution: kubuntu 6.06
Posts: 18

Original Poster
Rep: Reputation: 0
hello again. I think it's done.
What I did was create a file called '10-local.rules' in the directory of UDEV rules. (etc/udev/rules.d)

UDEV reads the different files in alphabetical order, so I had to create a file with my rules that would be read first than the default rules (such as '40-permission.rules' and others...)

I just added these two lines:

BUS=="usb", ID=="1-1", KERNEL=="mouse*" , NAME="input/sensor1"
BUS=="usb", ID=="3-1", KERNEL=="mouse*" , NAME="input/sensor2"

KERNEL=="sensor1", MODE="0664"

the first two say that if a usb device, plugged in the 1-1 (or 3-1) USB port and detected by kernel as being a mouse, then it should be called sensor1.
the other line is just to make the device readable to any user (but not writable...)

thanks again for your help!
 
Old 03-19-2007, 01:03 PM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,096

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Thanks for the follow-up, I'm sure others will find this thread useful, and you did most of the real work yourself! Well done.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to get USB Mouse working as a second pointer device paulsiu Linux - Hardware 3 03-06-2007 09:30 AM
change file permission of a mouse device file permanently alexandre_fs Linux - General 5 01-09-2007 07:30 AM
mapping usb device to device file scerenon Linux - Hardware 12 07-20-2006 05:13 PM
Assign one USB-storage device to one device file Misel Linux - Hardware 1 08-28-2004 04:52 AM
USB mouse on Slackware10 ( Or other device too ) caovankhanhvn Linux - Laptop and Netbook 9 08-12-2004 09:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration