From: Aurelien Jacobs Date: Wed, 24 Aug 2016 23:08:29 +0000 (+0200) Subject: gwinstek-gds-800: properly set encoding digits X-Git-Tag: libsigrok-0.5.0~237 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=6c1c13cdcdee4e5566bc0c2ef0ba9a1f59d2c846 gwinstek-gds-800: properly set encoding digits --- 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;