OSDN Git Service

Merge remote-tracking branch 'origin/abt/topic/gmin/l-dev/sensors/master' into gmin...
[android-x86/hardware-intel-libsensors.git] / description.c
index 4fb5a96..dbba158 100644 (file)
@@ -176,9 +176,6 @@ int sensor_get_version (int s)
 
 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;
@@ -187,10 +184,7 @@ float sensor_get_max_range (int s)
 
        /* 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;
 
@@ -218,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)
 {
@@ -264,11 +294,10 @@ uint32_t sensor_get_quirks (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"))
@@ -304,15 +333,9 @@ int sensor_get_order (int s, unsigned char map[MAX_CHANNELS])
        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;
 
@@ -353,14 +376,9 @@ char* sensor_get_string_type(int s)
 
 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:
@@ -389,12 +407,9 @@ flag_t sensor_get_flags (int s)
        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:
@@ -431,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.
@@ -468,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;
@@ -518,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 */