GP2X Detecting Usb Connect/disconnects?


foft

Certified Guru
Joined
Mar 14, 2004
Messages
480
Location
London, UK
Website
www.scrameta.net
I'm trying to detect keyboard/joysticks being attached. I've tried several strategies, all of which work on my other linux boxes (2.6...), but none work on the GP2X! What is the best method for this?

I tried:
i) F_NOTIFY in fcntl on "/dev/input". Works and returns success, but never notifies.
ii) Checking st.st_mtime on "/dev/input". Always 0.
iii) Checking st.st_size on "/dev/input". Always 0.
iv) Checking st_mine/st_size on "/proc/bus/input/devices". Does not exist in this kernel.
v) Checking st_mine/st_size on "/proc/bus/usb/devices". Does not exist in this kernel.
vi) Opening "/dev/input" and using fseek(f,0,SEEK_END). ftell always returns 0.
vii) Opening "/dev/input" and using lseek(f,0,SEEK_END). ftell always returns 0.
viii) Opening "/dev/input" and using lseek(f,A_LARGE_NUMBER,SEEK_SET). ftell always returns the large number - even if past end.
ix) Polling /dev/input/eventx a few times a second. Too slow. Takes a second to do 100 polls?
x) Looked into telldir/seekdir. No way to seek to end?
xi) Checked /sys - does not exist.

This is getting annoying now... I'm even tempted to monitor the kernel ringbuffer (as returned by dmesg)!

Also has anyone got crosstool or crosstool NG to work with a recent gcc? I'd really like to build gcc 4.2.3 on my mac (using linux for now), but not having any luck.

Thanks,

Mark
 
I had a method that monitored the usb address register for changes. However, it doesn't seem to work when you attach a hub to the usb host port (eg. the cradle) :(
 
I thought I'd use opendir instead to scan the directory... (takes .5ms, so not ideal but...) It does detects new files added. However, even if I closedir/opendir and rewinddir it does not detect deletes. Until I restart the process! Gah!

So to detect deletes I need to open (or stat) each file - which seems to take .25ms each. So each time someone disconnects/connects a device the scan (every second) takes .25ms longer! Not really a big issue I guess, but its quite annoying...

Mark
 
Back
Top