OSDN Git Service

Collect a minimum number of events for filtering for noisy sensors
authorAdriana Reus <adriana.reus@intel.com>
Wed, 22 Oct 2014 12:13:51 +0000 (15:13 +0300)
committerAdriana Reus <adriana.reus@intel.com>
Mon, 27 Oct 2014 08:51:27 +0000 (10:51 +0200)
This is to make sure we have at least a couple of events for
the filtering queue and to make sure we are not sensing events
that can affect the overall mean or standard deviation.

Change-Id: If359915e7281a553758eb79ec10ea0559f9490f8
Signed-off-by: Adriana Reus <adriana.reus@intel.com>
Reviewed-on: https://android.intel.com:443/291953

common.h
enumeration.c
transform.c

index 02b9a83..48e2124 100644 (file)
--- a/common.h
+++ b/common.h
@@ -33,6 +33,8 @@
 
 #define MAX_NAME_SIZE          32
 
+#define MIN_SAMPLES 5
+
 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
 #define REPORTING_MODE(x)      ((x) & 0x06)
 
@@ -213,6 +215,13 @@ struct sensor_info_t
        int history_size;       /* Number of recorded samples                 */
        int history_entries;    /* How many of these are initialized          */
        int history_index;      /* Index of sample to evict next time         */
+
+       /*
+        * Event counter - will be used to check if we have a significant sample
+        * for noisy sensors. We want to make sure we do not send any wrong
+        * events before filtering kicks in. We can also use it for statistics.
+        */
+       uint64_t event_count;
 };
 
 /* Reference a few commonly used variables... */
index f5de40c..d9f93c0 100644 (file)
@@ -377,6 +377,7 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        sensor_info[s].acquisition_thread = -1;
 
        sensor_info[s].meta_data_pending = 0;
+       sensor_info[s].event_count = 0;
 
        /* Check if we have a special ordering property on this sensor */
        if (sensor_get_order(s, sensor_info[s].order))
index dc78588..97837f7 100644 (file)
@@ -267,6 +267,7 @@ static int finalize_sample_default (int s, struct sensors_event_t* data)
        if (sensor_info[s].quirks & QUIRK_FIELD_ORDERING)
                reorder_fields(data->data, sensor_info[s].order);
 
+       sensor_info[s].event_count++;
        switch (sensor_info[s].type) {
                case SENSOR_TYPE_ACCELEROMETER:
                        /* Always consider the accelerometer accurate */
@@ -300,8 +301,18 @@ static int finalize_sample_default (int s, struct sensors_event_t* data)
                                sensor_info[s].motion_trigger_name)
                                        calibrate_gyro(data, &sensor_info[s]);
 
-                       if (sensor_info[s].quirks & QUIRK_NOISY)
+                       /* For noisy sensors we'll drop a very few number
+                        * of samples to make sure we have at least MIN_SAMPLES events
+                        * in the filtering queue. This is to make sure we are not sending
+                        * events that can disturb our mean or stddev.
+                        */
+                       if (sensor_info[s].quirks & QUIRK_NOISY) {
                                denoise_median(&sensor_info[s], data, 3);
+                               if((sensor_info[s].selected_trigger !=
+                                       sensor_info[s].motion_trigger_name) &&
+                                       sensor_info[s].event_count < MIN_SAMPLES)
+                                               return 0;
+                       }
                        break;
 
                case SENSOR_TYPE_LIGHT: