Mathias Agopian | 671a6ff | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | namespace android { |
| 32 | // --------------------------------------------------------------------------- |
| 33 | |
| 34 | static const nsecs_t DEFAULT_EVENTS_PERIOD = 200000000; // 5 Hz |
| 35 | |
| 36 | class SensorDevice : public Singleton<SensorDevice> { |
| 37 | friend class Singleton<SensorDevice>; |
| 38 | struct sensors_poll_device_t* mSensorDevice; |
| 39 | struct sensors_module_t* mSensorModule; |
Mathias Agopian | 6f4f8e7 | 2011-09-14 16:43:34 -0700 | [diff] [blame] | 40 | mutable Mutex mLock; // protect mActivationCount[].rates |
Mathias Agopian | 671a6ff | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 41 | // fixed-size array after construction |
| 42 | struct Info { |
Mathias Agopian | 6f4f8e7 | 2011-09-14 16:43:34 -0700 | [diff] [blame] | 43 | Info() : delay(0) { } |
Mathias Agopian | 671a6ff | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 44 | KeyedVector<void*, nsecs_t> rates; |
Mathias Agopian | 6f4f8e7 | 2011-09-14 16:43:34 -0700 | [diff] [blame] | 45 | nsecs_t delay; |
| 46 | status_t setDelayForIdent(void* ident, int64_t ns); |
| 47 | nsecs_t selectDelay(); |
Mathias Agopian | 671a6ff | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 48 | }; |
| 49 | DefaultKeyedVector<int, Info> mActivationCount; |
| 50 | |
| 51 | SensorDevice(); |
| 52 | public: |
| 53 | ssize_t getSensorList(sensor_t const** list); |
| 54 | status_t initCheck() const; |
| 55 | ssize_t poll(sensors_event_t* buffer, size_t count); |
| 56 | status_t activate(void* ident, int handle, int enabled); |
| 57 | status_t setDelay(void* ident, int handle, int64_t ns); |
| 58 | void dump(String8& result, char* buffer, size_t SIZE); |
| 59 | }; |
| 60 | |
| 61 | // --------------------------------------------------------------------------- |
| 62 | }; // namespace android |
| 63 | |
| 64 | #endif // ANDROID_SENSOR_DEVICE_H |