]> sigrok.org Git - libsigrok.git/blobdiff - src/input/feed_queue.c
feed_queue: rename routines for submission of a single sample value
[libsigrok.git] / src / input / feed_queue.c
index 98443244a235281f9cb422ed800b8a067995e572..4e01313dec0a33e26ddcf1b829656af56ce7e84f 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;
@@ -56,14 +57,14 @@ SR_API struct feed_queue_logic *feed_queue_logic_alloc(struct sr_dev_inst *sdi,
        return q;
 }
 
-SR_API int feed_queue_logic_submit(struct feed_queue_logic *q,
-       const uint8_t *data, size_t count)
+SR_API int feed_queue_logic_submit_one(struct feed_queue_logic *q,
+       const uint8_t *data, size_t repeat_count)
 {
        uint8_t *wrptr;
        int ret;
 
        wrptr = &q->data_bytes[q->fill_count * q->unit_size];
-       while (count--) {
+       while (repeat_count--) {
                memcpy(wrptr, data, q->unit_size);
                wrptr += q->unit_size;
                q->fill_count++;
@@ -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;
@@ -118,7 +134,8 @@ struct feed_queue_analog {
        GSList *channels;
 };
 
-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,12 +162,51 @@ SR_API struct feed_queue_analog *feed_queue_analog_alloc(struct sr_dev_inst *sdi
        return q;
 }
 
-SR_API int feed_queue_analog_submit(struct feed_queue_analog *q,
-       float data, size_t count)
+SR_API int feed_queue_analog_mq_unit(struct feed_queue_analog *q,
+       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->meaning.mq = mq;
+       q->meaning.mqflags = mq_flag;
+       q->meaning.unit = unit;
+
+       return SR_OK;
+}
+
+SR_API int feed_queue_analog_scale_offset(struct feed_queue_analog *q,
+       const struct sr_rational *scale, const struct sr_rational *offset)
+{
+       int ret;
+
+       if (!q)
+               return SR_ERR_ARG;
+
+       ret = feed_queue_analog_flush(q);
+       if (ret != SR_OK)
+               return ret;
+
+       if (scale)
+               q->encoding.scale = *scale;
+       if (offset)
+               q->encoding.offset = *offset;
+
+       return SR_OK;
+}
+
+SR_API int feed_queue_analog_submit_one(struct feed_queue_analog *q,
+       float data, size_t repeat_count)
 {
        int ret;
 
-       while (count--) {
+       while (repeat_count--) {
                q->data_values[q->fill_count++] = data;
                if (q->fill_count == q->alloc_count) {
                        ret = feed_queue_analog_flush(q);