From: Andreas Sandberg Date: Thu, 3 Oct 2024 16:40:12 +0000 (+0100) Subject: fluke-dmm: Remove device-specific float precision helper X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4a6d039c38f8dbef912a21d403e085131942df78;p=libsigrok.git fluke-dmm: Remove device-specific float precision helper The Fluke DMM driver has a helper function that determines the precision of a float. This functionality is now provided by strutil. Signed-off-by: Andreas Sandberg --- diff --git a/src/hardware/fluke-dmm/protocol.c b/src/hardware/fluke-dmm/protocol.c index 848374a4..5683ffea 100644 --- a/src/hardware/fluke-dmm/protocol.c +++ b/src/hardware/fluke-dmm/protocol.c @@ -26,28 +26,6 @@ #include "libsigrok-internal.h" #include "protocol.h" -static int count_digits(const char *str) -{ - int digits; - - if (*str == '-' || *str == '+') - str++; - - while (*str >= '0' && *str <= '9') - str++; - - digits = 0; - if (*str == '.') { - str++; - while (*str >= '0' && *str <= '9') { - str++; - digits++; - } - } - - return digits; -} - static void handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens) { struct dev_context *devc; @@ -84,12 +62,11 @@ static void handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens) while (*e && *e != ' ') e++; *e++ = '\0'; - if (sr_atof_ascii(tokens[1], &fvalue) != SR_OK) { + if (sr_atof_ascii_digits(tokens[1], &fvalue, &digits) != SR_OK) { /* Happens all the time, when switching modes. */ sr_dbg("Invalid float: '%s'", tokens[1]); return; } - digits = count_digits(tokens[1]); } while (*e && *e == ' ') e++; @@ -312,11 +289,11 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens) * is rather problematic, we'll cut through this here. */ fvalue = NAN; } else { - if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK || fvalue == 0.0) { + if (sr_atof_ascii_digits(tokens[0], &fvalue, &digits) != SR_OK || + fvalue == 0.0) { sr_err("Invalid float '%s'.", tokens[0]); return; } - digits = count_digits(tokens[0]); } devc = sdi->priv;