From 1be063f7bf1bfc1c448035113ab054f0af0a21bd Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 7 Sep 2020 11:25:54 +0200 Subject: [PATCH] examples/testlibusb: Print speed of devices Print the speed of devices to exercise libusb_get_device_speed(). Signed-off-by: Hans de Goede --- examples/testlibusb.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/testlibusb.c b/examples/testlibusb.c index f9e095a..52bf501 100755 --- a/examples/testlibusb.c +++ b/examples/testlibusb.c @@ -164,18 +164,28 @@ static void print_device(libusb_device *dev, libusb_device_handle *handle) { struct libusb_device_descriptor desc; unsigned char string[256]; + const char *speed; int ret; uint8_t i; + switch (libusb_get_device_speed(dev)) { + case LIBUSB_SPEED_LOW: speed = "1.5M"; break; + case LIBUSB_SPEED_FULL: speed = "12M"; break; + case LIBUSB_SPEED_HIGH: speed = "480M"; break; + case LIBUSB_SPEED_SUPER: speed = "5G"; break; + case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break; + default: speed = "Unknown"; + } + ret = libusb_get_device_descriptor(dev, &desc); if (ret < 0) { fprintf(stderr, "failed to get device descriptor"); return; } - printf("Dev (bus %u, device %u): %04X - %04X\n", + printf("Dev (bus %u, device %u): %04X - %04X speed: %s\n", libusb_get_bus_number(dev), libusb_get_device_address(dev), - desc.idVendor, desc.idProduct); + desc.idVendor, desc.idProduct, speed); if (!handle) libusb_open(dev, &handle); -- 2.7.4