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" |
| 30 | #include "SecondOrderLowPassFilter.h" |
| 31 | |
| 32 | // --------------------------------------------------------------------------- |
| 33 | |
| 34 | namespace android { |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
| 37 | class SensorDevice; |
| 38 | |
| 39 | class SensorFusion : public Singleton<SensorFusion> { |
| 40 | friend class Singleton<SensorFusion>; |
| 41 | |
| 42 | SensorDevice& mSensorDevice; |
| 43 | Sensor mAcc; |
| 44 | Sensor mMag; |
| 45 | Sensor mGyro; |
| 46 | Fusion mFusion; |
| 47 | bool mEnabled; |
| 48 | bool mHasGyro; |
| 49 | float mGyroRate; |
| 50 | nsecs_t mTargetDelayNs; |
| 51 | nsecs_t mGyroTime; |
| 52 | mat33_t mRotationMatrix; |
| 53 | SecondOrderLowPassFilter mLowPass; |
| 54 | BiquadFilter<vec3_t> mAccData; |
| 55 | vec3_t mFilteredMag; |
| 56 | vec3_t mFilteredAcc; |
| 57 | SortedVector<void*> mClients; |
| 58 | |
| 59 | SensorFusion(); |
| 60 | |
| 61 | public: |
| 62 | void process(const sensors_event_t& event); |
| 63 | |
| 64 | bool isEnabled() const { return mEnabled; } |
| 65 | bool hasGyro() const { return mHasGyro; } |
| 66 | bool hasEstimate() const { return !mHasGyro || mFusion.hasEstimate(); } |
| 67 | mat33_t getRotationMatrix() const { return mRotationMatrix; } |
| 68 | vec3_t getGyroBias() const { return mFusion.getBias(); } |
| 69 | float getEstimatedRate() const { return mGyroRate; } |
| 70 | |
| 71 | status_t activate(void* ident, bool enabled); |
| 72 | status_t setDelay(void* ident, int64_t ns); |
| 73 | |
| 74 | float getPowerUsage() const; |
| 75 | int32_t getMinDelay() const; |
| 76 | |
| 77 | void dump(String8& result, char* buffer, size_t SIZE); |
| 78 | }; |
| 79 | |
| 80 | |
| 81 | // --------------------------------------------------------------------------- |
| 82 | }; // namespace android |
| 83 | |
| 84 | #endif // ANDROID_SENSOR_FUSION_H |