From: Gerhard Sittig Date: Wed, 15 Mar 2023 22:43:42 +0000 (+0100) Subject: feed queue: add scale/offset support, rename MQ/unit routine X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cc8b162f0c7f8e59208b36b4b0d3580d11ba9c0e;p=libsigrok.git feed queue: add scale/offset support, rename MQ/unit routine Use the scale and offset support for analog measurement values which is part of the existing sr_analog_encoding API. Rename the routine which configures MQ and unit before submission of analog data. This drops local redundant scaling support. And brings feed queue on par with the binary helpers implementation. --- diff --git a/src/input/feed_queue.c b/src/input/feed_queue.c index 5914127b..1647d8b0 100644 --- a/src/input/feed_queue.c +++ b/src/input/feed_queue.c @@ -132,7 +132,6 @@ 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( @@ -163,8 +162,7 @@ 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, +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; @@ -176,10 +174,6 @@ SR_API int feed_queue_analog_params(struct feed_queue_analog *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 = mq_flag; q->meaning.unit = unit; @@ -187,13 +181,31 @@ SR_API int feed_queue_analog_params(struct feed_queue_analog *q, 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(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 61540ad1..22ef892b 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -2776,9 +2776,10 @@ 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, +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); +SR_API int feed_queue_analog_scale_offset(struct feed_queue_analog *q, + const struct sr_rational *scale, const struct sr_rational *offset); 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);