OSDN Git Service

Populate minDelay field.
authorAdriana Reus <adriana.reus@intel.com>
Thu, 4 Sep 2014 10:54:01 +0000 (13:54 +0300)
committerAdriana Reus <adriana.reus@intel.com>
Tue, 9 Sep 2014 13:21:25 +0000 (16:21 +0300)
Populate minDelay field with what data we find in
'sampling_frequencies_available'.
For sensors in poll mode where we don't have a way to
request a frequency, artificially set up a limit per
CDD requirements.

Signed-off-by: Adriana Reus <adriana.reus@intel.com>
Change-Id: I962e6e352a07f42b4833a83908a4b984a3f17235

control.c
description.c
enumeration.c

index f048956..d8856c7 100644 (file)
--- a/control.c
+++ b/control.c
@@ -1049,7 +1049,8 @@ int sensor_set_delay(int s, int64_t ns)
        float cur_sampling_rate; /* Currently used sampling rate              */
        int per_sensor_sampling_rate;
        int per_device_sampling_rate;
-       float max_supported_rate = 0;
+       int32_t min_delay = sensor_desc[s].minDelay;
+       float max_supported_rate = (min_delay != 0 && min_delay != -1) ? (1000000.0f / min_delay) : 0;
        char freqs_buf[100];
        char* cursor;
        int n;
@@ -1069,6 +1070,11 @@ int sensor_set_delay(int s, int64_t ns)
        if (new_sampling_rate < 1)
                new_sampling_rate = 1;
 
+       if (max_supported_rate &&
+               new_sampling_rate > max_supported_rate) {
+               new_sampling_rate = max_supported_rate;
+       }
+
        sensor_info[s].sampling_rate = new_sampling_rate;
 
        /* If we're dealing with a poll-mode sensor */
@@ -1123,9 +1129,6 @@ int sensor_set_delay(int s, int64_t ns)
                        /* Decode a single value */
                        sr = strtod(cursor, NULL);
 
-                       if (sr > max_supported_rate)
-                               max_supported_rate = sr;
-
                        /* If this matches the selected rate, we're happy */
                        if (new_sampling_rate == sr)
                                break;
index 2c6fec0..42764ae 100644 (file)
@@ -406,3 +406,65 @@ max_delay_t sensor_get_max_delay (int s)
        /* Return microseconds */
        return (max_delay_t)(1000000.0 / min_supported_rate);
 }
+
+/* this value depends on the reporting mode:
+ *
+ *   continuous: minimum sample period allowed in microseconds
+ *   on-change : 0
+ *   one-shot  :-1
+ *   special   : 0, unless otherwise noted
+ */
+int32_t sensor_get_min_delay(int s)
+{
+       char avail_sysfs_path[PATH_MAX];
+       int dev_num     = sensor_info[s].dev_num;
+       char freqs_buf[100];
+       char* cursor;
+       float max_supported_rate = 0;
+       float sr;
+       int catalog_index = sensor_info[s].catalog_index;
+       int sensor_type = sensor_catalog[catalog_index].type;
+
+
+       sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
+
+       if (sysfs_read_str(avail_sysfs_path, freqs_buf, sizeof(freqs_buf)) < 0) {
+               /* If poll mode sensor */
+               if (!sensor_info[s].num_channels) {
+                       switch (sensor_type) {
+                               case SENSOR_TYPE_ACCELEROMETER:
+                                       max_supported_rate = 125; /* 125 Hz */
+                                       break;
+                               case SENSOR_TYPE_GYROSCOPE:
+                               case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
+                                       max_supported_rate = 200; /* 200 Hz */
+                                       break;
+                               case SENSOR_TYPE_MAGNETIC_FIELD:
+                                       max_supported_rate = 10; /* 10 Hz */
+                                       break;
+                               default:
+                                       max_supported_rate = 0;
+                       }
+               }
+       } else {
+               cursor = freqs_buf;
+               while (*cursor && cursor[0]) {
+
+                       /* Decode a single value */
+                       sr = strtod(cursor, NULL);
+
+                       if (sr > max_supported_rate)
+                               max_supported_rate = sr;
+
+                       /* Skip digits */
+                       while (cursor[0] && !isspace(cursor[0]))
+                               cursor++;
+
+                       /* Skip spaces */
+                       while (cursor[0] && isspace(cursor[0]))
+                               cursor++;
+               }
+       }
+
+       return (int32_t)(1000000.0 / max_supported_rate);
+}
index e334508..5bab337 100644 (file)
@@ -333,6 +333,7 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        sensor_desc[s].requiredPermission = "";
        sensor_desc[s].flags = sensor_get_flags(s);
        sensor_desc[s].maxDelay = sensor_get_max_delay(s);
+       sensor_desc[s].minDelay = sensor_get_min_delay(s);
 
        if (sensor_info[s].internal_name[0] == '\0') {
                /*