From 6c1c13cdcdee4e5566bc0c2ef0ba9a1f59d2c846 Mon Sep 17 00:00:00 2001 From: Aurelien Jacobs Date: Thu, 25 Aug 2016 01:08:29 +0200 Subject: [PATCH] gwinstek-gds-800: properly set encoding digits --- src/hardware/gwinstek-gds-800/protocol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/hardware/gwinstek-gds-800/protocol.c b/src/hardware/gwinstek-gds-800/protocol.c index 482d4604..723b4212 100644 --- a/src/hardware/gwinstek-gds-800/protocol.c +++ b/src/hardware/gwinstek-gds-800/protocol.c @@ -18,6 +18,7 @@ */ #include "protocol.h" +#include #include #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;