]> sigrok.org Git - libsigrok.git/blobdiff - src/input/wav.c
hantek-4032l: Minor cosmetic fix.
[libsigrok.git] / src / input / wav.c
index 8ec3141ec9cf02ec1547052533238f7155f52386..b11dcc4860d5a54aae1e0259ada251a3e7741459 100644 (file)
@@ -51,6 +51,7 @@ struct context {
        int num_channels;
        int unitsize;
        gboolean found_data;
+       gboolean create_channels;
 };
 
 static int parse_wav_header(GString *buf, struct context *inc)
@@ -124,7 +125,7 @@ static int parse_wav_header(GString *buf, struct context *inc)
        return SR_OK;
 }
 
-static int format_match(GHashTable *metadata)
+static int format_match(GHashTable *metadata, unsigned int *confidence)
 {
        GString *buf;
        int ret;
@@ -143,15 +144,22 @@ static int format_match(GHashTable *metadata)
        if ((ret = parse_wav_header(buf, NULL)) != SR_OK)
                return ret;
 
+       *confidence = 1;
+
        return SR_OK;
 }
 
 static int init(struct sr_input *in, GHashTable *options)
 {
+       struct context *inc;
+
        (void)options;
 
        in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
        in->priv = g_malloc0(sizeof(struct context));
+       inc = in->priv;
+
+       inc->create_channels = TRUE;
 
        return SR_OK;
 }
@@ -331,11 +339,15 @@ static int receive(struct sr_input *in, GString *buf)
                else if (ret != SR_OK)
                        return ret;
 
-               for (int i = 0; i < inc->num_channels; i++) {
-                       snprintf(channelname, sizeof(channelname), "CH%d", i + 1);
-                       sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname);
+               if (inc->create_channels) {
+                       for (int i = 0; i < inc->num_channels; i++) {
+                               snprintf(channelname, sizeof(channelname), "CH%d", i + 1);
+                               sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname);
+                       }
                }
 
+               inc->create_channels = FALSE;
+
                /* sdi is ready, notify frontend. */
                in->sdi_ready = TRUE;
                return SR_OK;
@@ -365,9 +377,13 @@ static int end(struct sr_input *in)
 
 static int reset(struct sr_input *in)
 {
-       struct context *inc = in->priv;
+       memset(in->priv, 0, sizeof(struct context));
+
+       /*
+        * We only want to create the sigrok channels once, so
+        * inc->create_channels won't be set to TRUE this time around.
+        */
 
-       inc->started = FALSE;
        g_string_truncate(in->buf, 0);
 
        return SR_OK;