blob: e8d1a5d1e2e4b322d5a8eed851fbcec746dd377f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
#define ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
#include "Utils.h"
#include <cstdint>
struct sensor_t;
struct sensors_event_t;
namespace android {
namespace SensorHalExt {
class SensorEventCallback;
class BaseSensorObject : virtual public REF_BASE(BaseSensorObject) {
public:
BaseSensorObject();
virtual ~BaseSensorObject() = default;
// always called by DynamicSensorManager, callback must point to
// valid object throughout life cycle of BaseSensorObject
bool setEventCallback(SensorEventCallback* callback);
// virtual functions to get sensor information and operate sensor
virtual const sensor_t* getSensor() const = 0;
// get uuid of sensor, default implementation set it to all zero, means does not have a uuid.
virtual void getUuid(uint8_t* uuid) const;
// enable sensor
virtual int enable(bool enable) = 0;
// set sample period and batching period of sensor.
// both sample period and batch period are in nano-seconds.
virtual int batch(int64_t samplePeriod, int64_t batchPeriod) = 0;
// flush sensor, default implementation will send a flush complete event back.
virtual int flush();
protected:
// utility function for sub-class
void generateEvent(const sensors_event_t &e);
private:
SensorEventCallback* mCallback;
};
} // namespace SensorHalExt
} // namespace android
#endif // ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
|