]> sigrok.org Git - libsigrok.git/commitdiff
hung-chang-dso-2100: properly set encoding digits
authorAurelien Jacobs <redacted>
Tue, 23 Aug 2016 23:18:58 +0000 (01:18 +0200)
committerUwe Hermann <redacted>
Sun, 28 Aug 2016 22:25:18 +0000 (00:25 +0200)
src/hardware/hung-chang-dso-2100/protocol.c

index 88c47e0ae811a938101570af66774eef18fe66df..cfe84f41278cefdac12dc16029b176112bd4cb37 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <config.h>
+#include <math.h>
 #include <ieee1284.h>
 #include "protocol.h"
 
@@ -344,7 +345,10 @@ static void push_samples(const struct sr_dev_inst *sdi, uint8_t *buf, size_t num
        while (num--)
                data[num] = (buf[num] - 0x80) * factor;
 
-       sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
+       float vdivlog = log10f(factor);
+       int digits = -(int)vdivlog + (vdivlog < 0.0);
+
+       sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
        analog.meaning->channels = devc->enabled_channel;
        analog.meaning->mq = SR_MQ_VOLTAGE;
        analog.meaning->unit = SR_UNIT_VOLT;