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 | |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 17 | #include "SensorInterface.h" |
| 18 | #include "SensorDevice.h" |
| 19 | #include "SensorFusion.h" |
| 20 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | // --------------------------------------------------------------------------- |
| 26 | |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 27 | namespace { |
| 28 | const sensor_t DUMMY_SENSOR = { |
| 29 | .name = "", .vendor = "", .stringType = "", .requiredPermission = ""}; |
| 30 | } //unnamed namespace |
| 31 | |
| 32 | BaseSensor::BaseSensor(const sensor_t& sensor) : |
| 33 | mSensorDevice(SensorDevice::getInstance()), |
| 34 | mSensor(&sensor, mSensorDevice.getHalDeviceVersion()) { |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | // --------------------------------------------------------------------------- |
| 38 | |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 39 | HardwareSensor::HardwareSensor(const sensor_t& sensor): |
| 40 | BaseSensor(sensor) { |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | HardwareSensor::~HardwareSensor() { |
| 44 | } |
| 45 | |
| 46 | bool HardwareSensor::process(sensors_event_t* outEvent, |
| 47 | const sensors_event_t& event) { |
| 48 | *outEvent = event; |
| 49 | return true; |
| 50 | } |
| 51 | |
Mathias Agopian | 50b6676 | 2010-11-29 17:26:51 -0800 | [diff] [blame] | 52 | status_t HardwareSensor::activate(void* ident, bool enabled) { |
| 53 | return mSensorDevice.activate(ident, mSensor.getHandle(), enabled); |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 56 | status_t HardwareSensor::batch(void* ident, int /*handle*/, int flags, |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 57 | int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) { |
| 58 | return mSensorDevice.batch(ident, mSensor.getHandle(), flags, samplingPeriodNs, |
| 59 | maxBatchReportLatencyNs); |
| 60 | } |
| 61 | |
| 62 | status_t HardwareSensor::flush(void* ident, int handle) { |
| 63 | return mSensorDevice.flush(ident, handle); |
| 64 | } |
| 65 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 66 | status_t HardwareSensor::setDelay(void* ident, int handle, int64_t ns) { |
| 67 | return mSensorDevice.setDelay(ident, handle, ns); |
| 68 | } |
| 69 | |
Mathias Agopian | ac9a96d | 2013-07-12 02:01:16 -0700 | [diff] [blame] | 70 | void HardwareSensor::autoDisable(void *ident, int handle) { |
| 71 | mSensorDevice.autoDisable(ident, handle); |
Jaikumar Ganesh | 4c01b1a | 2013-04-16 15:52:23 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 74 | VirtualSensor::VirtualSensor() : |
| 75 | BaseSensor(DUMMY_SENSOR), mSensorFusion(SensorFusion::getInstance()) { |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 78 | // --------------------------------------------------------------------------- |
| 79 | }; // namespace android |