• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHRE_ASH_H_
18 #define CHRE_ASH_H_
19 
20 /**
21  * @file
22  * Defines the interface for the Android Sensor Hub support.
23  */
24 
25 #include <stdbool.h>
26 #include <stdint.h>
27 
28 #include "ash/cal.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * The values returned by this sensor cannot be trusted, calibration is needed
36  * or the environment doesn't allow readings.
37  */
38 #define ASH_CAL_ACCURACY_UNRELIABLE UINT8_C(0)
39 
40 /**
41  * This sensor is reporting data with low accuracy, calibration with the
42  * environment is needed.
43  */
44 #define ASH_CAL_ACCURACY_LOW UINT8_C(1)
45 
46 /**
47  * This sensor is reporting data with an average level of accuracy, calibration
48  * with the environment may improve the readings.
49  */
50 #define ASH_CAL_ACCURACY_MEDIUM UINT8_C(2)
51 
52 /**
53  * This sensor is reporting data with maximum accuracy.
54  */
55 #define ASH_CAL_ACCURACY_HIGH UINT8_C(3)
56 
57 /**
58  * Calibration info for a sensor which reports on a maximum of three axes.
59  *
60  * Let Su be the uncalibrated sensor data and Sc the calibrated one,
61  * Sc = compMatrix * (Su - bias)
62  *
63  */
64 struct ashCalInfo {
65   /**
66    * The zero-bias vector in the x, y, z order. If the sensor reports on N
67    * axes with N < 3, only the first N elements are considered valid.
68    */
69   float bias[3];
70 
71   /**
72    * The compensation matrix in the row major order. If the sensor reports on N
73    * axes with N < 3, only the first N elements of each row are considered
74    * valid.
75    */
76   float compMatrix[9];
77 
78   /**
79    * One of the ASH_CAL_ACCURACY_* constants. This corresponds to the
80    * definition in the Android SensorManager. See
81    * https://developer.android.com/reference/android/hardware/SensorEvent.html#accuracy
82    * for more details.
83    * Note that this accuracy field is simply a suggestion to the platform and
84    * the platform can ignore or over-write it.
85    */
86   uint8_t accuracy;
87 };
88 
89 /**
90  * Updates the runtime calibration info of a given sensor type for the platform
91  * to compensate for. The calibration will be applied on top of the sensor's
92  * factory calibration if present.
93  *
94  * @param sensorType One of the CHRE_SENSOR_TYPE_* constants.
95  * @param calInfo A non-null pointer to ashCalInfo to update the sensor's
96           calibration.
97  * @return true if the calibration info has been successfully updated.
98  */
99 bool ashSetCalibration(uint8_t sensorType, const struct ashCalInfo *calInfo);
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif  // CHRE_ASH_H_
106