}
-int sensor_get_version (int s)
+int sensor_get_version (__attribute__((unused)) int s)
{
return IIO_SENSOR_HAL_VERSION;
}
float sensor_get_max_range (int s)
{
- int catalog_index;
- int sensor_type;
-
if (sensor_info[s].max_range != 0.0 ||
!sensor_get_fl_prop(s, "max_range", &sensor_info[s].max_range))
return sensor_info[s].max_range;
/* We should cap returned samples accordingly... */
- catalog_index = sensor_info[s].catalog_index;
- sensor_type = sensor_catalog[catalog_index].type;
-
- switch (sensor_type) {
+ switch (sensor_info[s].type) {
case SENSOR_TYPE_ACCELEROMETER: /* m/s^2 */
return 50;
}
}
+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;
+
+ if (!sensor_get_fl_prop(s, "max_freq", &max_freq))
+ return max_freq;
+
+ return 1000;
+}
+
+int sensor_get_cal_steps (int s)
+{
+ int cal_steps;
+ if (!sensor_get_prop(s, "cal_steps", &cal_steps))
+ return cal_steps;
+
+ return 0;
+}
float sensor_get_resolution (int s)
{
if (strstr(quirks_buf, "init-rate"))
sensor_info[s].quirks |= QUIRK_INITIAL_RATE;
- if (strstr(quirks_buf, "continuous")) {
- sensor_info[s].quirks |= QUIRK_CONTINUOUS_DRIVER;
- }
+ if (strstr(quirks_buf, "continuous"))
+ sensor_info[s].quirks |= QUIRK_FORCE_CONTINUOUS;
- if (strstr(quirks_buf, "terse") && !(sensor_info[s].quirks & QUIRK_CONTINUOUS_DRIVER))
+ if (strstr(quirks_buf, "terse"))
sensor_info[s].quirks |= QUIRK_TERSE_DRIVER;
if (strstr(quirks_buf, "noisy"))
return 1; /* OK to use modified ordering map */
}
-char* sensor_get_string_type(int s)
+char* sensor_get_string_type (int s)
{
- int catalog_index;
- int sensor_type;
-
- catalog_index = sensor_info[s].catalog_index;
- sensor_type = sensor_catalog[catalog_index].type;
-
- switch (sensor_type) {
+ switch (sensor_info[s].type) {
case SENSOR_TYPE_ACCELEROMETER:
return SENSOR_STRING_TYPE_ACCELEROMETER;
flag_t sensor_get_flags (int s)
{
- int catalog_index;
- int sensor_type;
-
flag_t flags = 0x0;
- catalog_index = sensor_info[s].catalog_index;
- sensor_type = sensor_catalog[catalog_index].type;
- switch (sensor_type) {
+ switch (sensor_info[s].type) {
case SENSOR_TYPE_ACCELEROMETER:
case SENSOR_TYPE_MAGNETIC_FIELD:
case SENSOR_TYPE_ORIENTATION:
return flags;
}
-int get_cdd_freq(int s, int must)
+int get_cdd_freq (int s, int must)
{
- int catalog_index = sensor_info[s].catalog_index;
- int sensor_type = sensor_catalog[catalog_index].type;
-
- switch (sensor_type) {
+ switch (sensor_info[s].type) {
case SENSOR_TYPE_ACCELEROMETER:
return (must ? 100 : 200); /* must 100 Hz, should 200 Hz, CDD compliant */
case SENSOR_TYPE_GYROSCOPE:
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.
}
}
+ /* 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;
/* Decode a single value */
sr = strtod(cursor, NULL);
- if (sr > max_supported_rate && sr <= MAX_EVENTS)
+ if (sr > max_supported_rate && sr <= sensor_get_max_freq(s))
max_supported_rate = sr;
/* Skip digits */