OSDN Git Service

Reverse the default orientation of accelerometer
[android-x86/hardware-intel-libsensors.git] / gyro-calibration.c
index d9f8183..6a2170f 100644 (file)
@@ -1,6 +1,18 @@
 /*
- * Copyright (C) 2014-2015 Intel Corporation.
- */
+// Copyright (c) 2015 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
 
 #include <stdio.h>
 #include <math.h>
@@ -29,14 +41,14 @@ static void reset (gyro_cal_t* cal_data)
 }
 
 
-void gyro_cal_init (sensor_info_t* info)
+void gyro_cal_init (int s)
 {
        int ret;
-       gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
+       gyro_cal_t* cal_data = (gyro_cal_t*) sensor[s].cal_data;
        FILE* data_file;
        float version;
 
-       info->cal_level = 0;
+       sensor[s].cal_level = 0;
 
        if (cal_data == NULL)
                return;
@@ -59,10 +71,10 @@ void gyro_cal_init (sensor_info_t* info)
 }
 
 
-void gyro_store_data (sensor_info_t* info)
+void gyro_store_data (int s)
 {
        int ret;
-       gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
+       gyro_cal_t* cal_data = (gyro_cal_t*) sensor[s].cal_data;
        FILE* data_file;
 
        if (cal_data == NULL)
@@ -134,16 +146,16 @@ static int gyro_collect (float x, float y, float z, gyro_cal_t* cal_data)
 }
 
 
-void calibrate_gyro (sensors_event_t* event, sensor_info_t* info)
+void calibrate_gyro (int s, sensors_event_t* event)
 {
-       gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
+       gyro_cal_t* cal_data = (gyro_cal_t*) sensor[s].cal_data;
 
        if (cal_data == NULL)
                return;
 
        /* Attempt gyroscope calibration if we have not reached this state */
-       if (info->cal_level == 0)
-               info->cal_level = gyro_collect(event->data[0], event->data[1],
+       if (sensor[s].cal_level == 0)
+               sensor[s].cal_level = gyro_collect(event->data[0], event->data[1],
                                               event->data[2], cal_data);
 
 
@@ -151,6 +163,6 @@ void calibrate_gyro (sensors_event_t* event, sensor_info_t* info)
        event->data[1] = event->data[1] - cal_data->bias_y;
        event->data[2] = event->data[2] - cal_data->bias_z;
 
-       if (info->cal_level)
+       if (sensor[s].cal_level)
               event->gyro.status = SENSOR_STATUS_ACCURACY_HIGH;
 }