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:
parent
471ac344a5
commit
6ca578feb8
|
@ -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, " ");
|
||||
|
|
Loading…
Reference in New Issue