blob: d1cd7324990337aabd15f8798e28829c69988ebd [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
Peng Xu755c4512016-04-07 23:15:14 -070032LinearAccelerationSensor::LinearAccelerationSensor(sensor_t const* list, size_t count) :
33 mGravitySensor(list, count) {
Peng Xu0cc8f802016-04-05 23:46:03 -070034 const Sensor &gsensor = mGravitySensor.getSensor();
Peng Xu755c4512016-04-07 23:15:14 -070035 const sensor_t sensor = {
36 .name = "Linear Acceleration Sensor",
37 .vendor = "AOSP",
38 .version = gsensor.getVersion(),
39 .handle = '_lin',
40 .type = SENSOR_TYPE_LINEAR_ACCELERATION,
41 .maxRange = gsensor.getMaxValue(),
42 .resolution = gsensor.getResolution(),
43 .power = gsensor.getPowerUsage(),
44 .minDelay = gsensor.getMinDelay(),
45 };
46 mSensor = Sensor(&sensor);
Mathias Agopianf001c922010-11-11 17:58:51 -080047}
48
49bool LinearAccelerationSensor::process(sensors_event_t* outEvent,
50 const sensors_event_t& event)
51{
52 bool result = mGravitySensor.process(outEvent, event);
Mathias Agopian984826c2011-05-17 22:54:42 -070053 if (result && event.type == SENSOR_TYPE_ACCELEROMETER) {
54 outEvent->data[0] = event.acceleration.x - outEvent->data[0];
55 outEvent->data[1] = event.acceleration.y - outEvent->data[1];
56 outEvent->data[2] = event.acceleration.z - outEvent->data[2];
Mathias Agopianf001c922010-11-11 17:58:51 -080057 outEvent->sensor = '_lin';
58 outEvent->type = SENSOR_TYPE_LINEAR_ACCELERATION;
Mathias Agopian984826c2011-05-17 22:54:42 -070059 return true;
Mathias Agopianf001c922010-11-11 17:58:51 -080060 }
Mathias Agopian984826c2011-05-17 22:54:42 -070061 return false;
Mathias Agopianf001c922010-11-11 17:58:51 -080062}
63
Mathias Agopianf001c922010-11-11 17:58:51 -080064status_t LinearAccelerationSensor::activate(void* ident, bool enabled) {
Aravind Akellabf72dee2013-09-16 15:37:41 -070065 return mGravitySensor.activate(ident, enabled);
Mathias Agopianf001c922010-11-11 17:58:51 -080066}
67
68status_t LinearAccelerationSensor::setDelay(void* ident, int handle, int64_t ns) {
Aravind Akellabf72dee2013-09-16 15:37:41 -070069 return mGravitySensor.setDelay(ident, handle, ns);
Mathias Agopianf001c922010-11-11 17:58:51 -080070}
71
Mathias Agopianf001c922010-11-11 17:58:51 -080072// ---------------------------------------------------------------------------
73}; // namespace android
74