From: Frank Stettner Date: Fri, 23 Dec 2022 14:03:13 +0000 (+0100) Subject: dmm/mm38xr: fix values for digits properties X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e59dd45dcda4d3bc0fbd944872564fd30253f3c6;p=libsigrok.git dmm/mm38xr: fix values for digits properties Unify the mm38xr package parser with the other drivers regarding the use of the digits properties in the analog payload. This commit adjusts the previously unclear, but now clarified, use of these properties: Number of significant digits after the decimal point, if positive. When negative, exponent with reversed polarity that is necessary to express the value with all digits without a decimal point. --- diff --git a/src/dmm/mm38xr.c b/src/dmm/mm38xr.c index 1e4ecd5a..8f51adda 100644 --- a/src/dmm/mm38xr.c +++ b/src/dmm/mm38xr.c @@ -341,7 +341,6 @@ SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval, struct sr_datafeed_analog *analog, void *info) { gboolean is_overload, is_bad_jack; - int exponent; int digits; struct meterman_info mi; @@ -350,6 +349,8 @@ SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval, if (meterman_38xr_decode(buf, &mi) != SR_OK) return SR_ERR; + digits = 0; + if (mi.meas_mode != MEAS_MODE_CONTINUITY) { is_overload = mi.reading == METERMAN_DIGITS_OVERLOAD; is_bad_jack = mi.reading == METERMAN_DIGITS_BAD_INPUT_JACK; @@ -440,18 +441,17 @@ SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval, if (mi.rflag_h == 0x0a || mi.peakstatus == 0x0b) analog->meaning->mqflags |= SR_MQFLAG_AUTORANGE; if (mi.meas_mode != MEAS_MODE_CONTINUITY) { - digits = decimal_digits[mi.meas_mode][mi.rangecode]; - exponent = units_exponents[mi.meas_mode][mi.rangecode]; + digits = units_exponents[mi.meas_mode][mi.rangecode] - + decimal_digits[mi.meas_mode][mi.rangecode]; *floatval = mi.reading; if (meterman_38xr_is_negative(&mi)) { *floatval *= -1.0f; } - *floatval *= powf(10, -digits); - *floatval *= powf(10, exponent); + *floatval *= powf(10, digits); } - analog->encoding->digits = 4; - analog->spec->spec_digits = 4; + analog->encoding->digits = -digits; + analog->spec->spec_digits = -digits; return SR_OK; }