X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Funi-t-ut32x%2Fapi.c;h=1d12a580a76fbdd844520b1dcc3f111cf08c5504;hb=f1ba6b4b2c9a8ecf90bb31efb218752aa7e49d1a;hp=aed53aad337b01de5030cc2bb1d0f01247fc90c9;hpb=e32862ebccac5ae063abc68d9ce13a66ad46bb97;p=libsigrok.git diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index aed53aad..1d12a580 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -21,6 +21,10 @@ #include #include "protocol.h" +static const uint32_t scanopts[] = { + SR_CONF_CONN, +}; + static const uint32_t devopts[] = { SR_CONF_THERMOMETER, SR_CONF_CONTINUOUS, @@ -48,7 +52,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) const char *conn; drvc = di->context; - drvc->instances = NULL; conn = NULL; for (l = options; l; l = l->next) { @@ -71,7 +74,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup(VENDOR); sdi->model = g_strdup(MODEL); - sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = l->data; for (i = 0; i < ARRAY_SIZE(channel_names); i++) @@ -81,14 +83,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->priv = devc; devc->limit_samples = 0; devc->data_source = DEFAULT_DATA_SOURCE; - drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); } g_slist_free(usb_devices); } else g_slist_free_full(usb_devices, g_free); - return devices; + return std_scan_complete(di, devices); } static int dev_open(struct sr_dev_inst *sdi) @@ -126,9 +127,8 @@ static int dev_open(struct sr_dev_inst *sdi) sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return ret; + return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) @@ -136,14 +136,13 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; + if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } @@ -181,9 +180,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; switch (key) { @@ -213,6 +209,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * (void)cg; switch (key) { + case SR_CONF_SCAN_OPTIONS: + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + break; case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); @@ -236,9 +236,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int len, ret; unsigned char cmd[2]; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - drvc = di->context; devc = sdi->priv; usb = sdi->conn; @@ -257,7 +254,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return SR_ERR; } - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); if (!(devc->xfer = libusb_alloc_transfer(0))) return SR_ERR; @@ -291,16 +288,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - /* Signal USB transfer handler to clean up and stop. */ sdi->status = SR_ST_STOPPING; return SR_OK; } -SR_PRIV struct sr_dev_driver uni_t_ut32x_driver_info = { +static struct sr_dev_driver uni_t_ut32x_driver_info = { .name = "uni-t-ut32x", .longname = "UNI-T UT32x", .api_version = 1, @@ -318,3 +312,4 @@ SR_PRIV struct sr_dev_driver uni_t_ut32x_driver_info = { .dev_acquisition_stop = dev_acquisition_stop, .context = NULL, }; +SR_REGISTER_DEV_DRIVER(uni_t_ut32x_driver_info);