]> sigrok.org Git - libsigrok.git/blobdiff - src/input/feed_queue.c
feed queue: add scaling, MQ and unit to analog feed submission
[libsigrok.git] / src / input / feed_queue.c
index 98443244a235281f9cb422ed800b8a067995e572..ca91af3756602d7ccb50fe47de365d2eef817e8f 100644 (file)
@@ -22,7 +22,7 @@
 #include <string.h>
 
 struct feed_queue_logic {
-       struct sr_dev_inst *sdi;
+       const struct sr_dev_inst *sdi;
        size_t unit_size;
        size_t alloc_count;
        size_t fill_count;
@@ -31,7 +31,8 @@ struct feed_queue_logic {
        struct sr_datafeed_logic logic;
 };
 
-SR_API struct feed_queue_logic *feed_queue_logic_alloc(struct sr_dev_inst *sdi,
+SR_API struct feed_queue_logic *feed_queue_logic_alloc(
+       const struct sr_dev_inst *sdi,
        size_t sample_count, size_t unit_size)
 {
        struct feed_queue_logic *q;
@@ -94,6 +95,21 @@ SR_API int feed_queue_logic_flush(struct feed_queue_logic *q)
        return SR_OK;
 }
 
+SR_API int feed_queue_logic_send_trigger(struct feed_queue_logic *q)
+{
+       int ret;
+
+       ret = feed_queue_logic_flush(q);
+       if (ret != SR_OK)
+               return ret;
+
+       ret = std_session_send_df_trigger(q->sdi);
+       if (ret != SR_OK)
+               return ret;
+
+       return SR_OK;
+}
+
 SR_API void feed_queue_logic_free(struct feed_queue_logic *q)
 {
 
@@ -105,7 +121,7 @@ SR_API void feed_queue_logic_free(struct feed_queue_logic *q)
 }
 
 struct feed_queue_analog {
-       struct sr_dev_inst *sdi;
+       const struct sr_dev_inst *sdi;
        size_t alloc_count;
        size_t fill_count;
        float *data_values;
@@ -116,9 +132,11 @@ struct feed_queue_analog {
        struct sr_analog_meaning meaning;
        struct sr_analog_spec spec;
        GSList *channels;
+       float scale_factor;
 };
 
-SR_API struct feed_queue_analog *feed_queue_analog_alloc(struct sr_dev_inst *sdi,
+SR_API struct feed_queue_analog *feed_queue_analog_alloc(
+       const struct sr_dev_inst *sdi,
        size_t sample_count, int digits, struct sr_channel *ch)
 {
        struct feed_queue_analog *q;
@@ -145,11 +163,37 @@ SR_API struct feed_queue_analog *feed_queue_analog_alloc(struct sr_dev_inst *sdi
        return q;
 }
 
+SR_API int feed_queue_analog_params(struct feed_queue_analog *q,
+       float scale_factor,
+       enum sr_mq mq, enum sr_mqflag mq_flag, enum sr_unit unit)
+{
+       int ret;
+
+       if (!q)
+               return SR_ERR_ARG;
+
+       ret = feed_queue_analog_flush(q);
+       if (ret != SR_OK)
+               return ret;
+
+       q->scale_factor = scale_factor;
+       if (q->scale_factor == 1.0)
+               q->scale_factor = 0.0;
+
+       q->meaning->mq = mq;
+       q->meaning->mqflags = mqflags;
+       q->meaning->unit = unit;
+
+       return SR_OK;
+}
+
 SR_API int feed_queue_analog_submit(struct feed_queue_analog *q,
        float data, size_t count)
 {
        int ret;
 
+       if (q->scale_factor)
+               data *= q->scale_factor;
        while (count--) {
                q->data_values[q->fill_count++] = data;
                if (q->fill_count == q->alloc_count) {