]> git.sesse.net Git - bmusb/blobdiff - bmusb.cpp
Add an option to get a textual description of each card.
[bmusb] / bmusb.cpp
index 2ea6407f6ce1bf230e31ee7aaeb363a8d407b784..3132c42f2718ae80d19f4ec175b7ecf2feb48d98 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -28,6 +28,7 @@
 #include <memory>
 #include <mutex>
 #include <stack>
+#include <string>
 #include <thread>
 
 using namespace std;
@@ -706,7 +707,7 @@ struct USBCardDevice {
        libusb_device *device;
 };
 
-libusb_device_handle *open_card(int card_index)
+libusb_device_handle *open_card(int card_index, string *description)
 {      
        libusb_device **devices;
        ssize_t num_devices = libusb_get_device_list(nullptr, &devices);
@@ -745,14 +746,22 @@ libusb_device_handle *open_card(int card_index)
        });
 
        for (size_t i = 0; i < found_cards.size(); ++i) {
-               fprintf(stderr, "Card %d: Bus %03u Device %03u ", int(i), found_cards[i].bus, found_cards[i].port);
+               const char *product_name = nullptr;
                if (found_cards[i].product == 0xbd3b) {
-                       fprintf(stderr, "Intensity Shuttle\n");
+                       product_name = "Intensity Shuttle";
                } else if (found_cards[i].product == 0xbd4f) {
-                       fprintf(stderr, "UltraStudio SDI\n");
+                       product_name = "UltraStudio SDI";
                } else {
                        assert(false);
                }
+
+               char buf[256];
+               snprintf(buf, sizeof(buf), "Card %d: Bus %03u Device %03u  %s",
+                       int(i), found_cards[i].bus, found_cards[i].port, product_name);
+               if (i == size_t(card_index)) {
+                       *description = buf;
+               }
+               fprintf(stderr, "%s\n", buf);
        }
 
        if (size_t(card_index) >= found_cards.size()) {
@@ -794,7 +803,7 @@ void BMUSBCapture::configure_card()
                exit(1);
        }
 
-       libusb_device_handle *devh = open_card(card_index);
+       libusb_device_handle *devh = open_card(card_index, &description);
        if (!devh) {
                fprintf(stderr, "Error finding USB device\n");
                exit(1);