]> sigrok.org Git - libsigrok.git/blobdiff - src/analog.c
Add filename field to sr_output and make it accessible
[libsigrok.git] / src / analog.c
index fba7830f22972151f4f616f4dcea81e9e8ae05f8..10c4c1c7ac25ff145dbab628d14135e2a33753a2 100644 (file)
 #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;
+}
+
+/** @} */