1 /* 2 * Copyright (C) Texas Instruments - http://www.ti.com/ 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 /** 18 * @file SensorListener.h 19 * 20 * This defines API for camerahal to get sensor events 21 * 22 */ 23 24 #ifndef ANDROID_CAMERA_HARDWARE_SENSOR_LISTENER_H 25 #define ANDROID_CAMERA_HARDWARE_SENSOR_LISTENER_H 26 27 #include <android/sensor.h> 28 #include <gui/Sensor.h> 29 #include <gui/SensorManager.h> 30 #include <gui/SensorEventQueue.h> 31 #include <utils/Looper.h> 32 33 namespace android { 34 35 /** 36 * SensorListner class - Registers with sensor manager to get sensor events 37 */ 38 39 typedef void (*orientation_callback_t) (uint32_t orientation, uint32_t tilt, void* cookie); 40 41 class SensorLooperThread : public Thread { 42 public: 43 SensorLooperThread(Looper* looper) 44 : Thread(false) { 45 mLooper = sp<Looper>(looper); 46 } 47 ~SensorLooperThread() { 48 mLooper.clear(); 49 } 50 51 virtual bool threadLoop() { 52 int32_t ret = mLooper->pollOnce(-1); 53 return true; 54 } 55 56 // force looper wake up 57 void wake() { 58 mLooper->wake(); 59 } 60 private: 61 sp<Looper> mLooper; 62 }; 63 64 65 class SensorListener : public RefBase 66 { 67 /* public - types */ 68 public: 69 typedef enum { 70 SENSOR_ACCELEROMETER = 1 << 0, 71 SENSOR_MAGNETIC_FIELD = 1 << 1, 72 SENSOR_GYROSCOPE = 1 << 2, 73 SENSOR_LIGHT = 1 << 3, 74 SENSOR_PROXIMITY = 1 << 4, 75 SENSOR_ORIENTATION = 1 << 5, 76 } sensor_type_t; 77 /* public - functions */ 78 public: 79 SensorListener(); 80 ~SensorListener(); 81 status_t initialize(); 82 void setCallbacks(orientation_callback_t orientation_cb, void *cookie); 83 void enableSensor(sensor_type_t type); 84 void disableSensor(sensor_type_t type); 85 void handleOrientation(uint32_t orientation, uint32_t tilt); 86 /* public - member variables */ 87 public: 88 sp<SensorEventQueue> mSensorEventQueue; 89 /* private - member variables */ 90 private: 91 int sensorsEnabled; 92 orientation_callback_t mOrientationCb; 93 void *mCbCookie; 94 sp<Looper> mLooper; 95 sp<SensorLooperThread> mSensorLooperThread; 96 Mutex mLock; 97 }; 98 99 } 100 101 #endif 102