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