]> sigrok.org Git - libsigrok.git/blobdiff - src/analog.c
ols: Make constant names more precise, clarify comment
[libsigrok.git] / src / analog.c
index 9b2977e9b5d4948696c96afa16ce360d7d330fd0..2a8e8d9054cfdd8bc691bb2e5e95534a0c50c0c7 100644 (file)
@@ -88,6 +88,9 @@ static struct unit_mq_string unit_strings[] = {
        { SR_UNIT_MOMME, "momme" },
        { SR_UNIT_TOLA, "tola" },
        { SR_UNIT_PIECE, "pcs" },
+       { SR_UNIT_JOULE, "J" },
+       { SR_UNIT_COULOMB, "C" },
+       { SR_UNIT_AMPERE_HOUR, "Ah" },
        ALL_ZERO
 };
 
@@ -174,7 +177,7 @@ SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
 SR_API int sr_analog_to_float(const struct sr_datafeed_analog *analog,
                float *outbuf)
 {
-       unsigned int b, i, count;
+       unsigned int b, count;
        gboolean bigendian;
 
        if (!analog || !(analog->data) || !(analog->meaning)
@@ -274,7 +277,7 @@ SR_API int sr_analog_to_float(const struct sr_datafeed_analog *analog,
                /* The data is already in the right format. */
                memcpy(outbuf, analog->data, count * sizeof(float));
        } else {
-               for (i = 0; i < count; i += analog->encoding->unitsize) {
+               for (unsigned int i = 0; i < count; i += analog->encoding->unitsize) {
                        for (b = 0; b < analog->encoding->unitsize; b++) {
                                if (analog->encoding->is_bigendian == bigendian)
                                        ((uint8_t *)outbuf)[i + b] =
@@ -365,12 +368,9 @@ SR_API gboolean sr_analog_si_prefix_friendly(enum sr_unit unit)
 
        for (i = 0; i < ARRAY_SIZE(prefix_friendly_units); i++)
                if (unit == prefix_friendly_units[i])
-                       break;
-
-       if (unit != prefix_friendly_units[i])
-               return FALSE;
+                       return TRUE;
 
-       return TRUE;
+       return FALSE;
 }
 
 /**
@@ -605,9 +605,8 @@ SR_API int sr_rational_mult(struct sr_rational *res, const struct sr_rational *a
  * @param[out] res Result.
  *
  * @retval SR_OK Success.
- * @retval SR_ERR_ARG Division by zero.
- * @retval SR_ERR_ARG Denominator of divisor too large.
- * @retval SR_ERR_ARG Resulting value too large.
+ * @retval SR_ERR_ARG Division by zero, denominator of divisor too large,
+ *                    or resulting value too large.
  *
  * @since 0.5.0
  */