]> sigrok.org Git - libsigrok.git/commitdiff
gwinstek-gds-800: properly set encoding digits
authorAurelien Jacobs <redacted>
Wed, 24 Aug 2016 23:08:29 +0000 (01:08 +0200)
committerUwe Hermann <redacted>
Sun, 28 Aug 2016 22:25:18 +0000 (00:25 +0200)
src/hardware/gwinstek-gds-800/protocol.c

index 482d46045ec63d8c93ec253f8e2e9a28ebd8ae9e..723b421231342ad853f8f7bb9b904379f0551252 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "protocol.h"
+#include <math.h>
 #include <string.h>
 
 #define ANALOG_CHANNELS 2
@@ -235,12 +236,16 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data)
                        sr_spew("Received %d number of samples from channel "
                                "%d.", num_samples, devc->cur_acq_channel + 1);
 
+                       float vbit = volts_per_division * VERTICAL_DIVISIONS / 256.0;
+                       float vbitlog = log10f(vbit);
+                       int digits = -(int)vbitlog + (vbitlog < 0.0);
+
                        /* Convert data. */
                        for (i = 0; i < num_samples; i++)
-                               samples[i] = ((float) ((int16_t) (RB16(&devc->rcv_buffer[i*2])))) / 256. * VERTICAL_DIVISIONS * volts_per_division;
+                               samples[i] = ((float) ((int16_t) (RB16(&devc->rcv_buffer[i*2])))) * vbit;
 
                        /* Fill frame. */
-                       sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
+                       sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
                        analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, devc->cur_acq_channel));
                        analog.num_samples = num_samples;
                        analog.data = samples;