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 17f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#ifndef ANDROID_SENSOR_INTERFACE_H 18f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#define ANDROID_SENSOR_INTERFACE_H 19f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 20801ea093b0e923a61b832f2adba698a273479880Mathias Agopian#include <sensor/Sensor.h> 21755c451c7861a029e26e5f16e319b629169e656dPeng Xu#include <utils/RefBase.h> 22f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 23f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// --------------------------------------------------------------------------- 24f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 25f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopiannamespace android { 26f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// --------------------------------------------------------------------------- 27755c451c7861a029e26e5f16e319b629169e656dPeng Xuclass SensorDevice; 28755c451c7861a029e26e5f16e319b629169e656dPeng Xuclass SensorFusion; 29f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 30755c451c7861a029e26e5f16e319b629169e656dPeng Xuclass SensorInterface : public VirtualLightRefBase { 31f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianpublic: 32755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual ~SensorInterface() {} 33f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 340cc8f809924706c7d683da30605f432635dd5bb6Peng Xu virtual bool process(sensors_event_t* outEvent, const sensors_event_t& event) = 0; 35f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 36f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian virtual status_t activate(void* ident, bool enabled) = 0; 37f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian virtual status_t setDelay(void* ident, int handle, int64_t ns) = 0; 38755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual status_t batch(void* ident, int handle, int /*flags*/, int64_t samplingPeriodNs, 39755c451c7861a029e26e5f16e319b629169e656dPeng Xu int64_t maxBatchReportLatencyNs) = 0; 40755c451c7861a029e26e5f16e319b629169e656dPeng Xu 41755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual status_t flush(void* /*ident*/, int /*handle*/) = 0; 42755c451c7861a029e26e5f16e319b629169e656dPeng Xu 43755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual const Sensor& getSensor() const = 0; 44755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual bool isVirtual() const = 0; 45755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual void autoDisable(void* /*ident*/, int /*handle*/) = 0; 46755c451c7861a029e26e5f16e319b629169e656dPeng Xu}; 47755c451c7861a029e26e5f16e319b629169e656dPeng Xu 48755c451c7861a029e26e5f16e319b629169e656dPeng Xuclass BaseSensor : public SensorInterface { 49755c451c7861a029e26e5f16e319b629169e656dPeng Xupublic: 5038fc101331d15dde716f80f2f64b4317ea1e22f1Chih-Hung Hsieh explicit BaseSensor(const sensor_t& sensor); 516a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu BaseSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]); 52724d91d778e71c8186399f4955de14b54812b3edAravind Akella 53724d91d778e71c8186399f4955de14b54812b3edAravind Akella // Not all sensors need to support batching. 54755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual status_t batch(void* ident, int handle, int, int64_t samplingPeriodNs, 55755c451c7861a029e26e5f16e319b629169e656dPeng Xu int64_t maxBatchReportLatencyNs) override { 56724d91d778e71c8186399f4955de14b54812b3edAravind Akella if (maxBatchReportLatencyNs == 0) { 57724d91d778e71c8186399f4955de14b54812b3edAravind Akella return setDelay(ident, handle, samplingPeriodNs); 58724d91d778e71c8186399f4955de14b54812b3edAravind Akella } 59724d91d778e71c8186399f4955de14b54812b3edAravind Akella return -EINVAL; 60724d91d778e71c8186399f4955de14b54812b3edAravind Akella } 61724d91d778e71c8186399f4955de14b54812b3edAravind Akella 62755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual status_t flush(void* /*ident*/, int /*handle*/) override { 63724d91d778e71c8186399f4955de14b54812b3edAravind Akella return -EINVAL; 64724d91d778e71c8186399f4955de14b54812b3edAravind Akella } 65724d91d778e71c8186399f4955de14b54812b3edAravind Akella 66755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual const Sensor& getSensor() const override { return mSensor; } 67755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual void autoDisable(void* /*ident*/, int /*handle*/) override { } 68755c451c7861a029e26e5f16e319b629169e656dPeng Xuprotected: 69755c451c7861a029e26e5f16e319b629169e656dPeng Xu SensorDevice& mSensorDevice; 70755c451c7861a029e26e5f16e319b629169e656dPeng Xu Sensor mSensor; 71f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}; 72f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 73f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// --------------------------------------------------------------------------- 74f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 75755c451c7861a029e26e5f16e319b629169e656dPeng Xuclass HardwareSensor : public BaseSensor { 76f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianpublic: 7738fc101331d15dde716f80f2f64b4317ea1e22f1Chih-Hung Hsieh explicit HardwareSensor(const sensor_t& sensor); 786a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu HardwareSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]); 79f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 80f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian virtual ~HardwareSensor(); 81f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 82f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian virtual bool process(sensors_event_t* outEvent, 83f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian const sensors_event_t& event); 84f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 850cc8f809924706c7d683da30605f432635dd5bb6Peng Xu virtual status_t activate(void* ident, bool enabled) override; 86724d91d778e71c8186399f4955de14b54812b3edAravind Akella virtual status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs, 870cc8f809924706c7d683da30605f432635dd5bb6Peng Xu int64_t maxBatchReportLatencyNs) override; 880cc8f809924706c7d683da30605f432635dd5bb6Peng Xu virtual status_t setDelay(void* ident, int handle, int64_t ns) override; 890cc8f809924706c7d683da30605f432635dd5bb6Peng Xu virtual status_t flush(void* ident, int handle) override; 900cc8f809924706c7d683da30605f432635dd5bb6Peng Xu virtual bool isVirtual() const override { return false; } 910cc8f809924706c7d683da30605f432635dd5bb6Peng Xu virtual void autoDisable(void *ident, int handle) override; 92f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}; 93f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 94755c451c7861a029e26e5f16e319b629169e656dPeng Xuclass VirtualSensor : public BaseSensor 95755c451c7861a029e26e5f16e319b629169e656dPeng Xu{ 96755c451c7861a029e26e5f16e319b629169e656dPeng Xupublic: 97755c451c7861a029e26e5f16e319b629169e656dPeng Xu VirtualSensor(); 98755c451c7861a029e26e5f16e319b629169e656dPeng Xu virtual bool isVirtual() const override { return true; } 99755c451c7861a029e26e5f16e319b629169e656dPeng Xuprotected: 100755c451c7861a029e26e5f16e319b629169e656dPeng Xu SensorFusion& mSensorFusion; 101755c451c7861a029e26e5f16e319b629169e656dPeng Xu}; 102755c451c7861a029e26e5f16e319b629169e656dPeng Xu 103f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 104f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// --------------------------------------------------------------------------- 105f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}; // namespace android 106f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian 107f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#endif // ANDROID_SENSOR_INTERFACE_H 108