blob: b07d5448a67fc60e3d1ab42a3459a95f49a57ca0 [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#include <stdint.h>
18#include <math.h>
19#include <sys/types.h>
20
21#include <utils/Errors.h>
22
23#include <hardware/sensors.h>
24
25#include "CorrectedGyroSensor.h"
26#include "SensorDevice.h"
27#include "SensorFusion.h"
28
29namespace android {
30// ---------------------------------------------------------------------------
31
32CorrectedGyroSensor::CorrectedGyroSensor(sensor_t const* list, size_t count)
33 : mSensorDevice(SensorDevice::getInstance()),
34 mSensorFusion(SensorFusion::getInstance())
35{
36 for (size_t i=0 ; i<count ; i++) {
37 if (list[i].type == SENSOR_TYPE_GYROSCOPE) {
38 mGyro = Sensor(list + i);
39 break;
40 }
41 }
42}
43
44bool CorrectedGyroSensor::process(sensors_event_t* outEvent,
45 const sensors_event_t& event)
46{
47 if (event.type == SENSOR_TYPE_GYROSCOPE) {
Mathias Agopian33015422011-05-27 18:18:13 -070048 const vec3_t bias(mSensorFusion.getGyroBias());
Mathias Agopian984826c2011-05-17 22:54:42 -070049 *outEvent = event;
50 outEvent->data[0] -= bias.x;
51 outEvent->data[1] -= bias.y;
52 outEvent->data[2] -= bias.z;
53 outEvent->sensor = '_cgy';
54 return true;
55 }
56 return false;
57}
58
59status_t CorrectedGyroSensor::activate(void* ident, bool enabled) {
Aravind Akellabf72dee2013-09-16 15:37:41 -070060 mSensorDevice.activate(ident, mGyro.getHandle(), enabled);
61 return mSensorFusion.activate(ident, enabled);
Mathias Agopian984826c2011-05-17 22:54:42 -070062}
63
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070064status_t CorrectedGyroSensor::setDelay(void* ident, int /*handle*/, int64_t ns) {
Aravind Akellabf72dee2013-09-16 15:37:41 -070065 mSensorDevice.setDelay(ident, mGyro.getHandle(), ns);
66 return mSensorFusion.setDelay(ident, ns);
Mathias Agopian984826c2011-05-17 22:54:42 -070067}
68
69Sensor CorrectedGyroSensor::getSensor() const {
70 sensor_t hwSensor;
71 hwSensor.name = "Corrected Gyroscope Sensor";
Mathias Agopian03193062013-05-10 19:32:39 -070072 hwSensor.vendor = "AOSP";
Mathias Agopian984826c2011-05-17 22:54:42 -070073 hwSensor.version = 1;
74 hwSensor.handle = '_cgy';
75 hwSensor.type = SENSOR_TYPE_GYROSCOPE;
76 hwSensor.maxRange = mGyro.getMaxValue();
77 hwSensor.resolution = mGyro.getResolution();
78 hwSensor.power = mSensorFusion.getPowerUsage();
79 hwSensor.minDelay = mGyro.getMinDelay();
80 Sensor sensor(&hwSensor);
81 return sensor;
82}
83
84// ---------------------------------------------------------------------------
85}; // namespace android
86