summaryrefslogtreecommitdiffstats
path: root/nci/jni/PowerSwitch.h
blob: 2e6b604724f1d42a11b3d30cf26a220ef79457ed (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*****************************************************************************
**
**  Name:           PowerSwitch.h
**
**  Description:    Adjust the controller's power states.
**
**  Copyright (c) 2012, Broadcom Corp., All Rights Reserved.
**  Proprietary and confidential.
**
*****************************************************************************/
#pragma once
#include "nfa_api.h"
#include "SyncEvent.h"


/*****************************************************************************
**
**  Name:           PowerSwitch
**
**  Description:    Adjust the controller's power states.
**
*****************************************************************************/
class PowerSwitch
{
public:


    /*******************************************************************************
    **
    ** Description:     UNKNOWN_LEVEL: power level is unknown because the stack is off.
    **                  FULL_POWER: controller is in full-power state.
    **                  LOW_POWER: controller is in lower-power state.
    **
    *******************************************************************************/
    enum PowerLevel {UNKNOWN_LEVEL, FULL_POWER, LOW_POWER, POWER_OFF};

    /*******************************************************************************
    **
    ** Description:     Platform Power Level, copied from NativeNfcBrcmPowerMode.java.
    **                  UNKNOWN_LEVEL: power level is unknown.
    **                  POWER_OFF: The phone is turned OFF
    **                  SCREEN_OFF: The phone is turned ON but screen is OFF
    **                  SCREEN_ON_LOCKED: The phone is turned ON, screen is ON but user locked
    **                  SCREEN_ON_UNLOCKED: The phone is turned ON, screen is ON, and user unlocked
    **
    *******************************************************************************/
    static const int PLATFORM_UNKNOWN_LEVEL = 0;
    static const int PLATFORM_POWER_OFF = 1;
    static const int PLATFORM_SCREEN_OFF = 2;
    static const int PLATFORM_SCREEN_ON_LOCKED = 3;
    static const int PLATFORM_SCREEN_ON_UNLOCKED = 4;

    static const int VBAT_MONITOR_ENABLED = 1;
    static const int VBAT_MONITOR_PRIMARY_THRESHOLD = 5;
    static const int VBAT_MONITOR_SECONDARY_THRESHOLD = 8;
    /*******************************************************************************
    **
    ** Function:        PowerSwitch
    **
    ** Description:     Initialize member variables.
    **
    ** Returns:         None
    **
    *******************************************************************************/
    PowerSwitch ();


    /*******************************************************************************
    **
    ** Function:        ~PowerSwitch
    **
    ** Description:     Release all resources.
    **
    ** Returns:         None
    **
    *******************************************************************************/
    ~PowerSwitch ();


    /*******************************************************************************
    **
    ** Function:        getInstance
    **
    ** Description:     Get the singleton of this object.
    **
    ** Returns:         Reference to this object.
    **
    *******************************************************************************/
    static PowerSwitch& getInstance ();

    /*******************************************************************************
    **
    ** Function:        initialize
    **
    ** Description:     Initialize member variables.
    **
    ** Returns:         None
    **
    *******************************************************************************/
    void initialize (PowerLevel level);


    /*******************************************************************************
    **
    ** Function:        getLevel
    **
    ** Description:     Get the current power level of the controller.
    **
    ** Returns:         Power level.
    **
    *******************************************************************************/
    PowerLevel getLevel ();


    /*******************************************************************************
    **
    ** Function:        isScreenOn
    **
    ** Description:     Get the current screen state of the platform host.
    **
    ** Returns:         true if screen if on, (locked or unlocked).
    **
    *******************************************************************************/
    bool isScreenOn ();


    /*******************************************************************************
    **
    ** Function:        setLevel
    **
    ** Description:     Set the controller's power level.
    **                  level: power level.
    **
    ** Returns:         True if ok.
    **
    *******************************************************************************/
    bool setLevel (PowerLevel level);

    /*******************************************************************************
    **
    ** Function:        setScreenState
    **
    ** Description:     Set the Platform's screen state
    **                  state: true for screen on, flase for screem off
    **
    ** Returns:         True if ok.
    **
    *******************************************************************************/
    bool setScreenState (bool state);

    /*******************************************************************************
    **
    ** Function:        abort
    **
    ** Description:     Abort and unblock currrent operation.
    **
    ** Returns:         None
    **
    *******************************************************************************/
    void abort ();


    /*******************************************************************************
    **
    ** Function:        deviceManagementCallback
    **
    ** Description:     Callback function for the stack.
    **                  event: event ID.
    **                  eventData: event's data.
    **
    ** Returns:         None
    **
    *******************************************************************************/
    static void deviceManagementCallback (UINT8 event, tNFA_DM_CBACK_DATA* eventData);


    /*******************************************************************************
    **
    ** Function:        isPowerOffSleepFeatureEnabled
    **
    ** Description:     Whether power-off-sleep feature is enabled in .conf file.
    **
    ** Returns:         True if feature is enabled.
    **
    *******************************************************************************/
    bool isPowerOffSleepFeatureEnabled ();

private:
    PowerLevel mCurrLevel;
    bool mScreenState;
    UINT8 mCurrDeviceMgtPowerState; //device management power state; such as NFA_DM_PWR_STATE_???
    int mDesiredScreenOffPowerState; //read from .conf file; 0=power-off-sleep; 1=full power; 2=CE4 power
    static PowerSwitch sPowerSwitch; //singleton object
    static const UINT8 NFA_DM_PWR_STATE_UNKNOWN = -1; //device management power state power state is unknown
    SyncEvent mPowerStateEvent;


    /*******************************************************************************
    **
    ** Function:        setPowerOffSleepState
    **
    ** Description:     Adjust controller's power-off-sleep state.
    **                  sleep: whether to enter sleep state.
    **
    ** Returns:         True if ok.
    **
    *******************************************************************************/
    bool setPowerOffSleepState (bool sleep);


    /*******************************************************************************
    **
    ** Function:        deviceMgtPowerStateToString
    **
    ** Description:     Decode power level to a string.
    **                  deviceMgtPowerState: power level.
    **
    ** Returns:         Text representation of power level.
    **
    *******************************************************************************/
    const char* deviceMgtPowerStateToString (UINT8 deviceMgtPowerState);


    /*******************************************************************************
    **
    ** Function:        powerLevelToString
    **
    ** Description:     Decode power level to a string.
    **                  level: power level.
    **
    ** Returns:         Text representation of power level.
    **
    *******************************************************************************/
    const char* powerLevelToString (PowerLevel level);
};