X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fvictor-dmm%2Fapi.c;h=d415a3f9cc86c4809db8dd44898a1c222dec3d19;hb=090f1e1e5478ea15baa3731fefbd4aff9be78c77;hp=b8db20483562486cbe983ea046c2b60cd66d9162;hpb=7e463623382e1f574fde150b3fc88a65eaebb578;p=libsigrok.git diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index b8db2048..d415a3f9 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -28,18 +28,17 @@ #define VICTOR_VID 0x1244 #define VICTOR_PID 0xd237 -#define VICTOR_VENDOR "Victor" #define VICTOR_INTERFACE 0 #define VICTOR_ENDPOINT (LIBUSB_ENDPOINT_IN | 1) -static const uint32_t drvopts[] = { - SR_CONF_MULTIMETER, -}; - static const uint32_t scanopts[] = { SR_CONF_CONN, }; +static const uint32_t drvopts[] = { + SR_CONF_MULTIMETER, +}; + static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, @@ -70,11 +69,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (des.idVendor != VICTOR_VID || des.idProduct != VICTOR_PID) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; - sdi->vendor = g_strdup(VICTOR_VENDOR); + sdi->vendor = g_strdup("Victor"); sdi->connection_id = g_strdup(connection_id); devc = g_malloc0(sizeof(struct dev_context)); sr_sw_limits_init(&devc->limits); @@ -105,8 +105,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (ret != SR_OK) return ret; - /* The device reports as HID class, so the kernel would have - * claimed it. */ if (libusb_kernel_driver_active(usb->devhdl, 0) == 1) { if ((ret = libusb_detach_kernel_driver(usb->devhdl, 0)) < 0) { sr_err("Failed to detach kernel driver: %s.", @@ -131,23 +129,20 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, VICTOR_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } -static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_get(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc = sdi->priv; struct sr_usb_dev_inst *usb; - char str[128]; (void)cg; @@ -156,8 +151,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s if (!sdi || !sdi->conn) return SR_ERR_ARG; usb = sdi->conn; - snprintf(str, 128, "%d.%d", usb->bus, usb->address); - *data = g_variant_new_string(str); + *data = g_variant_new_printf("%d.%d", usb->bus, usb->address); break; case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_MSEC: @@ -169,8 +163,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_OK; } -static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_set(uint32_t key, GVariant *data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -181,30 +175,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return sr_sw_limits_config_set(&devc->limits, key, data); } -static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_list(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - (void)sdi; - (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: - if (!sdi) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); - else - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; - default: - return SR_ERR_NA; - } - - return SR_OK; + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); } static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) @@ -328,7 +302,7 @@ static struct sr_dev_driver victor_dmm_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, - .dev_clear = NULL, + .dev_clear = std_dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list,