Home | History | Annotate | Download | only in sensorservice
      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"
     26 #include "SensorDevice.h"
     27 #include "SensorFusion.h"
     28 
     29 namespace android {
     30 // ---------------------------------------------------------------------------
     31 
     32 LinearAccelerationSensor::LinearAccelerationSensor(sensor_t const* list, size_t count) :
     33         mGravitySensor(list, count) {
     34     const Sensor &gsensor = mGravitySensor.getSensor();
     35     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);
     47 }
     48 
     49 bool LinearAccelerationSensor::process(sensors_event_t* outEvent,
     50         const sensors_event_t& event)
     51 {
     52     bool result = mGravitySensor.process(outEvent, event);
     53     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];
     57         outEvent->sensor = '_lin';
     58         outEvent->type = SENSOR_TYPE_LINEAR_ACCELERATION;
     59         return true;
     60     }
     61     return false;
     62 }
     63 
     64 status_t LinearAccelerationSensor::activate(void* ident, bool enabled) {
     65     return mGravitySensor.activate(ident, enabled);
     66 }
     67 
     68 status_t LinearAccelerationSensor::setDelay(void* ident, int handle, int64_t ns) {
     69     return mGravitySensor.setDelay(ident, handle, ns);
     70 }
     71 
     72 // ---------------------------------------------------------------------------
     73 }; // namespace android
     74 
     75