21
21
#include " LightingManager.h"
22
22
#include < app/server/OnboardingCodesUtil.h>
23
23
24
+ #ifdef CAPSENSE_ENABLED
25
+ #include " capsense.h"
26
+ #endif
27
+
24
28
// FIXME: Undefine the `sleep()` function included by the CHIPDeviceLayer.h
25
29
// from unistd.h to avoid a conflicting declaration with the `sleep()` provided
26
30
// by Mbed-OS in mbed_power_mgmt.h.
@@ -58,13 +62,16 @@ static LEDWidget sStatusLED(MBED_CONF_APP_SYSTEM_STATE_LED);
58
62
59
63
static mbed::InterruptIn sLightingButton (LIGHTING_BUTTON);
60
64
static mbed::InterruptIn sFunctionButton (FUNCTION_BUTTON);
61
-
65
+ #ifdef CAPSENSE_ENABLED
66
+ static mbed::CapsenseButton CapFunctionButton (Capsense::getInstance(), 0);
67
+ static mbed::CapsenseButton CapLockButton (Capsense::getInstance(), 1);
68
+ static mbed::CapsenseSlider CapSlider (Capsense::getInstance());
69
+ #endif
62
70
static bool sIsWiFiStationProvisioned = false ;
63
71
static bool sIsWiFiStationEnabled = false ;
64
72
static bool sIsWiFiStationConnected = false ;
65
73
static bool sIsPairedToAccount = false ;
66
74
static bool sHaveBLEConnections = false ;
67
- static bool sHaveServiceConnectivity = false ;
68
75
69
76
static mbed::Timeout sFunctionTimer ;
70
77
@@ -95,10 +102,17 @@ int AppTask::Init()
95
102
96
103
// -------------
97
104
// Initialize button
105
+ #ifdef CAPSENSE_ENABLED
106
+ CapFunctionButton.fall (mbed::callback (this , &AppTask::FunctionButtonPressEventHandler));
107
+ CapFunctionButton.rise (mbed::callback (this , &AppTask::FunctionButtonReleaseEventHandler));
108
+ CapLockButton.fall (mbed::callback (this , &AppTask::LightingButtonPressEventHandler));
109
+ CapSlider.on_move (mbed::callback (this , &AppTask::SliderEventHandler));
110
+ #else
98
111
sLightingButton .fall (mbed::callback (this , &AppTask::LightingButtonPressEventHandler));
99
112
sFunctionButton .fall (mbed::callback (this , &AppTask::FunctionButtonPressEventHandler));
100
113
sFunctionButton .rise (mbed::callback (this , &AppTask::FunctionButtonReleaseEventHandler));
101
- // ----------------
114
+ #endif
115
+
102
116
// Initialize lighting manager
103
117
LightingMgr ().Init (MBED_CONF_APP_LIGHTING_STATE_LED);
104
118
LightingMgr ().SetCallbacks (ActionInitiated, ActionCompleted);
@@ -153,20 +167,14 @@ int AppTask::StartApp()
153
167
sIsWiFiStationEnabled = ConnectivityMgr ().IsWiFiStationEnabled ();
154
168
sIsWiFiStationConnected = ConnectivityMgr ().IsWiFiStationConnected ();
155
169
sHaveBLEConnections = (ConnectivityMgr ().NumBLEConnections () != 0 );
156
- sHaveServiceConnectivity = ConnectivityMgr ().HaveServiceConnectivity ();
157
170
PlatformMgr ().UnlockChipStack ();
158
171
}
159
172
160
- // Consider the system to be "fully connected" if it has service
161
- // connectivity and it is able to interact with the service on a regular basis.
162
- bool isFullyConnected = sHaveServiceConnectivity ;
163
-
164
173
// Update the status LED if factory reset has not been initiated.
165
174
//
166
- // If system has "full connectivity" , keep the LED On constantly.
175
+ // If system is connected to Wi-Fi station , keep the LED On constantly.
167
176
//
168
- // If thread and service provisioned, but not attached to the thread network yet OR no
169
- // connectivity to the service OR subscriptions are not fully established
177
+ // If Wi-Fi is provisioned, but not connected to Wi-Fi station yet
170
178
// THEN blink the LED Off for a short period of time.
171
179
//
172
180
// If the system has ble connection(s) uptill the stage above, THEN blink the LEDs at an even
@@ -175,12 +183,11 @@ int AppTask::StartApp()
175
183
// Otherwise, blink the LED ON for a very short time.
176
184
if (sAppTask .mFunction != kFunction_FactoryReset )
177
185
{
178
- if (isFullyConnected )
186
+ if (sIsWiFiStationConnected )
179
187
{
180
188
sStatusLED .Set (true );
181
189
}
182
- else if (sIsWiFiStationProvisioned && sIsWiFiStationEnabled && sIsPairedToAccount &&
183
- (!sIsWiFiStationConnected || !isFullyConnected))
190
+ else if (sIsWiFiStationProvisioned && sIsWiFiStationEnabled && sIsPairedToAccount && !sIsWiFiStationConnected )
184
191
{
185
192
sStatusLED .Blink (950 , 50 );
186
193
}
@@ -202,7 +209,7 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent)
202
209
{
203
210
LightingManager::Action_t action = LightingManager::INVALID_ACTION;
204
211
int32_t actor = 0 ;
205
-
212
+ uint8_t value = 0 ;
206
213
if (aEvent->Type == AppEvent::kEventType_Lighting )
207
214
{
208
215
action = static_cast <LightingManager::Action_t>(aEvent->LightingEvent .Action );
@@ -213,8 +220,14 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent)
213
220
action = LightingMgr ().IsTurnedOn () ? LightingManager::OFF_ACTION : LightingManager::ON_ACTION;
214
221
actor = AppEvent::kEventType_Button ;
215
222
}
223
+ else if (aEvent->Type == AppEvent::kEventType_Slider )
224
+ {
225
+ action = LightingManager::LEVEL_ACTION;
226
+ actor = AppEvent::kEventType_Slider ;
227
+ value = aEvent->SliderEvent .Value ;
228
+ }
216
229
217
- if (action != LightingManager::INVALID_ACTION && !LightingMgr ().InitiateAction (action, actor, 0 , NULL ))
230
+ if (action != LightingManager::INVALID_ACTION && !LightingMgr ().InitiateAction (action, actor, 0 , &value ))
218
231
ChipLogProgress (NotSpecified, " Action is already in progress or active." );
219
232
}
220
233
@@ -248,6 +261,40 @@ void AppTask::FunctionButtonReleaseEventHandler()
248
261
sAppTask .PostEvent (&button_event);
249
262
}
250
263
264
+ void AppTask::ButtonEventHandler (uint32_t id, bool pushed)
265
+ {
266
+ if (id > 1 )
267
+ {
268
+ ChipLogError (NotSpecified, " Wrong button ID" );
269
+ return ;
270
+ }
271
+
272
+ AppEvent button_event;
273
+ button_event.Type = AppEvent::kEventType_Button ;
274
+ button_event.ButtonEvent .Pin = id == 0 ? LIGHTING_BUTTON : FUNCTION_BUTTON;
275
+ button_event.ButtonEvent .Action = pushed ? BUTTON_PUSH_EVENT : BUTTON_RELEASE_EVENT;
276
+
277
+ if (id == 0 )
278
+ {
279
+ button_event.Handler = LightingActionEventHandler;
280
+ }
281
+ else
282
+ {
283
+ button_event.Handler = FunctionHandler;
284
+ }
285
+
286
+ sAppTask .PostEvent (&button_event);
287
+ }
288
+
289
+ void AppTask::SliderEventHandler (int slider_pos)
290
+ {
291
+ AppEvent slider_event;
292
+ slider_event.Type = AppEvent::kEventType_Slider ;
293
+ slider_event.SliderEvent .Value = slider_pos;
294
+ slider_event.Handler = LightingActionEventHandler;
295
+ sAppTask .PostEvent (&slider_event);
296
+ }
297
+
251
298
void AppTask::ActionInitiated (LightingManager::Action_t aAction, int32_t aActor)
252
299
{
253
300
if (aAction == LightingManager::ON_ACTION)
0 commit comments