]> sigrok.org Git - libsigrok.git/commitdiff
serial-lcr: add support for chip specific channel names
authorGerhard Sittig <redacted>
Mon, 17 Jun 2019 20:51:36 +0000 (22:51 +0200)
committerGerhard Sittig <redacted>
Thu, 20 Jun 2019 14:45:36 +0000 (16:45 +0200)
Allow LCR chip drivers to specify custom printf() formats for their
channel names. Default to "P1" etc in the absence of format specs.
This implementation is similar to serial-dmm.

src/hardware/serial-lcr/api.c
src/hardware/serial-lcr/protocol.h

index 002fb5bf3293db1142e206fbdee6aa366d745d87..5bf5f1840fec14715bfcf21b1a4c2b7494315fe3 100644 (file)
@@ -98,6 +98,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        size_t ch_idx;
+       const char **ch_fmts;
+       const char *fmt;
        char ch_name[8];
 
        lcr = (struct lcr_info *)di;
@@ -163,8 +165,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        sdi->priv = devc;
        devc->lcr_info = lcr;
        sr_sw_limits_init(&devc->limits);
+       ch_fmts = lcr->channel_formats;
        for (ch_idx = 0; ch_idx < lcr->channel_count; ch_idx++) {
-               snprintf(ch_name, sizeof(ch_name), "P%zu", ch_idx + 1);
+               fmt = (ch_fmts && ch_fmts[ch_idx]) ? ch_fmts[ch_idx] : "P%zu";
+               snprintf(ch_name, sizeof(ch_name), fmt, ch_idx + 1);
                sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, ch_name);
        }
        devices = g_slist_append(devices, sdi);
@@ -323,7 +327,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                        .dev_acquisition_stop = std_serial_dev_acquisition_stop, \
                        .context = NULL, \
                }, \
-               vendor, model, ES51919_CHANNEL_COUNT, \
+               vendor, model, ES51919_CHANNEL_COUNT, NULL, \
                ES51919_COMM_PARAM, ES51919_PACKET_SIZE, \
                es51919_packet_valid, es51919_packet_parse, \
                NULL, NULL, es51919_config_list, \
index 8e11733c423e4ae44d8f37afbc26a57b9ac17a8c..292a10eae7dafcb1047818d8cb5cec49a798768d 100644 (file)
@@ -33,6 +33,7 @@ struct lcr_info {
        const char *vendor;
        const char *model;
        size_t channel_count;
+       const char **channel_formats;
        const char *comm;
        size_t packet_size;
        gboolean (*packet_valid)(const uint8_t *pkt);