1f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian/* 2f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Copyright (C) 2010 The Android Open Source Project 3f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * 4f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * you may not use this file except in compliance with the License. 6f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * You may obtain a copy of the License at 7f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * 8f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * 10f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Unless required by applicable law or agreed to in writing, software 11f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * See the License for the specific language governing permissions and 14f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * limitations under the License. 15f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian */ 16f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 17f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <stdint.h> 18f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <math.h> 19f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <sys/types.h> 20f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 21f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <utils/Errors.h> 22f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 23f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <hardware/sensors.h> 24f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 25f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include "LinearAccelerationSensor.h" 26984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include "SensorDevice.h" 27984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian#include "SensorFusion.h" 28f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 29f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopiannamespace android { 30f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// --------------------------------------------------------------------------- 31f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 32f001c92436b4a66eb7687286325ced7f10c9f917Mathias AgopianLinearAccelerationSensor::LinearAccelerationSensor(sensor_t const* list, size_t count) 33f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian : mSensorDevice(SensorDevice::getInstance()), 34f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian mGravitySensor(list, count) 35f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian{ 36f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian} 37f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 38f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianbool LinearAccelerationSensor::process(sensors_event_t* outEvent, 39f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian const sensors_event_t& event) 40f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian{ 41f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian bool result = mGravitySensor.process(outEvent, event); 42984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian if (result && event.type == SENSOR_TYPE_ACCELEROMETER) { 43984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian outEvent->data[0] = event.acceleration.x - outEvent->data[0]; 44984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian outEvent->data[1] = event.acceleration.y - outEvent->data[1]; 45984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian outEvent->data[2] = event.acceleration.z - outEvent->data[2]; 46f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian outEvent->sensor = '_lin'; 47f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian outEvent->type = SENSOR_TYPE_LINEAR_ACCELERATION; 48984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian return true; 49f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian } 50984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian return false; 51f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian} 52f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 53f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianstatus_t LinearAccelerationSensor::activate(void* ident, bool enabled) { 54bf72deea2f9982a09c6a95f94cfa1654bc8c684fAravind Akella return mGravitySensor.activate(ident, enabled); 55f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian} 56f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 57f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianstatus_t LinearAccelerationSensor::setDelay(void* ident, int handle, int64_t ns) { 58bf72deea2f9982a09c6a95f94cfa1654bc8c684fAravind Akella return mGravitySensor.setDelay(ident, handle, ns); 59f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian} 60f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 61f001c92436b4a66eb7687286325ced7f10c9f917Mathias AgopianSensor LinearAccelerationSensor::getSensor() const { 62f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian Sensor gsensor(mGravitySensor.getSensor()); 63f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian sensor_t hwSensor; 64f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian hwSensor.name = "Linear Acceleration Sensor"; 650319306670b0344da99efa606b6f172dde575a39Mathias Agopian hwSensor.vendor = "AOSP"; 66984826cc158193e61e3a00359ef4f6699c7d748aMathias Agopian hwSensor.version = gsensor.getVersion(); 67f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian hwSensor.handle = '_lin'; 68f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION; 69f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian hwSensor.maxRange = gsensor.getMaxValue(); 70f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian hwSensor.resolution = gsensor.getResolution(); 71f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian hwSensor.power = gsensor.getPowerUsage(); 72f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian hwSensor.minDelay = gsensor.getMinDelay(); 73f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian Sensor sensor(&hwSensor); 74f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian return sensor; 75f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian} 76f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 77f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// --------------------------------------------------------------------------- 78f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}; // namespace android 79f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 80