From: Gerhard Sittig Date: Sun, 5 Mar 2023 12:38:28 +0000 (+0100) Subject: feed queue: add scaling, MQ and unit to analog feed submission X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=43e6f7a7798f579c97f34f77c586a4962a41c29a;p=libsigrok.git feed queue: add scaling, MQ and unit to analog feed submission Allow for the analog data to scale during submission, and pass caller specified MQ including flags and units to the sigrok session. Using these specs is optional, default behaviour is backwards compatible. Accumulated data gets flushed before the configuration changes. This allows the migration of binary helper using drivers to feed queue. --- diff --git a/src/input/feed_queue.c b/src/input/feed_queue.c index b25fa77a..ca91af37 100644 --- a/src/input/feed_queue.c +++ b/src/input/feed_queue.c @@ -132,6 +132,7 @@ 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( @@ -162,11 +163,37 @@ SR_API struct feed_queue_analog *feed_queue_analog_alloc( 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) { diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 8adda3b7..61540ad1 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -2776,6 +2776,9 @@ SR_API void feed_queue_logic_free(struct feed_queue_logic *q); 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); +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); SR_API int feed_queue_analog_submit(struct feed_queue_analog *q, float data, size_t count); SR_API int feed_queue_analog_flush(struct feed_queue_analog *q);