]> sigrok.org Git - libsigrok.git/commitdiff
opendev2/opendev3: Don't depend on global vars.
authorUwe Hermann <redacted>
Fri, 14 May 2010 11:12:06 +0000 (13:12 +0200)
committerUwe Hermann <redacted>
Mon, 17 May 2010 22:05:09 +0000 (00:05 +0200)
hardware/saleae-logic/saleae-logic.c

index a7f14713d5c6a49883b7469ccbb82852d60f493f..423e1d3441cf114ee21e8f5d04b235ef447a1de8 100644 (file)
@@ -166,7 +166,7 @@ int check_conf_profile(libusb_device *dev)
 
 static int opendev2(int device_index, struct sigrok_device_instance **sdi,
                    libusb_device *dev, struct libusb_device_descriptor *des,
-                   int *skip)
+                   int *skip, uint16_t vid, uint16_t pid, int interface)
 {
        int err;
 
@@ -175,7 +175,7 @@ static int opendev2(int device_index, struct sigrok_device_instance **sdi,
                return -1;
        }
 
-       if (des->idVendor != USB_VENDOR || des->idProduct != USB_PRODUCT)
+       if (des->idVendor != vid || des->idProduct != pid)
                return 0;
 
        if (*skip != device_index) {
@@ -193,7 +193,7 @@ static int opendev2(int device_index, struct sigrok_device_instance **sdi,
                (*sdi)->status = ST_ACTIVE;
                g_message("opened device %d on %d.%d interface %d",
                          (*sdi)->index, (*sdi)->usb->bus,
-                         (*sdi)->usb->address, USB_INTERFACE);
+                         (*sdi)->usb->address, interface);
        } else {
                g_warning("failed to open device: %d", err);
                *sdi = NULL;
@@ -203,7 +203,8 @@ static int opendev2(int device_index, struct sigrok_device_instance **sdi,
 }
 
 static int opendev3(struct sigrok_device_instance **sdi, libusb_device *dev,
-                   struct libusb_device_descriptor *des)
+                   struct libusb_device_descriptor *des,
+                   uint16_t vid, uint16_t pid, int interface)
 {
        int err;
 
@@ -212,7 +213,7 @@ static int opendev3(struct sigrok_device_instance **sdi, libusb_device *dev,
                return -1;
        }
 
-       if (des->idVendor != USB_VENDOR || des->idProduct != USB_PRODUCT)
+       if (des->idVendor != vid || des->idProduct != pid)
                return 0;
 
        if (libusb_get_bus_number(dev) == (*sdi)->usb->bus
@@ -222,7 +223,7 @@ static int opendev3(struct sigrok_device_instance **sdi, libusb_device *dev,
                        (*sdi)->status = ST_ACTIVE;
                        g_message("opened device %d on %d.%d interface %d",
                                  (*sdi)->index, (*sdi)->usb->bus,
-                                 (*sdi)->usb->address, USB_INTERFACE);
+                                 (*sdi)->usb->address, interface);
                } else {
                        g_warning("failed to open device: %d", err);
                        *sdi = NULL;
@@ -254,7 +255,8 @@ struct sigrok_device_instance *sl_open_device(int device_index)
                for (i = 0; devlist[i]; i++) {
                        /* TODO: Error handling. */
                        err = opendev2(device_index, &sdi, devlist[i], &des,
-                                      &skip);
+                                      &skip, USB_VENDOR, USB_PRODUCT,
+                                      USB_INTERFACE);
                }
        } else if (sdi->status == ST_INACTIVE) {
                /*
@@ -264,7 +266,8 @@ struct sigrok_device_instance *sl_open_device(int device_index)
                libusb_get_device_list(usb_context, &devlist);
                for (i = 0; devlist[i]; i++) {
                        /* TODO: Error handling. */
-                       err = opendev3(&sdi, devlist[i], &des);
+                       err = opendev3(&sdi, devlist[i], &des, USB_VENDOR,
+                                      USB_PRODUCT, USB_INTERFACE);
                }
        } else {
                /* Status must be ST_ACTIVE, i.e. already in use... */