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
20f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <stdint.h>
21f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <sys/types.h>
22f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
23f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include <gui/Sensor.h>
24f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
25f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#include "SensorDevice.h"
26f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
27f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// ---------------------------------------------------------------------------
28f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
29f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopiannamespace android {
30f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// ---------------------------------------------------------------------------
31f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
32f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianclass SensorInterface {
33f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianpublic:
34f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual ~SensorInterface();
35f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
36f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual bool process(sensors_event_t* outEvent,
37f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian            const sensors_event_t& event) = 0;
38f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
39f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual status_t activate(void* ident, bool enabled) = 0;
40f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual status_t setDelay(void* ident, int handle, int64_t ns) = 0;
41724d91d778e71c8186399f4955de14b54812b3edAravind Akella
42724d91d778e71c8186399f4955de14b54812b3edAravind Akella    // Not all sensors need to support batching.
4392dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn    virtual status_t batch(void* ident, int handle, int /*flags*/, int64_t samplingPeriodNs,
44724d91d778e71c8186399f4955de14b54812b3edAravind Akella                           int64_t maxBatchReportLatencyNs) {
45724d91d778e71c8186399f4955de14b54812b3edAravind Akella        if (maxBatchReportLatencyNs == 0) {
46724d91d778e71c8186399f4955de14b54812b3edAravind Akella            return setDelay(ident, handle, samplingPeriodNs);
47724d91d778e71c8186399f4955de14b54812b3edAravind Akella        }
48724d91d778e71c8186399f4955de14b54812b3edAravind Akella        return -EINVAL;
49724d91d778e71c8186399f4955de14b54812b3edAravind Akella    }
50724d91d778e71c8186399f4955de14b54812b3edAravind Akella
5192dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn    virtual status_t flush(void* /*ident*/, int /*handle*/) {
52724d91d778e71c8186399f4955de14b54812b3edAravind Akella        return -EINVAL;
53724d91d778e71c8186399f4955de14b54812b3edAravind Akella    }
54724d91d778e71c8186399f4955de14b54812b3edAravind Akella
55f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual Sensor getSensor() const = 0;
56f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual bool isVirtual() const = 0;
5792dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn    virtual void autoDisable(void* /*ident*/, int /*handle*/) { }
58f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian};
59f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
60f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// ---------------------------------------------------------------------------
61f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
62f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianclass HardwareSensor : public SensorInterface
63f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian{
64f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    SensorDevice& mSensorDevice;
65f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    Sensor mSensor;
66f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
67f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianpublic:
68f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    HardwareSensor(const sensor_t& sensor);
69f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
70f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual ~HardwareSensor();
71f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
72f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual bool process(sensors_event_t* outEvent,
73f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian            const sensors_event_t& event);
74f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
75f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual status_t activate(void* ident, bool enabled);
76724d91d778e71c8186399f4955de14b54812b3edAravind Akella    virtual status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs,
77724d91d778e71c8186399f4955de14b54812b3edAravind Akella                           int64_t maxBatchReportLatencyNs);
78f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual status_t setDelay(void* ident, int handle, int64_t ns);
79724d91d778e71c8186399f4955de14b54812b3edAravind Akella    virtual status_t flush(void* ident, int handle);
80f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual Sensor getSensor() const;
81f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    virtual bool isVirtual() const { return false; }
82ac9a96da65f6eae4513654adaad8a457d1c1575cMathias Agopian    virtual void autoDisable(void *ident, int handle);
83f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian};
84f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
85f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
86f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian// ---------------------------------------------------------------------------
87f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}; // namespace android
88f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
89f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian#endif // ANDROID_SENSOR_INTERFACE_H
90