You can use regcomp()/regexec() (regex.h) to do your own parsing instead
of calling grep externally.  You could also use libusb to grab the list
of devices and run through them, checking for the joystick.  Either way
would work.

However, it doesn't really sound like that would be sufficient without
some serious tuning.

I'm guessing you could do this two ways:

1)  Have a thread regularly read the USB device list and signal when the
joystick's gone missing.

2)  Use select() and non-blocking reads to perform time out when there
isn't an input in X timeunits.  When you get a timeout, recheck the USB
device list.


The problem with all of this is the delay from when the device is
actually unplugged to when you detect it's been unplugged.  (Maybe it's
not an issue in practice.)  With a fast enough loop/timeout you could
detect an unplugged joystick pretty quickly, but will it be quick enough
to safely stop a really large/fast robot?


I'm not sure if there is some sort of signally mechanism that you can
detect when the /proc entry is closed by the driver, but that would be
your best bet of all of these.  (Maybe there's some signal that is
ignored by default that you can catch?)

Anyway, just adding some warnings to the aforementioned solutions.


Paul Braman
Paul<dot>Braman<at>NielsenMedia<dot>com

Senior Engineer
Engineering and Technology
Nielsen Media Research


> -----Original Message-----
> From: Tim Arney
> Sent: Thursday, November 18, 2004 8:58 AM
> Subject: Re: [Linux-usb-users] Detecting unplugged device
> 
> Thanks for your quick reply.  So can I execute grep from 
> within a C program?  Is there no way you know of using the 
> usb library directly?
> 
> 
> Quoting Edward <[EMAIL PROTECTED]>:
> 
> > My best bet would be to grep the /proc/bus/usb/devices 
> > file for your joystick device.
> > 
> > 
> > ----- Original Message -----
> > From: "Tim Arney" <[EMAIL PROTECTED]>
> > Sent: Thursday, November 18, 2004 13:51
> > Subject: [Linux-usb-users] Detecting unplugged device
> > 
> > > So anyway, I'm essentially looking for a point in the 
> > > right direction as to how I might test to see if the 
> > > joystick is connected from my C/C++ program?


-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users

Reply via email to