blob: 04beceda55df469325720a11fa8ad6ea521df500 [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{
Peng Xu0cc8f802016-04-05 23:46:03 -070036 const Sensor &gsensor = mGravitySensor.getSensor();
37 sensor_t hwSensor;
38 hwSensor.name = "Linear Acceleration Sensor";
39 hwSensor.vendor = "AOSP";
40 hwSensor.version = gsensor.getVersion();
41 hwSensor.handle = '_lin';
42 hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION;
43 hwSensor.maxRange = gsensor.getMaxValue();
44 hwSensor.resolution = gsensor.getResolution();
45 hwSensor.power = gsensor.getPowerUsage();
46 hwSensor.minDelay = gsensor.getMinDelay();
47 mSensor = Sensor(&hwSensor);
Mathias Agopianf001c922010-11-11 17:58:51 -080048}
49
50bool LinearAccelerationSensor::process(sensors_event_t* outEvent,
51 const sensors_event_t& event)
52{
53 bool result = mGravitySensor.process(outEvent, event);
Mathias Agopian984826c2011-05-17 22:54:42 -070054 if (result && event.type == SENSOR_TYPE_ACCELEROMETER) {
55 outEvent->data[0] = event.acceleration.x - outEvent->data[0];
56 outEvent->data[1] = event.acceleration.y - outEvent->data[1];
57 outEvent->data[2] = event.acceleration.z - outEvent->data[2];
Mathias Agopianf001c922010-11-11 17:58:51 -080058 outEvent->sensor = '_lin';
59 outEvent->type = SENSOR_TYPE_LINEAR_ACCELERATION;
Mathias Agopian984826c2011-05-17 22:54:42 -070060 return true;
Mathias Agopianf001c922010-11-11 17:58:51 -080061 }
Mathias Agopian984826c2011-05-17 22:54:42 -070062 return false;
Mathias Agopianf001c922010-11-11 17:58:51 -080063}
64
Mathias Agopianf001c922010-11-11 17:58:51 -080065status_t LinearAccelerationSensor::activate(void* ident, bool enabled) {
Aravind Akellabf72dee2013-09-16 15:37:41 -070066 return mGravitySensor.activate(ident, enabled);
Mathias Agopianf001c922010-11-11 17:58:51 -080067}
68
69status_t LinearAccelerationSensor::setDelay(void* ident, int handle, int64_t ns) {
Aravind Akellabf72dee2013-09-16 15:37:41 -070070 return mGravitySensor.setDelay(ident, handle, ns);
Mathias Agopianf001c922010-11-11 17:58:51 -080071}
72
Peng Xu0cc8f802016-04-05 23:46:03 -070073const Sensor& LinearAccelerationSensor::getSensor() const {
74 return mSensor;
Mathias Agopianf001c922010-11-11 17:58:51 -080075}
76
77// ---------------------------------------------------------------------------
78}; // namespace android
79