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 #include "Common.h" 34 35 namespace Ti { 36 namespace Camera { 37 38 /** 39 * SensorListner class - Registers with sensor manager to get sensor events 40 */ 41 42 typedef void (*orientation_callback_t) (uint32_t orientation, uint32_t tilt, void* cookie); 43 44 class SensorLooperThread : public android::Thread { 45 public: 46 SensorLooperThread(android::Looper* looper) 47 : Thread(false) { 48 mLooper = android::sp<android::Looper>(looper); 49 } 50 ~SensorLooperThread() { 51 mLooper.clear(); 52 } 53 54 virtual bool threadLoop() { 55 int32_t ret = mLooper->pollOnce(-1); 56 return true; 57 } 58 59 // force looper wake up 60 void wake() { 61 mLooper->wake(); 62 } 63 private: 64 android::sp<android::Looper> mLooper; 65 }; 66 67 68 class SensorListener : public android::RefBase 69 { 70 /* public - types */ 71 public: 72 typedef enum { 73 SENSOR_ACCELEROMETER = 1 << 0, 74 SENSOR_MAGNETIC_FIELD = 1 << 1, 75 SENSOR_GYROSCOPE = 1 << 2, 76 SENSOR_LIGHT = 1 << 3, 77 SENSOR_PROXIMITY = 1 << 4, 78 SENSOR_ORIENTATION = 1 << 5, 79 } sensor_type_t; 80 /* public - functions */ 81 public: 82 SensorListener(); 83 ~SensorListener(); 84 status_t initialize(); 85 void setCallbacks(orientation_callback_t orientation_cb, void *cookie); 86 void enableSensor(sensor_type_t type); 87 void disableSensor(sensor_type_t type); 88 void handleOrientation(uint32_t orientation, uint32_t tilt); 89 /* public - member variables */ 90 public: 91 android::sp<android::SensorEventQueue> mSensorEventQueue; 92 /* private - member variables */ 93 private: 94 int sensorsEnabled; 95 orientation_callback_t mOrientationCb; 96 void *mCbCookie; 97 android::sp<android::Looper> mLooper; 98 android::sp<SensorLooperThread> mSensorLooperThread; 99 android::Mutex mLock; 100 }; 101 102 } // namespace Camera 103 } // namespace Ti 104 105 #endif 106