OSDN Git Service

STPK-1429 Groundwork for per sensor sampling rate
authorPatrick Porlan <patrick.porlan@intel.com>
Tue, 8 Apr 2014 12:16:14 +0000 (14:16 +0200)
committersuyyala <sridhar.uyyala@intel.com>
Mon, 28 Apr 2014 02:40:39 +0000 (19:40 -0700)
This supports sampling rate as used by the Intel Sensor Hub.
That conveniently performs the syfs read and double enable
buffer operation that the ISH sensor seem to require.

Issue: STPK-1429

Change-Id: I6e5b6419bb3dc83563849a8d65d7688b6b264bf6
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
common.h
control.c

index 3d4b855..5b3a6f7 100644 (file)
--- a/common.h
+++ b/common.h
@@ -19,6 +19,7 @@
 #define TRIGGER_PATH           BASE_PATH "trigger/current_trigger"
 #define COMMON_OFFSET_PATH     BASE_PATH "in_%s_offset"
 #define COMMON_SCALE_PATH      BASE_PATH "in_%s_scale"
+#define COMMON_SAMPLING_PATH   BASE_PATH "in_%s_sampling_frequency"
 
 #define MAX_TYPE_SPEC_LEN 32   /* Channel type spec len; ex: "le:u10/16>>0" */
 #define MAX_SENSOR_REPORT_SIZE 32      /* Sensor report buffer size */
@@ -77,6 +78,8 @@ struct sensor_info_t
        float offset;   /* (cooked = raw + offset) * scale */
        float scale;
 
+       int sampling_rate;      /* requested events / second */
+
        int dev_num;    /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
        int enable_count;
 
index f6f44df..7cf1efd 100644 (file)
--- a/control.c
+++ b/control.c
@@ -591,6 +591,7 @@ return_first_available_sensor_report:
                        ALOGV("Report on sensor %d\n", s);
                        return 1;
                }
+await_event:
 
        /* Keep a minimum time interval between poll operations */
        delta = (get_timestamp() - last_poll_exit_ts)/1000;
@@ -604,6 +605,11 @@ return_first_available_sensor_report:
 
        last_poll_exit_ts = get_timestamp();
 
+       if (nfds == -1) {
+               ALOGI("epoll_wait returned -1 (%s)\n", strerror(errno));
+               goto await_event;
+       }
+
        ALOGV("%d fds signalled\n", nfds);
 
        /* For each of the devices for which a report is available */
@@ -623,13 +629,37 @@ return_first_available_sensor_report:
 }
 
 
-int sensor_set_delay(int handle, int64_t ns)
+int sensor_set_delay(int s, int64_t ns)
 {
        /* Set the rate at which a specific sensor should report events */
-       /* Continuous reports: accelerometer, gyroscope */
-       /* On change with minimum delay between events: ALS, proximity */
-       /* See sensors.h for indication on sensor trigger modes */
-       return -1;
+
+       /* See Android sensors.h for indication on sensor trigger modes */
+
+       char sysfs_path[PATH_MAX];
+       int dev_num             =       sensor_info[s].dev_num;
+       int i                   =       sensor_info[s].catalog_index;
+       const char *prefix      =       sensor_catalog[i].tag;
+       int new_sampling_rate   =       (int) (1000000000L/ns);
+       int cur_sampling_rate;
+
+       ALOGI("sensor_set_delay: sampling rate set to %d\n", new_sampling_rate);
+
+       sprintf(sysfs_path, COMMON_SAMPLING_PATH, dev_num, prefix);
+
+       if (sysfs_read_int(sysfs_path, &cur_sampling_rate) != -1)
+               if (new_sampling_rate != cur_sampling_rate) {
+
+                       if (trig_sensors_per_dev[dev_num])
+                               enable_buffer(dev_num, 0);
+
+                       sysfs_write_int(sysfs_path, new_sampling_rate);
+
+                       if (trig_sensors_per_dev[dev_num])
+                               enable_buffer(dev_num, 1);
+       }
+
+       sensor_info[s].sampling_rate = new_sampling_rate;
+       return 0;
 }