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