OSDN Git Service

GMINL-2659: Keep recent events history for fusion-like processing
[android-x86/hardware-intel-libsensors.git] / transform.c
index dc78588..a49300d 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:
@@ -324,6 +335,9 @@ static int finalize_sample_default (int s, struct sensors_event_t* data)
                        break;
        }
 
+       /* Add this event to our global records, for filtering purposes */
+       record_sample(s, data);
+
        return 1; /* Return sample to Android */
 }
 
@@ -362,6 +376,9 @@ static int finalize_sample_ISH (int s, struct sensors_event_t* data)
                data->data[2] = -roll;
        }
 
+       /* Add this event to our global records, for filtering purposes */
+       record_sample(s, data);
+
        return 1; /* Return sample to Android */
 }