From 89dc581796527f6860fea124c65e174b205f8a51 Mon Sep 17 00:00:00 2001 From: Patrick Porlan Date: Wed, 12 Nov 2014 15:02:07 +0100 Subject: [PATCH] GMINL-3234: Allow for a minimal sensor sampling rate The magnetometer is used at 5 Hz by default, which makes calibration and filtering operate less than optimally. Allow for a minimum sampling rate specifier, though the min_freq optional parameter. Change-Id: I7fbb894c72f72cca17d2609454e70f5f8c7874e7 Signed-off-by: Patrick Porlan --- description.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/description.c b/description.c index ea2ece9..dbba158 100644 --- a/description.c +++ b/description.c @@ -212,7 +212,25 @@ float sensor_get_max_range (int s) } } -float sensor_get_max_freq (int s) +static float sensor_get_min_freq (int s) +{ + /* + * Check if a low cap has been specified for this sensor sampling rate. + * In some case, even when the driver supports lower rate, we still + * wish to receive a certain number of samples per seconds for various + * reasons (calibration, filtering, no change in power consumption...). + */ + + float min_freq; + + if (!sensor_get_fl_prop(s, "min_freq", &min_freq)) + return min_freq; + + return 0; +} + + +static float sensor_get_max_freq (int s) { float max_freq; @@ -428,6 +446,7 @@ max_delay_t sensor_get_max_delay (int s) char freqs_buf[100]; char* cursor; float min_supported_rate = 1000; + float rate_cap; float sr; /* continuous, on-change: maximum sampling period allowed in microseconds. @@ -465,6 +484,12 @@ max_delay_t sensor_get_max_delay (int s) } } + /* Check if a minimum rate was specified for this sensor */ + rate_cap = sensor_get_min_freq(s); + + if (min_supported_rate < rate_cap) + min_supported_rate = rate_cap; + /* return 0 for wrong values */ if (min_supported_rate < 0.1) return 0; -- 2.11.0