blob: 73a6db5128dfb34d2d66e0a372e3ead76ca472b9 [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
Peng Xu755c4512016-04-07 23:15:14 -070017#include "SensorInterface.h"
18#include "SensorDevice.h"
19#include "SensorFusion.h"
20
Mathias Agopianf001c922010-11-11 17:58:51 -080021#include <stdint.h>
22#include <sys/types.h>
23
Mathias Agopianf001c922010-11-11 17:58:51 -080024namespace android {
25// ---------------------------------------------------------------------------
26
Peng Xu755c4512016-04-07 23:15:14 -070027namespace {
28const sensor_t DUMMY_SENSOR = {
29 .name = "", .vendor = "", .stringType = "", .requiredPermission = ""};
30} //unnamed namespace
31
32BaseSensor::BaseSensor(const sensor_t& sensor) :
33 mSensorDevice(SensorDevice::getInstance()),
34 mSensor(&sensor, mSensorDevice.getHalDeviceVersion()) {
Mathias Agopianf001c922010-11-11 17:58:51 -080035}
36
Peng Xu6a2d3a02015-12-21 12:00:23 -080037BaseSensor::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
Mathias Agopianf001c922010-11-11 17:58:51 -080042// ---------------------------------------------------------------------------
43
Peng Xu755c4512016-04-07 23:15:14 -070044HardwareSensor::HardwareSensor(const sensor_t& sensor):
45 BaseSensor(sensor) {
Mathias Agopianf001c922010-11-11 17:58:51 -080046}
47
Peng Xu6a2d3a02015-12-21 12:00:23 -080048HardwareSensor::HardwareSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]):
49 BaseSensor(sensor, uuid) {
50}
51
Mathias Agopianf001c922010-11-11 17:58:51 -080052HardwareSensor::~HardwareSensor() {
53}
54
55bool HardwareSensor::process(sensors_event_t* outEvent,
56 const sensors_event_t& event) {
57 *outEvent = event;
58 return true;
59}
60
Mathias Agopian50b66762010-11-29 17:26:51 -080061status_t HardwareSensor::activate(void* ident, bool enabled) {
62 return mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
Mathias Agopianf001c922010-11-11 17:58:51 -080063}
64
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070065status_t HardwareSensor::batch(void* ident, int /*handle*/, int flags,
Aravind Akella724d91d2013-06-27 12:04:23 -070066 int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
67 return mSensorDevice.batch(ident, mSensor.getHandle(), flags, samplingPeriodNs,
68 maxBatchReportLatencyNs);
69}
70
71status_t HardwareSensor::flush(void* ident, int handle) {
72 return mSensorDevice.flush(ident, handle);
73}
74
Mathias Agopianf001c922010-11-11 17:58:51 -080075status_t HardwareSensor::setDelay(void* ident, int handle, int64_t ns) {
76 return mSensorDevice.setDelay(ident, handle, ns);
77}
78
Mathias Agopianac9a96d2013-07-12 02:01:16 -070079void HardwareSensor::autoDisable(void *ident, int handle) {
80 mSensorDevice.autoDisable(ident, handle);
Jaikumar Ganesh4c01b1a2013-04-16 15:52:23 -070081}
82
Peng Xu755c4512016-04-07 23:15:14 -070083VirtualSensor::VirtualSensor() :
84 BaseSensor(DUMMY_SENSOR), mSensorFusion(SensorFusion::getInstance()) {
Mathias Agopianf001c922010-11-11 17:58:51 -080085}
86
Mathias Agopianf001c922010-11-11 17:58:51 -080087// ---------------------------------------------------------------------------
88}; // namespace android