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 <christopher.a.dickens@gmail.com>
This commit is contained in:
Chris Dickens 2020-01-13 12:50:40 -08:00
parent 88ded79caa
commit cb95e3ad35
2 changed files with 16 additions and 27 deletions

View file

@ -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(" Manufacturer: %s\n", string);
}
if (ret > 0)
printf("%s - ", string);
else
printf("%04X - ", desc.idVendor);
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(" Product: %s\n", string);
}
if (ret > 0)
printf("%s\n", string);
else
printf("%04X\n", desc.idProduct);
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) {