X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Frdtech-um%2Fapi.c;h=363dfe55c53bf63907d4a3bdd24ddf076da5dc7b;hb=b3df76683179cbb9559e1cad8efe0d10c02dacce;hp=768596a647679325c443ec4ce06f420d8ff550be;hpb=8ff25aa9b285edca280b2abc95382a8a5ba785d6;p=libsigrok.git diff --git a/src/hardware/rdtech-um/api.c b/src/hardware/rdtech-um/api.c index 768596a6..363dfe55 100644 --- a/src/hardware/rdtech-um/api.c +++ b/src/hardware/rdtech-um/api.c @@ -55,7 +55,9 @@ static GSList *rdtech_um_scan(struct sr_dev_driver *di, struct dev_context *devc; struct sr_dev_inst *sdi; size_t ch_idx; - const char *name; + const struct rdtech_um_channel_desc *pch; + struct sr_channel *ch; + struct feed_queue_analog *feed; serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) @@ -80,8 +82,16 @@ static GSList *rdtech_um_scan(struct sr_dev_driver *di, sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; - for (ch_idx = 0; (name = p->channels[ch_idx].name); ch_idx++) - sr_channel_new(sdi, ch_idx, SR_CHANNEL_ANALOG, TRUE, name); + devc->feeds = g_malloc0(p->channel_count * sizeof(devc->feeds[0])); + for (ch_idx = 0; ch_idx < p->channel_count; ch_idx++) { + pch = &p->channels[ch_idx]; + ch = sr_channel_new(sdi, ch_idx, + SR_CHANNEL_ANALOG, TRUE, pch->name); + feed = feed_queue_analog_alloc(sdi, 1, pch->digits, ch); + feed_queue_analog_mq_unit(feed, pch->mq, 0, pch->unit); + feed_queue_analog_scale_offset(feed, &pch->scale, NULL); + devc->feeds[ch_idx] = feed; + } devices = g_slist_append(NULL, sdi); serial_close(serial); @@ -98,6 +108,27 @@ err_out: return NULL; } +static void clear_helper(struct dev_context *devc) +{ + const struct rdtech_um_profile *p; + size_t ch_idx; + + if (!devc) + return; + + p = devc->profile; + if (p && devc->feeds) { + for (ch_idx = 0; ch_idx < p->channel_count; ch_idx++) + feed_queue_analog_free(devc->feeds[ch_idx]); + g_free(devc->feeds); + } +} + +static int dev_clear(const struct sr_dev_driver *di) +{ + return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper); +} + static GSList *scan(struct sr_dev_driver *di, GSList *options) { const char *conn; @@ -154,7 +185,7 @@ static struct sr_dev_driver rdtech_um_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, - .dev_clear = std_dev_clear, + .dev_clear = dev_clear, .config_get = NULL, .config_set = config_set, .config_list = config_list,