2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_SENSOR_INTERFACE_H
18 #define ANDROID_SENSOR_INTERFACE_H
20 #include <sensor/Sensor.h>
21 #include <utils/RefBase.h>
23 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
30 class SensorInterface : public VirtualLightRefBase {
32 virtual ~SensorInterface() {}
34 virtual bool process(sensors_event_t* outEvent, const sensors_event_t& event) = 0;
36 virtual status_t activate(void* ident, bool enabled) = 0;
37 virtual status_t setDelay(void* ident, int handle, int64_t ns) = 0;
38 virtual status_t batch(void* ident, int handle, int /*flags*/, int64_t samplingPeriodNs,
39 int64_t maxBatchReportLatencyNs) = 0;
41 virtual status_t flush(void* /*ident*/, int /*handle*/) = 0;
43 virtual const Sensor& getSensor() const = 0;
44 virtual bool isVirtual() const = 0;
45 virtual void autoDisable(void* /*ident*/, int /*handle*/) = 0;
48 class BaseSensor : public SensorInterface {
50 explicit BaseSensor(const sensor_t& sensor);
51 BaseSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]);
53 // Not all sensors need to support batching.
54 virtual status_t batch(void* ident, int handle, int, int64_t samplingPeriodNs,
55 int64_t maxBatchReportLatencyNs) override {
56 if (maxBatchReportLatencyNs == 0) {
57 return setDelay(ident, handle, samplingPeriodNs);
62 virtual status_t flush(void* /*ident*/, int /*handle*/) override {
66 virtual const Sensor& getSensor() const override { return mSensor; }
67 virtual void autoDisable(void* /*ident*/, int /*handle*/) override { }
69 SensorDevice& mSensorDevice;
73 // ---------------------------------------------------------------------------
75 class HardwareSensor : public BaseSensor {
77 explicit HardwareSensor(const sensor_t& sensor);
78 HardwareSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]);
80 virtual ~HardwareSensor();
82 virtual bool process(sensors_event_t* outEvent,
83 const sensors_event_t& event);
85 virtual status_t activate(void* ident, bool enabled) override;
86 virtual status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs,
87 int64_t maxBatchReportLatencyNs) override;
88 virtual status_t setDelay(void* ident, int handle, int64_t ns) override;
89 virtual status_t flush(void* ident, int handle) override;
90 virtual bool isVirtual() const override { return false; }
91 virtual void autoDisable(void *ident, int handle) override;
94 class VirtualSensor : public BaseSensor
98 virtual bool isVirtual() const override { return true; }
100 SensorFusion& mSensorFusion;
104 // ---------------------------------------------------------------------------
105 }; // namespace android
107 #endif // ANDROID_SENSOR_INTERFACE_H