summaryrefslogtreecommitdiffstats
path: root/camera/inc/SensorListener.h
blob: 913eb959842cb2111f9480396787f799917f76d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Copyright (C) Texas Instruments - http://www.ti.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
* @file SensorListener.h
*
* This defines API for camerahal to get sensor events
*
*/

#ifndef ANDROID_CAMERA_HARDWARE_SENSOR_LISTENER_H
#define ANDROID_CAMERA_HARDWARE_SENSOR_LISTENER_H

#include <android/sensor.h>
#include <gui/Sensor.h>
#include <gui/SensorManager.h>
#include <gui/SensorEventQueue.h>
#include <utils/Looper.h>

namespace android {

/**
 * SensorListner class - Registers with sensor manager to get sensor events
 */

typedef void (*orientation_callback_t) (uint32_t orientation, uint32_t tilt, void* cookie);

class SensorLooperThread : public Thread {
    public:
        SensorLooperThread(Looper* looper)
            : Thread(false) {
            mLooper = sp<Looper>(looper);
        }
        ~SensorLooperThread() {
            mLooper.clear();
        }

        virtual bool threadLoop() {
            int32_t ret = mLooper->pollOnce(-1);
            return true;
        }

        // force looper wake up
        void wake() {
            mLooper->wake();
        }
    private:
        sp<Looper> mLooper;
};


class SensorListener : public RefBase
{
/* public - types */
public:
    typedef enum {
        SENSOR_ACCELEROMETER  = 1 << 0,
        SENSOR_MAGNETIC_FIELD = 1 << 1,
        SENSOR_GYROSCOPE      = 1 << 2,
        SENSOR_LIGHT          = 1 << 3,
        SENSOR_PROXIMITY      = 1 << 4,
        SENSOR_ORIENTATION    = 1 << 5,
    } sensor_type_t;
/* public - functions */
public:
    SensorListener();
    ~SensorListener();
    status_t initialize();
    void setCallbacks(orientation_callback_t orientation_cb, void *cookie);
    void enableSensor(sensor_type_t type);
    void disableSensor(sensor_type_t type);
    void handleOrientation(uint32_t orientation, uint32_t tilt);
/* public - member variables */
public:
    sp<SensorEventQueue> mSensorEventQueue;
/* private - member variables */
private:
    int sensorsEnabled;
    orientation_callback_t mOrientationCb;
    void *mCbCookie;
    sp<Looper> mLooper;
    sp<SensorLooperThread> mSensorLooperThread;
    Mutex mLock;
};

}

#endif