]> sigrok.org Git - libsigrok.git/commitdiff
Fix analog output display
authorSven Schnelle <redacted>
Sat, 11 Feb 2017 19:16:59 +0000 (20:16 +0100)
committerSven Schnelle <redacted>
Wed, 15 Feb 2017 07:57:04 +0000 (08:57 +0100)
I've seen the following output from sigrok-cli:

CH1: 478.720 mV
CH1: -514 mV
CH1: -0 V

I added some debug, and it seems like the digits value isn't reset
to the actual value after calling sr_analog_si_prefix_friendly():

using 6 digits
value2 0.478720 digits 6
value2 -0.513536 digits 3
value2 -0.487424 digits 0

This commit fixes this by resetting the value to the actual value before.

Signed-off-by: Sven Schnelle <redacted>
src/output/analog.c

index 9ff77da4b765cf7ae7d8ea4af9b42dd66b3fdf71..cd1764b842fd7c23d0e8fd2a91e3aaf762a3160c 100644 (file)
@@ -79,7 +79,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
        GSList *l;
        float *fdata;
        unsigned int i;
-       int num_channels, c, ret, digits;
+       int num_channels, c, ret, digits, actual_digits;
        char *number, *suffix;
 
        *out = NULL;
@@ -119,11 +119,12 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
                        for (l = analog->meaning->channels, c = 0; l; l = l->next, c++) {
                                float value = fdata[i * num_channels + c];
                                const char *prefix = "";
+                               actual_digits = digits;
                                if (si_friendly)
-                                       prefix = sr_analog_si_prefix(&value, &digits);
+                                       prefix = sr_analog_si_prefix(&value, &actual_digits);
                                ch = l->data;
                                g_string_append_printf(*out, "%s: ", ch->name);
-                               number = g_strdup_printf("%.*f", MAX(digits, 0), value);
+                               number = g_strdup_printf("%.*f", MAX(actual_digits, 0), value);
                                g_string_append(*out, number);
                                g_free(number);
                                g_string_append(*out, " ");