blob: b8f360f52cf264e7aa28913e955063fb97f34eed [file] [log] [blame]
Mathias Agopian984826c2011-05-17 22:54:42 -07001/*
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 Agopian984826c2011-05-17 22:54:42 -070030
31// ---------------------------------------------------------------------------
32
33namespace android {
34// ---------------------------------------------------------------------------
35
36class SensorDevice;
37
38class SensorFusion : public Singleton<SensorFusion> {
39 friend class Singleton<SensorFusion>;
Aravind Akella724d91d2013-06-27 12:04:23 -070040 static const nsecs_t DEFAULT_EVENTS_PERIOD = 200000000; // 5 Hz
Mathias Agopian984826c2011-05-17 22:54:42 -070041
42 SensorDevice& mSensorDevice;
43 Sensor mAcc;
44 Sensor mMag;
45 Sensor mGyro;
46 Fusion mFusion;
47 bool mEnabled;
Mathias Agopian2e2a5602013-05-30 14:18:23 -070048 float mEstimatedGyroRate;
Mathias Agopian984826c2011-05-17 22:54:42 -070049 nsecs_t mTargetDelayNs;
50 nsecs_t mGyroTime;
Mathias Agopian33015422011-05-27 18:18:13 -070051 vec4_t mAttitude;
Mathias Agopian984826c2011-05-17 22:54:42 -070052 SortedVector<void*> mClients;
53
54 SensorFusion();
55
56public:
57 void process(const sensors_event_t& event);
58
59 bool isEnabled() const { return mEnabled; }
Mathias Agopian33015422011-05-27 18:18:13 -070060 bool hasEstimate() const { return mFusion.hasEstimate(); }
61 mat33_t getRotationMatrix() const { return mFusion.getRotationMatrix(); }
62 vec4_t getAttitude() const { return mAttitude; }
Mathias Agopian984826c2011-05-17 22:54:42 -070063 vec3_t getGyroBias() const { return mFusion.getBias(); }
Mathias Agopian2e2a5602013-05-30 14:18:23 -070064 float getEstimatedRate() const { return mEstimatedGyroRate; }
Mathias Agopian984826c2011-05-17 22:54:42 -070065
66 status_t activate(void* ident, bool enabled);
67 status_t setDelay(void* ident, int64_t ns);
68
69 float getPowerUsage() const;
70 int32_t getMinDelay() const;
71
Mathias Agopianba02cd22013-07-03 16:20:57 -070072 void dump(String8& result);
Mathias Agopian984826c2011-05-17 22:54:42 -070073};
74
75
76// ---------------------------------------------------------------------------
77}; // namespace android
78
79#endif // ANDROID_SENSOR_FUSION_H