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; 40 mutable Mutex mLock; // protect mActivationCount[].rates 41 // fixed-size array after construction 42 struct Info { 43 Info() : delay(0) { } 44 KeyedVector<void*, nsecs_t> rates; 45 nsecs_t delay; 46 status_t setDelayForIdent(void* ident, int64_t ns); 47 nsecs_t selectDelay(); 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 int getHalDeviceVersion() const; 56 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); 59 void autoDisable(void *ident, int handle); 60 void dump(String8& result, char* buffer, size_t SIZE); 61 }; 62 63 // --------------------------------------------------------------------------- 64 }; // namespace android 65 66 #endif // ANDROID_SENSOR_DEVICE_H 67