diff options
author | Daniel Drake <dsd@gentoo.org> | 2008-03-06 23:43:57 +0000 |
---|---|---|
committer | Daniel Drake <dsd@gentoo.org> | 2008-03-06 23:43:57 +0000 |
commit | 23f8fb8bafeeda93ce234cb40eb7219d2e36c19c (patch) | |
tree | 8d8cf461108906423bbe4a2586859e8f7a9a459d /examples | |
parent | 9cfdb494fccac53a4277da7c8b6d15f1a72a4959 (diff) | |
download | libusb-23f8fb8bafeeda93ce234cb40eb7219d2e36c19c.tar.gz |
Add convenience function to find and open a device by USB VID+PID
Lots of libusb apps I write are simple test apps not intended to be real
apps. Having a function available to quickly locate my device will be
handy in such situations.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dpfp.c | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/examples/dpfp.c b/examples/dpfp.c index 87a7da1..6b5124e 100644 --- a/examples/dpfp.c +++ b/examples/dpfp.c @@ -81,36 +81,8 @@ static struct libusb_bulk_transfer irqtrf = { static int find_dpfp_device(void) { - struct libusb_device *dev; - struct libusb_device *found = NULL; - struct libusb_device **devs; - size_t i = 0; - int r; - - r = libusb_get_device_list(&devs); - if (r < 0) - return r; - - while ((dev = devs[i++]) != NULL) { - struct libusb_dev_descriptor *desc = libusb_device_get_descriptor(dev); - if (desc->idVendor == 0x05ba && desc->idProduct == 0x000a) { - found = dev; - break; - } - } - - if (!found) { - r = -ENODEV; - goto out; - } - - devh = libusb_open(dev); - if (!devh) - r = -EIO; - -out: - libusb_free_device_list(devs, 1); - return r; + devh = libusb_open_device_with_vid_pid(0x05ba, 0x000a); + return devh ? 0 : -EIO; } static int print_f0_data(void) |