aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Schnelle <svens@stackframe.org>2017-02-11 20:16:59 +0100
committerSven Schnelle <svens@stackframe.org>2017-02-15 08:57:04 +0100
commit6ca578feb8a0b5b0cc689c97dd1307935bf0a817 (patch)
treefe8b372c0278dcc35f6d493f0255f49b3e4bc396
parent471ac344a5885c73f58cbcd0d0c87f416926afc2 (diff)
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>
-rw-r--r--src/output/analog.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/output/analog.c b/src/output/analog.c
index 9ff77da..cd1764b 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, " ");