examples: testlibusb: Always print VID and PID in addition to strings
authorChris Dickens <christopher.a.dickens@gmail.com>
Mon, 13 Jan 2020 20:50:40 +0000 (12:50 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Mon, 13 Jan 2020 20:50:40 +0000 (12:50 -0800)
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 <christopher.a.dickens@gmail.com>
examples/testlibusb.c
libusb/version_nano.h

index 3eb0fc6..7a29c1a 100755 (executable)
@@ -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) {
index 26ee5e6..bf39e2b 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11422
+#define LIBUSB_NANO 11423