From cb95e3ad35319eb1898eff791391a696a85775a5 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Mon, 13 Jan 2020 12:50:40 -0800 Subject: examples: testlibusb: Always print VID and PID in addition to strings Previously the program would only print the VID when the manufacturer string is unavailable and the PID when the product string is unavailable. Change this to print the VID and PID unconditionally and print the manufacturer and product strings similar to how the serial number string is being printed. In addition, line up the string values with the rest of the output. Signed-off-by: Chris Dickens --- examples/testlibusb.c | 41 +++++++++++++++-------------------------- libusb/version_nano.h | 2 +- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/examples/testlibusb.c b/examples/testlibusb.c index 3eb0fc6..7a29c1a 100755 --- a/examples/testlibusb.c +++ b/examples/testlibusb.c @@ -178,40 +178,29 @@ static void print_device(libusb_device *dev) return; } - printf("Dev (bus %u, device %u): ", - libusb_get_bus_number(dev), libusb_get_device_address(dev)); + printf("Dev (bus %u, device %u): %04X - %04X\n", + libusb_get_bus_number(dev), libusb_get_device_address(dev), + desc.idVendor, desc.idProduct); ret = libusb_open(dev, &handle); if (LIBUSB_SUCCESS == ret) { - if (desc.iManufacturer) + if (desc.iManufacturer) { ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string)); - else - ret = LIBUSB_ERROR_NOT_FOUND; - - if (ret > 0) - printf("%s - ", string); - else - printf("%04X - ", desc.idVendor); + if (ret > 0) + printf(" Manufacturer: %s\n", string); + } - if (desc.iProduct) + if (desc.iProduct) { ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string)); - else - ret = LIBUSB_ERROR_NOT_FOUND; - - if (ret > 0) - printf("%s\n", string); - else - printf("%04X\n", desc.idProduct); + if (ret > 0) + printf(" Product: %s\n", string); + } - if (desc.iSerialNumber && verbose) + if (desc.iSerialNumber && verbose) { ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string)); - else - ret = LIBUSB_ERROR_NOT_FOUND; - - if (ret > 0) - printf(" Serial Number: %s\n", string); - } else { - printf("%04X - %04X\n", desc.idVendor, desc.idProduct); + if (ret > 0) + printf(" Serial Number: %s\n", string); + } } if (verbose) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 26ee5e6..bf39e2b 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11422 +#define LIBUSB_NANO 11423 -- cgit v1.2.1