SensorDevice.h revision f001c92436b4a66eb7687286325ced7f10c9f917
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 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; 40 Mutex mLock; // protect mActivationCount[].rates 41 // fixed-size array after construction 42 struct Info { 43 Info() : count(0) { } 44 int32_t count; 45 KeyedVector<void*, nsecs_t> rates; 46 }; 47 DefaultKeyedVector<int, Info> mActivationCount; 48 49 SensorDevice(); 50public: 51 ssize_t getSensorList(sensor_t const** list); 52 status_t initCheck() const; 53 ssize_t poll(sensors_event_t* buffer, size_t count); 54 status_t activate(void* ident, int handle, int enabled); 55 status_t setDelay(void* ident, int handle, int64_t ns); 56 void dump(String8& result, char* buffer, size_t SIZE); 57}; 58 59// --------------------------------------------------------------------------- 60}; // namespace android 61 62#endif // ANDROID_SENSOR_DEVICE_H 63