From: Sven Schnelle Date: Sat, 11 Feb 2017 19:16:59 +0000 (+0100) Subject: Fix analog output display X-Git-Tag: libsigrok-0.5.0~120 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6ca578feb8a0b5b0cc689c97dd1307935bf0a817;p=libsigrok.git Fix analog output display 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 --- diff --git a/src/output/analog.c b/src/output/analog.c index 9ff77da4..cd1764b8 100644 --- a/src/output/analog.c +++ b/src/output/analog.c @@ -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, " ");