1984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian/* 2984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * Copyright (C) 2011 The Android Open Source Project 3984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * 4984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * you may not use this file except in compliance with the License. 6984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * You may obtain a copy of the License at 7984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * 8984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * 10984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * Unless required by applicable law or agreed to in writing, software 11984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * See the License for the specific language governing permissions and 14984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian * limitations under the License. 15984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian */ 16984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 17984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#ifndef ANDROID_SENSOR_FUSION_H 18984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#define ANDROID_SENSOR_FUSION_H 19984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 20984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include <stdint.h> 21984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include <sys/types.h> 22984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 23984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include <utils/SortedVector.h> 24984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include <utils/Singleton.h> 25984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include <utils/String8.h> 26984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 27984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include <gui/Sensor.h> 28984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 29984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include "Fusion.h" 30984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 31984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian// --------------------------------------------------------------------------- 32984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 33984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopiannamespace android { 34984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian// --------------------------------------------------------------------------- 35984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 36984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopianclass SensorDevice; 37984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 38984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopianclass SensorFusion : public Singleton<SensorFusion> { 39984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian friend class Singleton<SensorFusion>; 40984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 41984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian SensorDevice& mSensorDevice; 42984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian Sensor mAcc; 43984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian Sensor mMag; 44984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian Sensor mGyro; 45984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian Fusion mFusion; 46984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian bool mEnabled; 47984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian float mGyroRate; 48984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian nsecs_t mTargetDelayNs; 49984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian nsecs_t mGyroTime; 503301542828febc768e1df42892cfac4992c35474Mathias Agopian vec4_t mAttitude; 51984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian SortedVector<void*> mClients; 52984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 53984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian SensorFusion(); 54984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 55984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopianpublic: 56984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian void process(const sensors_event_t& event); 57984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 58984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian bool isEnabled() const { return mEnabled; } 593301542828febc768e1df42892cfac4992c35474Mathias Agopian bool hasEstimate() const { return mFusion.hasEstimate(); } 603301542828febc768e1df42892cfac4992c35474Mathias Agopian mat33_t getRotationMatrix() const { return mFusion.getRotationMatrix(); } 613301542828febc768e1df42892cfac4992c35474Mathias Agopian vec4_t getAttitude() const { return mAttitude; } 62984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian vec3_t getGyroBias() const { return mFusion.getBias(); } 63984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian float getEstimatedRate() const { return mGyroRate; } 64984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 65984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian status_t activate(void* ident, bool enabled); 66984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian status_t setDelay(void* ident, int64_t ns); 67984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 68984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian float getPowerUsage() const; 69984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian int32_t getMinDelay() const; 70984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 71984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian void dump(String8& result, char* buffer, size_t SIZE); 72984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian}; 73984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 74984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 75984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian// --------------------------------------------------------------------------- 76984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian}; // namespace android 77984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian 78984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#endif // ANDROID_SENSOR_FUSION_H 79