]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hung-chang-dso-2100/protocol.c
drivers: Consistently use same indentation for config_*() API calls.
[libsigrok.git] / src / hardware / hung-chang-dso-2100 / protocol.c
index 6f997db020389ed30d8abdaee0c05651ecc19c84..69efb14d3c332b125334490b4ebc901ed25794be 100644 (file)
@@ -17,6 +17,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
+#include <math.h>
 #include <ieee1284.h>
 #include "protocol.h"
 
  *             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
@@ -330,14 +332,10 @@ 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 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,
                .payload = &analog,
@@ -347,7 +345,18 @@ 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_session_send(devc->cb_data, &packet);
+       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);
 }
 
 static int read_subframe(const struct sr_dev_inst *sdi, uint8_t *buf)
@@ -392,7 +401,7 @@ static int read_subframe(const struct sr_dev_inst *sdi, uint8_t *buf)
                                };
 
                                push_samples(sdi, buf, 6);
-                               sr_session_send(devc->cb_data, &packet);
+                               sr_session_send(sdi, &packet);
                                buf += 6;
                                num -= 6;
                        }
@@ -411,7 +420,7 @@ static int read_subframe(const struct sr_dev_inst *sdi, uint8_t *buf)
 SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data)
 {
        struct sr_datafeed_packet packet = { .type = SR_DF_FRAME_BEGIN };
-       const struct sr_dev_inst *sdi;
+       struct sr_dev_inst *sdi;
        struct dev_context *devc;
        uint8_t state, buf[1000];
 
@@ -434,11 +443,11 @@ SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data)
                return TRUE;
 
        if (state != 0x03) {
-               sr_err("Unexpected state 0x%X while checking for trigger");
+               sr_err("Unexpected state 0x%X while checking for trigger", state);
                return FALSE;
        }
 
-       sr_session_send(devc->cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
        if (devc->channel) {
                while (read_subframe(sdi, buf)) {
@@ -452,10 +461,10 @@ SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data)
        }
 
        packet.type = SR_DF_FRAME_END;
-       sr_session_send(devc->cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
        if (++devc->frame >= devc->frame_limit)
-               hung_chang_dso_2100_dev_acquisition_stop(sdi, devc->cb_data);
+               sr_dev_acquisition_stop(sdi);
        else
                hung_chang_dso_2100_move_to(sdi, 0x21);