blob: 25ae4736c97df3cfa8a54883d56d2bc4ac06a0b5 [file] [log] [blame]
Mathias Agopianf001c922010-11-11 17:58:51 -08001/*
2 * Copyright (C) 2010 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 "LinearAccelerationSensor.h"
Mathias Agopian984826c2011-05-17 22:54:42 -070026#include "SensorDevice.h"
27#include "SensorFusion.h"
Mathias Agopianf001c922010-11-11 17:58:51 -080028
29namespace android {
30// ---------------------------------------------------------------------------
31
32LinearAccelerationSensor::LinearAccelerationSensor(sensor_t const* list, size_t count)
33 : mSensorDevice(SensorDevice::getInstance()),
34 mGravitySensor(list, count)
35{
Mathias Agopianf001c922010-11-11 17:58:51 -080036}
37
38bool LinearAccelerationSensor::process(sensors_event_t* outEvent,
39 const sensors_event_t& event)
40{
41 bool result = mGravitySensor.process(outEvent, event);
Mathias Agopian984826c2011-05-17 22:54:42 -070042 if (result && event.type == SENSOR_TYPE_ACCELEROMETER) {
43 outEvent->data[0] = event.acceleration.x - outEvent->data[0];
44 outEvent->data[1] = event.acceleration.y - outEvent->data[1];
45 outEvent->data[2] = event.acceleration.z - outEvent->data[2];
Mathias Agopianf001c922010-11-11 17:58:51 -080046 outEvent->sensor = '_lin';
47 outEvent->type = SENSOR_TYPE_LINEAR_ACCELERATION;
Mathias Agopian984826c2011-05-17 22:54:42 -070048 return true;
Mathias Agopianf001c922010-11-11 17:58:51 -080049 }
Mathias Agopian984826c2011-05-17 22:54:42 -070050 return false;
Mathias Agopianf001c922010-11-11 17:58:51 -080051}
52
Mathias Agopianf001c922010-11-11 17:58:51 -080053status_t LinearAccelerationSensor::activate(void* ident, bool enabled) {
Mathias Agopian984826c2011-05-17 22:54:42 -070054 return mGravitySensor.activate(this, enabled);
Mathias Agopianf001c922010-11-11 17:58:51 -080055}
56
57status_t LinearAccelerationSensor::setDelay(void* ident, int handle, int64_t ns) {
Mathias Agopian984826c2011-05-17 22:54:42 -070058 return mGravitySensor.setDelay(this, handle, ns);
Mathias Agopianf001c922010-11-11 17:58:51 -080059}
60
61Sensor LinearAccelerationSensor::getSensor() const {
62 Sensor gsensor(mGravitySensor.getSensor());
63 sensor_t hwSensor;
64 hwSensor.name = "Linear Acceleration Sensor";
Mathias Agopian03193062013-05-10 19:32:39 -070065 hwSensor.vendor = "AOSP";
Mathias Agopian984826c2011-05-17 22:54:42 -070066 hwSensor.version = gsensor.getVersion();
Mathias Agopianf001c922010-11-11 17:58:51 -080067 hwSensor.handle = '_lin';
68 hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION;
69 hwSensor.maxRange = gsensor.getMaxValue();
70 hwSensor.resolution = gsensor.getResolution();
71 hwSensor.power = gsensor.getPowerUsage();
72 hwSensor.minDelay = gsensor.getMinDelay();
73 Sensor sensor(&hwSensor);
74 return sensor;
75}
76
77// ---------------------------------------------------------------------------
78}; // namespace android
79