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 <svens@stackframe.org>
This commit is contained in:
Sven Schnelle 2017-02-11 20:16:59 +01:00
parent 471ac344a5
commit 6ca578feb8
1 changed files with 4 additions and 3 deletions

View File

@ -79,7 +79,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
GSList *l; GSList *l;
float *fdata; float *fdata;
unsigned int i; unsigned int i;
int num_channels, c, ret, digits; int num_channels, c, ret, digits, actual_digits;
char *number, *suffix; char *number, *suffix;
*out = NULL; *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++) { for (l = analog->meaning->channels, c = 0; l; l = l->next, c++) {
float value = fdata[i * num_channels + c]; float value = fdata[i * num_channels + c];
const char *prefix = ""; const char *prefix = "";
actual_digits = digits;
if (si_friendly) if (si_friendly)
prefix = sr_analog_si_prefix(&value, &digits); prefix = sr_analog_si_prefix(&value, &actual_digits);
ch = l->data; ch = l->data;
g_string_append_printf(*out, "%s: ", ch->name); 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_string_append(*out, number);
g_free(number); g_free(number);
g_string_append(*out, " "); g_string_append(*out, " ");