]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/tondaj-sl-814/protocol.c
demo: Convert to SR_DF_ANALOG.
[libsigrok.git] / src / hardware / tondaj-sl-814 / protocol.c
index 44d12ec4f40866f61e477493d6c8974cac93ea26..4daf5af5abdd4ca3056ae478f6214c53f6a47a14 100644 (file)
@@ -69,18 +69,18 @@ static void parse_packet(const uint8_t *buf, float *floatval,
        /* The value on the display always has one digit after the comma. */
        *floatval /= 10;
 
-       analog->mq = SR_MQ_SOUND_PRESSURE_LEVEL;
-       analog->unit = SR_UNIT_DECIBEL_SPL;
+       analog->meaning->mq = SR_MQ_SOUND_PRESSURE_LEVEL;
+       analog->meaning->unit = SR_UNIT_DECIBEL_SPL;
 
        if (is_a)
-               analog->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A;
+               analog->meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A;
        else
-               analog->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C;
+               analog->meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C;
 
        if (is_fast)
-               analog->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_F;
+               analog->meaning->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_F;
        else
-               analog->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_S;
+               analog->meaning->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_S;
 
        /* TODO: How to handle level? */
        (void)level;
@@ -90,23 +90,27 @@ static void decode_packet(struct sr_dev_inst *sdi)
 {
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog analog;
+       struct sr_analog_encoding encoding;
+       struct sr_analog_meaning meaning;
+       struct sr_analog_spec spec;
        struct dev_context *devc;
        float floatval;
 
        devc = sdi->priv;
-       memset(&analog, 0, sizeof(struct sr_datafeed_analog));
+
+       sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
 
        parse_packet(devc->buf, &floatval, &analog);
 
        /* Send a sample packet with one analog value. */
-       analog.channels = sdi->channels;
+       analog.meaning->channels = sdi->channels;
        analog.num_samples = 1;
        analog.data = &floatval;
        packet.type = SR_DF_ANALOG;
        packet.payload = &analog;
-       sr_session_send(devc->cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
-       devc->num_samples++;
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
 }
 
 SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
@@ -201,11 +205,8 @@ SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
                return FALSE;
        }
 
-       /* Stop acquisition if we acquired enough samples. */
-       if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
-               sr_info("Requested number of samples reached.");
-               sdi->driver->dev_acquisition_stop(sdi, cb_data);
-       }
+       if (sr_sw_limits_check(&devc->limits))
+               sdi->driver->dev_acquisition_stop(sdi);
 
        return TRUE;
 }