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.
This commit is contained in:
Aurelien Jacobs 2016-06-20 22:58:12 +02:00
parent 4d6d660b83
commit 28c95cc6c4
2 changed files with 3 additions and 3 deletions

View File

@ -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. */

View File

@ -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);