| Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2011 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 ANDROID_SENSOR_FUSION_H | 
 | 18 | #define ANDROID_SENSOR_FUSION_H | 
 | 19 |  | 
 | 20 | #include <stdint.h> | 
 | 21 | #include <sys/types.h> | 
 | 22 |  | 
 | 23 | #include <utils/SortedVector.h> | 
 | 24 | #include <utils/Singleton.h> | 
 | 25 | #include <utils/String8.h> | 
 | 26 |  | 
 | 27 | #include <gui/Sensor.h> | 
 | 28 |  | 
 | 29 | #include "Fusion.h" | 
| Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 30 |  | 
 | 31 | // --------------------------------------------------------------------------- | 
 | 32 |  | 
 | 33 | namespace android { | 
 | 34 | // --------------------------------------------------------------------------- | 
 | 35 |  | 
 | 36 | class SensorDevice; | 
 | 37 |  | 
 | 38 | class SensorFusion : public Singleton<SensorFusion> { | 
 | 39 |     friend class Singleton<SensorFusion>; | 
 | 40 |  | 
 | 41 |     SensorDevice& mSensorDevice; | 
 | 42 |     Sensor mAcc; | 
 | 43 |     Sensor mMag; | 
 | 44 |     Sensor mGyro; | 
 | 45 |     Fusion mFusion; | 
 | 46 |     bool mEnabled; | 
| Mathias Agopian | 2e2a560 | 2013-05-30 14:18:23 -0700 | [diff] [blame] | 47 |     float mEstimatedGyroRate; | 
| Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 48 |     nsecs_t mTargetDelayNs; | 
 | 49 |     nsecs_t mGyroTime; | 
| Mathias Agopian | 3301542 | 2011-05-27 18:18:13 -0700 | [diff] [blame] | 50 |     vec4_t mAttitude; | 
| Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 51 |     SortedVector<void*> mClients; | 
 | 52 |  | 
 | 53 |     SensorFusion(); | 
 | 54 |  | 
 | 55 | public: | 
 | 56 |     void process(const sensors_event_t& event); | 
 | 57 |  | 
 | 58 |     bool isEnabled() const { return mEnabled; } | 
| Mathias Agopian | 3301542 | 2011-05-27 18:18:13 -0700 | [diff] [blame] | 59 |     bool hasEstimate() const { return mFusion.hasEstimate(); } | 
 | 60 |     mat33_t getRotationMatrix() const { return mFusion.getRotationMatrix(); } | 
 | 61 |     vec4_t getAttitude() const { return mAttitude; } | 
| Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 62 |     vec3_t getGyroBias() const { return mFusion.getBias(); } | 
| Mathias Agopian | 2e2a560 | 2013-05-30 14:18:23 -0700 | [diff] [blame] | 63 |     float getEstimatedRate() const { return mEstimatedGyroRate; } | 
| Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 64 |  | 
 | 65 |     status_t activate(void* ident, bool enabled); | 
 | 66 |     status_t setDelay(void* ident, int64_t ns); | 
 | 67 |  | 
 | 68 |     float getPowerUsage() const; | 
 | 69 |     int32_t getMinDelay() const; | 
 | 70 |  | 
| Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 71 |     void dump(String8& result); | 
| Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 72 | }; | 
 | 73 |  | 
 | 74 |  | 
 | 75 | // --------------------------------------------------------------------------- | 
 | 76 | }; // namespace android | 
 | 77 |  | 
 | 78 | #endif // ANDROID_SENSOR_FUSION_H |