X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fanalog.c;h=10c4c1c7ac25ff145dbab628d14135e2a33753a2;hb=81b3ce374c3b6d48e5ed321ac7a871ce4248a0bb;hp=fba7830f22972151f4f616f4dcea81e9e8ae05f8;hpb=a24da9a81358644265465325d12579cd8aa34ba5;p=libsigrok.git diff --git a/src/analog.c b/src/analog.c index fba7830f..10c4c1c7 100644 --- a/src/analog.c +++ b/src/analog.c @@ -24,7 +24,23 @@ #include "libsigrok.h" #include "libsigrok-internal.h" +/** @cond PRIVATE */ #define LOG_PREFIX "analog" +/** @endcond */ + +/** + * @file + * + * Handling and converting analog data. + */ + +/** + * @defgroup grp_analog Analog data handling + * + * Handling and converting analog data. + * + * @{ + */ struct unit_mq_string { uint64_t value; @@ -180,11 +196,11 @@ SR_API int sr_analog_float_to_string(float value, int digits, char **result) /* This produces at least one too many digits */ *result = g_strdup_printf("%.*f", digits, value); - for (i = 0, cnt = 0; *result[i]; i++) { - if (isdigit(*result[i++])) + for (i = 0, cnt = 0; (*result)[i]; i++) { + if (isdigit((*result)[i++])) cnt++; if (cnt == digits) { - *result[i] = 0; + (*result)[i] = 0; break; } } @@ -229,3 +245,16 @@ SR_API int sr_analog_unit_to_string(const struct sr_datafeed_analog2 *analog, return SR_OK; } +/* + * Set sr_rational r to the given value. + * + * @param p Numerator + * @param q Denominator + */ +SR_API void sr_rational_set(struct sr_rational *r, uint64_t p, uint64_t q) +{ + r->p = p; + r->q = q; +} + +/** @} */