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
17755c451c7861a029e26e5f16e319b629169e656dPeng Xu#include "SensorInterface.h"
18755c451c7861a029e26e5f16e319b629169e656dPeng Xu#include "SensorDevice.h"
19755c451c7861a029e26e5f16e319b629169e656dPeng Xu#include "SensorFusion.h"
20755c451c7861a029e26e5f16e319b629169e656dPeng Xu
21f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <stdint.h>
22f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <sys/types.h>
23f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
24f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopiannamespace android {
25f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// ---------------------------------------------------------------------------
26f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
27755c451c7861a029e26e5f16e319b629169e656dPeng Xunamespace {
28755c451c7861a029e26e5f16e319b629169e656dPeng Xuconst sensor_t DUMMY_SENSOR = {
29755c451c7861a029e26e5f16e319b629169e656dPeng Xu        .name = "", .vendor = "", .stringType = "", .requiredPermission = ""};
30755c451c7861a029e26e5f16e319b629169e656dPeng Xu} //unnamed namespace
31755c451c7861a029e26e5f16e319b629169e656dPeng Xu
32755c451c7861a029e26e5f16e319b629169e656dPeng XuBaseSensor::BaseSensor(const sensor_t& sensor) :
33755c451c7861a029e26e5f16e319b629169e656dPeng Xu        mSensorDevice(SensorDevice::getInstance()),
34755c451c7861a029e26e5f16e319b629169e656dPeng Xu        mSensor(&sensor, mSensorDevice.getHalDeviceVersion()) {
35f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
36f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
376a2d3a06caa337857cf60cfc70a9a78909ad3608Peng XuBaseSensor::BaseSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]) :
386a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu        mSensorDevice(SensorDevice::getInstance()),
396a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu        mSensor(sensor, Sensor::uuid_t(uuid), mSensorDevice.getHalDeviceVersion()) {
406a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu}
416a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu
42f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// ---------------------------------------------------------------------------
43f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
44755c451c7861a029e26e5f16e319b629169e656dPeng XuHardwareSensor::HardwareSensor(const sensor_t& sensor):
45755c451c7861a029e26e5f16e319b629169e656dPeng Xu        BaseSensor(sensor) {
46f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
47f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
486a2d3a06caa337857cf60cfc70a9a78909ad3608Peng XuHardwareSensor::HardwareSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]):
496a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu        BaseSensor(sensor, uuid) {
506a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu}
516a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu
52f001c92436b4a66eb7687286325ced7f10c9f917Mathias AgopianHardwareSensor::~HardwareSensor() {
53f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
54f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
55f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianbool HardwareSensor::process(sensors_event_t* outEvent,
56f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian        const sensors_event_t& event) {
57f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    *outEvent = event;
58f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    return true;
59f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
60f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
6150b66767f6c5635430483393e17d15969dfe2f05Mathias Agopianstatus_t HardwareSensor::activate(void* ident, bool enabled) {
6250b66767f6c5635430483393e17d15969dfe2f05Mathias Agopian    return mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
63f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
64f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
6592dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzynstatus_t HardwareSensor::batch(void* ident, int /*handle*/, int flags,
66724d91d778e71c8186399f4955de14b54812b3edAravind Akella                               int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
67724d91d778e71c8186399f4955de14b54812b3edAravind Akella    return mSensorDevice.batch(ident, mSensor.getHandle(), flags, samplingPeriodNs,
68724d91d778e71c8186399f4955de14b54812b3edAravind Akella                               maxBatchReportLatencyNs);
69724d91d778e71c8186399f4955de14b54812b3edAravind Akella}
70724d91d778e71c8186399f4955de14b54812b3edAravind Akella
71724d91d778e71c8186399f4955de14b54812b3edAravind Akellastatus_t HardwareSensor::flush(void* ident, int handle) {
72724d91d778e71c8186399f4955de14b54812b3edAravind Akella    return mSensorDevice.flush(ident, handle);
73724d91d778e71c8186399f4955de14b54812b3edAravind Akella}
74724d91d778e71c8186399f4955de14b54812b3edAravind Akella
75f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianstatus_t HardwareSensor::setDelay(void* ident, int handle, int64_t ns) {
76f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    return mSensorDevice.setDelay(ident, handle, ns);
77f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
78f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
79ac9a96da65f6eae4513654adaad8a457d1c1575cMathias Agopianvoid HardwareSensor::autoDisable(void *ident, int handle) {
80ac9a96da65f6eae4513654adaad8a457d1c1575cMathias Agopian    mSensorDevice.autoDisable(ident, handle);
814c01b1ad80e084f0cd1057f89fdd1fcedf19dd96Jaikumar Ganesh}
824c01b1ad80e084f0cd1057f89fdd1fcedf19dd96Jaikumar Ganesh
83755c451c7861a029e26e5f16e319b629169e656dPeng XuVirtualSensor::VirtualSensor() :
84755c451c7861a029e26e5f16e319b629169e656dPeng Xu        BaseSensor(DUMMY_SENSOR), mSensorFusion(SensorFusion::getInstance()) {
85f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
86f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
87f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// ---------------------------------------------------------------------------
88f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}; // namespace android
89