OSDN Git Service

Correct timestamps read from the timestamp iio channel
[android-x86/hardware-intel-libsensors.git] / description.c
index 22dff3c..a009a34 100644 (file)
@@ -168,7 +168,7 @@ char* sensor_get_vendor (int s)
 }
 
 
-int sensor_get_version (int s)
+int sensor_get_version (__attribute__((unused)) int s)
 {
        return IIO_SENSOR_HAL_VERSION;
 }
@@ -212,6 +212,42 @@ float sensor_get_max_range (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;
+
+       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)
 {
@@ -410,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.
@@ -447,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;
@@ -497,7 +540,7 @@ int32_t sensor_get_min_delay(int s)
                        /* 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 */