• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SensorInterface.h"
18 #include "SensorDevice.h"
19 #include "SensorFusion.h"
20 
21 #include <stdint.h>
22 #include <sys/types.h>
23 
24 namespace android {
25 // ---------------------------------------------------------------------------
26 
27 namespace {
28 const sensor_t DUMMY_SENSOR = {
29         .name = "", .vendor = "", .stringType = "", .requiredPermission = ""};
30 } //unnamed namespace
31 
BaseSensor(const sensor_t & sensor)32 BaseSensor::BaseSensor(const sensor_t& sensor) :
33         mSensorDevice(SensorDevice::getInstance()),
34         mSensor(&sensor, mSensorDevice.getHalDeviceVersion()) {
35 }
36 
BaseSensor(const sensor_t & sensor,const uint8_t (& uuid)[16])37 BaseSensor::BaseSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]) :
38         mSensorDevice(SensorDevice::getInstance()),
39         mSensor(sensor, Sensor::uuid_t(uuid), mSensorDevice.getHalDeviceVersion()) {
40 }
41 
42 // ---------------------------------------------------------------------------
43 
HardwareSensor(const sensor_t & sensor)44 HardwareSensor::HardwareSensor(const sensor_t& sensor):
45         BaseSensor(sensor) {
46 }
47 
HardwareSensor(const sensor_t & sensor,const uint8_t (& uuid)[16])48 HardwareSensor::HardwareSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]):
49         BaseSensor(sensor, uuid) {
50 }
51 
~HardwareSensor()52 HardwareSensor::~HardwareSensor() {
53 }
54 
process(sensors_event_t * outEvent,const sensors_event_t & event)55 bool HardwareSensor::process(sensors_event_t* outEvent,
56         const sensors_event_t& event) {
57     *outEvent = event;
58     return true;
59 }
60 
activate(void * ident,bool enabled)61 status_t HardwareSensor::activate(void* ident, bool enabled) {
62     return mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
63 }
64 
batch(void * ident,int,int flags,int64_t samplingPeriodNs,int64_t maxBatchReportLatencyNs)65 status_t HardwareSensor::batch(void* ident, int /*handle*/, int flags,
66                                int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
67     return mSensorDevice.batch(ident, mSensor.getHandle(), flags, samplingPeriodNs,
68                                maxBatchReportLatencyNs);
69 }
70 
flush(void * ident,int handle)71 status_t HardwareSensor::flush(void* ident, int handle) {
72     return mSensorDevice.flush(ident, handle);
73 }
74 
setDelay(void * ident,int handle,int64_t ns)75 status_t HardwareSensor::setDelay(void* ident, int handle, int64_t ns) {
76     return mSensorDevice.setDelay(ident, handle, ns);
77 }
78 
autoDisable(void * ident,int handle)79 void HardwareSensor::autoDisable(void *ident, int handle) {
80     mSensorDevice.autoDisable(ident, handle);
81 }
82 
VirtualSensor()83 VirtualSensor::VirtualSensor() :
84         BaseSensor(DUMMY_SENSOR), mSensorFusion(SensorFusion::getInstance()) {
85 }
86 
87 // ---------------------------------------------------------------------------
88 }; // namespace android
89