]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/saleae-logic16/api.c
sr_dev_close(): Set status to SR_ST_INACTIVE.
[libsigrok.git] / src / hardware / saleae-logic16 / api.c
index 3597d3f1245357ca7f24e3c1f96defe930df4fea..ff0af73532dbd09389bdd776ac1e03970e87b8ce 100644 (file)
@@ -195,7 +195,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                for (j = 0; j < ARRAY_SIZE(channel_names); j++)
                        sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE,
-                                           channel_names[j]);
+                                       channel_names[j]);
 
                devc = g_malloc0(sizeof(struct dev_context));
                devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V;
@@ -235,17 +235,13 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
        struct sr_usb_dev_inst *usb;
        struct libusb_device_descriptor des;
        struct drv_context *drvc;
-       int ret, i, device_count;
+       int ret = SR_ERR, i, device_count;
        char connection_id[64];
 
        di = sdi->driver;
        drvc = di->context;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               /* Device is already in use. */
-               return SR_ERR;
-
        device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        if (device_count < 0) {
                sr_err("Failed to get device list: %s.",
@@ -280,6 +276,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                } else {
                        sr_err("Failed to open device: %s.",
                               libusb_error_name(ret));
+                       ret = SR_ERR;
                        break;
                }
 
@@ -287,13 +284,16 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                if (ret == LIBUSB_ERROR_BUSY) {
                        sr_err("Unable to claim USB interface. Another "
                               "program or driver has already claimed it.");
+                       ret = SR_ERR;
                        break;
                } else if (ret == LIBUSB_ERROR_NO_DEVICE) {
                        sr_err("Device has been disconnected.");
+                       ret = SR_ERR;
                        break;
                } else if (ret != 0) {
                        sr_err("Unable to claim interface: %s.",
                               libusb_error_name(ret));
+                       ret = SR_ERR;
                        break;
                }
 
@@ -302,15 +302,17 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                        break;
                }
 
-               sdi->status = SR_ST_ACTIVE;
                sr_info("Opened device on %d.%d (logical) / %s (physical), interface %d.",
                        usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
 
+               ret = SR_OK;
+
                break;
        }
+
        libusb_free_device_list(devlist, 1);
 
-       if (sdi->status != SR_ST_ACTIVE) {
+       if (ret != SR_OK) {
                if (usb->devhdl) {
                        libusb_release_interface(usb->devhdl, USB_INTERFACE);
                        libusb_close(usb->devhdl);
@@ -377,15 +379,15 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct sr_usb_dev_inst *usb;
 
        usb = sdi->conn;
+
        if (!usb->devhdl)
-               return SR_ERR;
+               return SR_ERR_BUG;
 
        sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
                usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
        libusb_release_interface(usb->devhdl, USB_INTERFACE);
        libusb_close(usb->devhdl);
        usb->devhdl = NULL;
-       sdi->status = SR_ST_INACTIVE;
 
        return SR_OK;
 }
@@ -460,9 +462,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        (void)cg;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        ret = SR_OK;
@@ -674,9 +673,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        unsigned char *buf;
        size_t size, convsize;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        drvc = di->context;
        devc = sdi->priv;
        usb = sdi->conn;
@@ -775,9 +771,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
        int ret;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        ret = logic16_abort_acquisition(sdi);
 
        abort_acquisition(sdi->priv);