]> sigrok.org Git - libsigrok.git/commitdiff
serial-dmm: introduce support for subdriver specific channel names
authorGerhard Sittig <redacted>
Sun, 30 Sep 2018 02:45:27 +0000 (04:45 +0200)
committerUwe Hermann <redacted>
Tue, 2 Oct 2018 17:01:25 +0000 (19:01 +0200)
Default to the existing "P1" etc naming scheme for analog channels of
serial-dmm subdrivers. Add support for subdriver specific channel names
(which can reference the channel number if they desire). This is useful
for devices with multiple displays, or special purpose devices where
other names than P1 can better reflect the channel's nature.

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

index 88e3b88aef6b8974208a473313b558d8cc5b53e5..c127000de6210457a14cd08adee4aa3de6dbb0a7 100644 (file)
@@ -138,8 +138,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                dmm->channel_count = 4;
        for (ch_idx = 0; ch_idx < dmm->channel_count; ch_idx++) {
                size_t ch_num;
+               const char *fmt;
+               fmt = "P%zu";
+               if (dmm->channel_formats && dmm->channel_formats[ch_idx])
+                       fmt = dmm->channel_formats[ch_idx];
                ch_num = ch_idx + 1;
-               snprintf(ch_name, sizeof(ch_name), "P%zu", ch_num);
+               snprintf(ch_name, sizeof(ch_name), fmt, ch_num);
                sr_channel_new(sdi, ch_idx, SR_CHANNEL_ANALOG, TRUE, ch_name);
        }
        devices = g_slist_append(devices, sdi);
@@ -207,7 +211,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                        .context = NULL, \
                }, \
                VENDOR, MODEL, CONN, BAUDRATE, PACKETSIZE, TIMEOUT, DELAY, \
-               REQUEST, 1, VALID, PARSE, DETAILS, sizeof(struct CHIPSET##_info) \
+               REQUEST, 1, NULL, VALID, PARSE, DETAILS, sizeof(struct CHIPSET##_info) \
        }).di
 
 SR_REGISTER_DEV_DRIVER_LIST(serial_dmm_drivers,
index 696f6b6ef314e0dfca2e7cae6777669f07f1b428..decd429d89969acd6bd50e090cbcdd48da92eca4 100644 (file)
@@ -49,6 +49,8 @@ struct dmm_info {
        int (*packet_request)(struct sr_serial_dev_inst *);
        /** Number of channels / displays. */
        size_t channel_count;
+       /** (Optional) printf formats for channel names. */
+       const char **channel_formats;
        /** Packet validation function. */
        gboolean (*packet_valid)(const uint8_t *);
        /** Packet parsing function. */