Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 26 | #include "SensorDevice.h" |
| 27 | #include "SensorFusion.h" |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | // --------------------------------------------------------------------------- |
| 31 | |
| 32 | LinearAccelerationSensor::LinearAccelerationSensor(sensor_t const* list, size_t count) |
| 33 | : mSensorDevice(SensorDevice::getInstance()), |
| 34 | mGravitySensor(list, count) |
| 35 | { |
Peng Xu | 0cc8f80 | 2016-04-05 23:46:03 -0700 | [diff] [blame] | 36 | 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 Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | bool LinearAccelerationSensor::process(sensors_event_t* outEvent, |
| 51 | const sensors_event_t& event) |
| 52 | { |
| 53 | bool result = mGravitySensor.process(outEvent, event); |
Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 54 | 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 Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 58 | outEvent->sensor = '_lin'; |
| 59 | outEvent->type = SENSOR_TYPE_LINEAR_ACCELERATION; |
Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 60 | return true; |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 61 | } |
Mathias Agopian | 984826c | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 62 | return false; |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 65 | status_t LinearAccelerationSensor::activate(void* ident, bool enabled) { |
Aravind Akella | bf72dee | 2013-09-16 15:37:41 -0700 | [diff] [blame] | 66 | return mGravitySensor.activate(ident, enabled); |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | status_t LinearAccelerationSensor::setDelay(void* ident, int handle, int64_t ns) { |
Aravind Akella | bf72dee | 2013-09-16 15:37:41 -0700 | [diff] [blame] | 70 | return mGravitySensor.setDelay(ident, handle, ns); |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Peng Xu | 0cc8f80 | 2016-04-05 23:46:03 -0700 | [diff] [blame] | 73 | const Sensor& LinearAccelerationSensor::getSensor() const { |
| 74 | return mSensor; |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | // --------------------------------------------------------------------------- |
| 78 | }; // namespace android |
| 79 | |