From: Aurelien Jacobs Date: Mon, 20 Jun 2016 20:58:12 +0000 (+0200) Subject: analog: add support for negative number of digits X-Git-Tag: libsigrok-0.5.0~297 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=28c95cc6c45ede9ec9d184d606bfc16505834429;p=libsigrok.git analog: add support for negative number of digits When a meter display 105.2 kΩ, libsigrok will return 105200 Ω but it is really valuable to know that the last 2 digits are not significant, so encoding.digits should be set to -2. This would allow a sigrok client to display 105200 as 105.2 k instead of 105.200 k. --- diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h index 511ab28c..7d9260ed 100644 --- a/include/libsigrok/libsigrok.h +++ b/include/libsigrok/libsigrok.h @@ -508,7 +508,7 @@ struct sr_analog_encoding { gboolean is_signed; gboolean is_float; gboolean is_bigendian; - uint8_t digits; + int8_t digits; gboolean is_digits_decimal; struct sr_rational scale; struct sr_rational offset; @@ -522,7 +522,7 @@ struct sr_analog_meaning { }; struct sr_analog_spec { - uint8_t spec_digits; + int8_t spec_digits; }; /** Generic option struct used by various subsystems. */ diff --git a/src/output/analog.c b/src/output/analog.c index 99daf3ac..5f77a59c 100644 --- a/src/output/analog.c +++ b/src/output/analog.c @@ -118,7 +118,7 @@ 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++) { ch = l->data; g_string_append_printf(*out, "%s: ", ch->name); - number = g_strdup_printf("%.*f", digits, + number = g_strdup_printf("%.*f", MAX(digits, 0), fdata[i * num_channels + c]); g_string_append(*out, number); g_free(number);