X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fvictor-dmm%2Fapi.c;h=74523ed7aabbfd4cef6e0baab92a0f917e3f4ce2;hb=5d336f1130ddc2faaeabd7ed6ec602904054bfb8;hp=06b47a57486727ac9840ff83a083be545f8f5efc;hpb=6078d2c99619233173d4536b74258c15e6be73ba;p=libsigrok.git diff --git a/hardware/victor-dmm/api.c b/hardware/victor-dmm/api.c index 06b47a57..74523ed7 100644 --- a/hardware/victor-dmm/api.c +++ b/hardware/victor-dmm/api.c @@ -33,7 +33,6 @@ SR_PRIV struct sr_dev_driver victor_dmm_driver_info; static struct sr_dev_driver *di = &victor_dmm_driver_info; -static int dev_close(struct sr_dev_inst *sdi); static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static const int32_t hwopts[] = { @@ -47,37 +46,9 @@ static const int32_t hwcaps[] = { SR_CONF_CONTINUOUS, }; -/* Properly close and free all devices. */ -static int clear_instances(void) -{ - struct sr_dev_inst *sdi; - struct drv_context *drvc; - struct dev_context *devc; - GSList *l; - - if (!(drvc = di->priv)) - /* Can get called on an unused driver, doesn't matter. */ - return SR_OK; - - for (l = drvc->instances; l; l = l->next) { - if (!(sdi = l->data)) - continue; - if (!(devc = sdi->priv)) - continue; - dev_close(sdi); - sr_usb_dev_inst_free(sdi->conn); - sr_dev_inst_free(sdi); - } - - g_slist_free(drvc->instances); - drvc->instances = NULL; - - return SR_OK; -} - static int init(struct sr_context *sr_ctx) { - return std_hw_init(sr_ctx, di, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } static GSList *scan(GSList *options) @@ -85,7 +56,7 @@ static GSList *scan(GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; - struct sr_probe *probe; + struct sr_channel *ch; struct libusb_device_descriptor des; libusb_device **devlist; GSList *devices; @@ -117,9 +88,9 @@ static GSList *scan(GSList *options) return NULL; sdi->priv = devc; - if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) + if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) return NULL; - sdi->probes = g_slist_append(NULL, probe); + sdi->channels = g_slist_append(NULL, ch); if (!(sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL))) @@ -215,24 +186,29 @@ static int dev_close(struct sr_dev_inst *sdi) static int cleanup(void) { + int ret; struct drv_context *drvc; if (!(drvc = di->priv)) /* Can get called on an unused driver, doesn't matter. */ return SR_OK; - clear_instances(); + + ret = std_dev_clear(di, NULL); g_free(drvc); di->priv = NULL; - return SR_OK; + return ret; } -static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) +static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_channel_group *cg) { struct sr_usb_dev_inst *usb; char str[128]; + (void)cg; + switch (id) { case SR_CONF_CONN: if (!sdi || !sdi->conn) @@ -248,12 +224,15 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) return SR_OK; } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, + const struct sr_channel_group *cg) { struct dev_context *devc; gint64 now; int ret; + (void)cg; + if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -284,10 +263,11 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) return ret; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) +static int config_list(int 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: @@ -354,7 +334,6 @@ static int handle_events(int fd, int revents, void *cb_data) struct sr_dev_inst *sdi; struct timeval tv; gint64 now; - int i; (void)fd; (void)revents; @@ -369,8 +348,7 @@ static int handle_events(int fd, int revents, void *cb_data) } if (sdi->status == SR_ST_STOPPING) { - for (i = 0; devc->usbfd[i] != -1; i++) - sr_source_remove(devc->usbfd[i]); + usb_source_remove(drvc->sr_ctx); dev_close(sdi); @@ -389,10 +367,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct drv_context *drvc = di->priv; - const struct libusb_pollfd **pfd; struct sr_usb_dev_inst *usb; struct libusb_transfer *transfer; - int ret, i; + int ret; unsigned char *buf; if (sdi->status != SR_ST_ACTIVE) @@ -410,15 +387,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); - pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; pfd[i]; i++) { - /* Handle USB events every 100ms, for decent latency. */ - sr_source_add(pfd[i]->fd, pfd[i]->events, 100, - handle_events, (void *)sdi); - /* We'll need to remove this fd later. */ - devc->usbfd[i] = pfd[i]->fd; - } - devc->usbfd[i] = -1; + usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi); buf = g_try_malloc(DMM_DATA_SIZE); transfer = libusb_alloc_transfer(0); @@ -466,7 +435,7 @@ SR_PRIV struct sr_dev_driver victor_dmm_driver_info = { .cleanup = cleanup, .scan = scan, .dev_list = dev_list, - .dev_clear = clear_instances, + .dev_clear = NULL, .config_get = config_get, .config_set = config_set, .config_list = config_list,