blob: 227dab6686b4899c2b36c35a9a070094f273d373 [file] [log] [blame]
Mathias Agopianf001c922010-11-11 17:58:51 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef ANDROID_SENSOR_DEVICE_H
18#define ANDROID_SENSOR_DEVICE_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/KeyedVector.h>
24#include <utils/Singleton.h>
25#include <utils/String8.h>
26
27#include <gui/Sensor.h>
28
29// ---------------------------------------------------------------------------
30
31namespace android {
32// ---------------------------------------------------------------------------
33
34static const nsecs_t DEFAULT_EVENTS_PERIOD = 200000000; // 5 Hz
35
36class SensorDevice : public Singleton<SensorDevice> {
37 friend class Singleton<SensorDevice>;
38 struct sensors_poll_device_t* mSensorDevice;
39 struct sensors_module_t* mSensorModule;
Mathias Agopian667102f2011-09-14 16:43:34 -070040 mutable Mutex mLock; // protect mActivationCount[].rates
Mathias Agopianf001c922010-11-11 17:58:51 -080041 // fixed-size array after construction
42 struct Info {
Mathias Agopian667102f2011-09-14 16:43:34 -070043 Info() : delay(0) { }
Mathias Agopianf001c922010-11-11 17:58:51 -080044 KeyedVector<void*, nsecs_t> rates;
Mathias Agopian667102f2011-09-14 16:43:34 -070045 nsecs_t delay;
46 status_t setDelayForIdent(void* ident, int64_t ns);
47 nsecs_t selectDelay();
Mathias Agopianf001c922010-11-11 17:58:51 -080048 };
49 DefaultKeyedVector<int, Info> mActivationCount;
50
51 SensorDevice();
52public:
53 ssize_t getSensorList(sensor_t const** list);
54 status_t initCheck() const;
Jaikumar Ganesh4342fdf2013-04-08 16:43:12 -070055 int getHalDeviceVersion() const;
Mathias Agopianf001c922010-11-11 17:58:51 -080056 ssize_t poll(sensors_event_t* buffer, size_t count);
57 status_t activate(void* ident, int handle, int enabled);
58 status_t setDelay(void* ident, int handle, int64_t ns);
Mathias Agopianac9a96d2013-07-12 02:01:16 -070059 void autoDisable(void *ident, int handle);
Mathias Agopianf001c922010-11-11 17:58:51 -080060 void dump(String8& result, char* buffer, size_t SIZE);
61};
62
63// ---------------------------------------------------------------------------
64}; // namespace android
65
66#endif // ANDROID_SENSOR_DEVICE_H