diff options
author | Pete Batard <pbatard@gmail.com> | 2010-01-14 01:11:25 +0000 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-01-14 01:11:25 +0000 |
commit | 967842d93cf2504a07ba7284a4cfa8a7295f3f93 (patch) | |
tree | 0ff9374452b1424679ea125bf5fdb7a4c98246f5 /examples | |
parent | edae10e465d922fc1e726cd9700c493a8bd4716b (diff) | |
download | libusb-967842d93cf2504a07ba7284a4cfa8a7295f3f93.tar.gz |
svn r11: remove dpfp compilation (doesn't work on Windows) and add the xusb test program
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 6 | ||||
-rw-r--r-- | examples/xusb.c | 71 |
2 files changed, 76 insertions, 1 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index 600ebd4..6db7d0a 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,9 +1,13 @@ INCLUDES = -I$(top_srcdir) -noinst_PROGRAMS = lsusb dpfp dpfp_threaded +noinst_PROGRAMS = xusb lsusb +#dpfp dpfp_threaded lsusb_SOURCES = lsusb.c lsusb_LDADD = ../libusb/libusb-1.0.la -lusb-1.0 +xusb_SOURCES = xusb.c +xusb_LDADD = ../libusb/libusb-1.0.la -lusb-1.0 + dpfp_SOURCES = dpfp.c dpfp_LDADD = ../libusb/libusb-1.0.la -lusb-1.0 diff --git a/examples/xusb.c b/examples/xusb.c new file mode 100644 index 0000000..51140e4 --- /dev/null +++ b/examples/xusb.c @@ -0,0 +1,71 @@ +/* + * libusb example program to list devices on the bus + * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdio.h> +#include <sys/types.h> + +#include <libusb/libusb.h> + +static void print_devs(libusb_device **devs) +{ + libusb_device *dev; + libusb_device_handle *handle; + int i = 0; + + while ((dev = devs[i++]) != NULL) { + struct libusb_device_descriptor desc; + int r = libusb_get_device_descriptor(dev, &desc); + if (r < 0) { + fprintf(stderr, "failed to get device descriptor"); + return; + } + + printf("%04x:%04x (bus %d, device %d)\n", + desc.idVendor, desc.idProduct, + libusb_get_bus_number(dev), libusb_get_device_address(dev)); + + // DEBUG: Access an XBox gamepad through WinUSB + if ((desc.idVendor == 0x045e) && (desc.idProduct == 0x0289)) { + printf("got Xbox gamepad\n"); + r = libusb_open(dev, &handle); + } + } +} + +int main(void) +{ + libusb_device **devs; + int r; + ssize_t cnt; + + r = libusb_init(NULL); + if (r < 0) + return r; + + cnt = libusb_get_device_list(NULL, &devs); + if (cnt < 0) + return (int) cnt; + + print_devs(devs); + libusb_free_device_list(devs, 1); + + libusb_exit(NULL); + return 0; +} + |