X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhung-chang-dso-2100%2Fprotocol.c;h=160e5a0c63f1de492d9b45eb3b86f5c1837f51d9;hb=6c23b710ec21b6937be059aa7cb14313e929ec7c;hp=31f161e8f1dca4f03ec5cbab4acf242f6ddf24a2;hpb=695dc859c15ba4190f5c1aa2e1a6e2dc6a6e5845;p=libsigrok.git diff --git a/src/hardware/hung-chang-dso-2100/protocol.c b/src/hardware/hung-chang-dso-2100/protocol.c index 31f161e8..160e5a0c 100644 --- a/src/hardware/hung-chang-dso-2100/protocol.c +++ b/src/hardware/hung-chang-dso-2100/protocol.c @@ -18,6 +18,7 @@ */ #include +#include #include #include "protocol.h" @@ -78,11 +79,11 @@ * trigger on (rising or falling) * The next state is 0x0C * 0x0C Same as state 0x0F but expects the calibration - * value for the first channel's position + * value for the first channel's position * (POS1 in the schematics) * The next state is 0x0D * 0x0D Same as state 0x0F but expects the calibration - * value for the second channel's position + * value for the second channel's position * (POS2 in the schematics) * The next state is 0x0E * 0x0E Same as state 0x0F but expects the trigger level @@ -331,16 +332,12 @@ static void push_samples(const struct sr_dev_inst *sdi, uint8_t *buf, size_t num { struct dev_context *devc = sdi->priv; float *data = devc->samples; - struct sr_datafeed_analog_old analog = { - .channels = devc->enabled_channel, - .num_samples = num, - .mq = SR_MQ_VOLTAGE, - .unit = SR_UNIT_VOLT, - .mqflags = 0, - .data = data, - }; + struct sr_datafeed_analog analog; + struct sr_analog_encoding encoding; + struct sr_analog_meaning meaning; + struct sr_analog_spec spec; struct sr_datafeed_packet packet = { - .type = SR_DF_ANALOG_OLD, + .type = SR_DF_ANALOG, .payload = &analog, }; float factor = devc->factor; @@ -348,6 +345,17 @@ static void push_samples(const struct sr_dev_inst *sdi, uint8_t *buf, size_t num while (num--) data[num] = (buf[num] - 0x80) * factor; + 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; + analog.meaning->mqflags = 0; + analog.num_samples = num; + analog.data = data; + sr_session_send(sdi, &packet); }