OSDN Git Service

[Activity HAL] Added activity HAL source files
[android-x86/hardware-intel-libsensors.git] / gyro-calibration.c
index b6defec..179a6a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Intel Corporation.
+ * Copyright (C) 2014-2015 Intel Corporation.
  */
 
 #include <stdio.h>
 #include "common.h"
 #include "calibration.h"
 
-static void reset (struct gyro_cal* cal_data)
+
+/* Gyro defines */
+#define GYRO_MAX_ERR 0.05
+#define GYRO_DS_SIZE 100
+#define GYRO_CALIBRATION_PATH "/data/gyro.conf"
+
+
+static void reset (gyro_cal_t* cal_data)
 {
        cal_data->count = 0;
 
@@ -21,10 +28,10 @@ static void reset (struct gyro_cal* cal_data)
 }
 
 
-void gyro_cal_init (struct sensor_info_t* info)
+void gyro_cal_init (sensor_info_t* info)
 {
        int ret;
-       struct gyro_cal* cal_data = (struct gyro_cal*) info->cal_data;
+       gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
        FILE* data_file;
 
        info->cal_level = 0;
@@ -40,13 +47,17 @@ void gyro_cal_init (struct sensor_info_t* info)
 
        ret = fscanf(data_file, "%f %f %f",
                        &cal_data->bias_x, &cal_data->bias_y, &cal_data->bias_z);
+       if (ret != 3)
+               ALOGE("Gyro calibration - init failed!\n");
+
        fclose(data_file);
 }
 
-void gyro_store_data (struct sensor_info_t* info)
+
+void gyro_store_data (sensor_info_t* info)
 {
        int ret;
-       struct gyro_cal* cal_data = (struct gyro_cal*) info->cal_data;
+       gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
        FILE* data_file;
 
        if (cal_data == NULL)
@@ -67,7 +78,7 @@ void gyro_store_data (struct sensor_info_t* info)
 }
 
 
-static int gyro_collect (float x, float y, float z, struct gyro_cal* cal_data)
+static int gyro_collect (float x, float y, float z, gyro_cal_t* cal_data)
 {
        /* Analyze gyroscope data */
 
@@ -117,9 +128,10 @@ static int gyro_collect (float x, float y, float z, struct gyro_cal* cal_data)
        return 1; /* Calibrated! */
 }
 
-void calibrate_gyro(struct sensors_event_t* event, struct sensor_info_t* info)
+
+void calibrate_gyro (sensors_event_t* event, sensor_info_t* info)
 {
-       struct gyro_cal* cal_data = (struct gyro_cal*) info->cal_data;
+       gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
 
        if (cal_data == NULL)
                return;
@@ -129,25 +141,11 @@ void calibrate_gyro(struct sensors_event_t* event, struct sensor_info_t* info)
                info->cal_level = gyro_collect(event->data[0], event->data[1],
                                               event->data[2], cal_data);
 
+
+       event->data[0] = event->data[0] - cal_data->bias_x;
+       event->data[1] = event->data[1] - cal_data->bias_y;
+       event->data[2] = event->data[2] - cal_data->bias_z;
+
        if (info->cal_level)
-               event->gyro.status = SENSOR_STATUS_ACCURACY_HIGH;
-
-       switch (event->type) {
-               case SENSOR_TYPE_GYROSCOPE:
-                       /* For the gyroscope apply the bias */
-                       event->data[0] = event->data[0] - cal_data->bias_x;
-                       event->data[1] = event->data[1] - cal_data->bias_y;
-                       event->data[2] = event->data[2] - cal_data->bias_z;
-                       break;
-
-               case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
-                       /*
-                        * For the uncalibrated gyroscope don't apply the bias,
-                        * but tell he Android framework what we think it is.
-                        */
-                       event->uncalibrated_gyro.bias[0] = cal_data->bias_x;
-                       event->uncalibrated_gyro.bias[1] = cal_data->bias_y;
-                       event->uncalibrated_gyro.bias[2] = cal_data->bias_z;
-                       break;
-       }
+              event->gyro.status = SENSOR_STATUS_ACCURACY_HIGH;
 }