55
55
#define APP_TASK_PRIORITY 4
56
56
#define APP_EVENT_QUEUE_SIZE 10
57
57
58
+ #if (CHIP_CONFIG_ENABLE_ICD_SERVER == 1)
59
+ #define LED_ENABLE 0
60
+ #else
61
+ #define LED_ENABLE 1
62
+ #endif
63
+ #define BUTTON_ENABLE 1
64
+
58
65
using namespace ::chip;
59
66
using namespace ::chip::Credentials;
60
67
using namespace ::chip::DeviceLayer;
@@ -164,38 +171,9 @@ int AppTask::StartAppTask()
164
171
165
172
int AppTask::Init ()
166
173
{
167
- LED_Params ledParams;
168
- Button_Params buttonParams;
169
-
170
174
cc13xx_26xxLogInit ();
171
175
172
- // Initialize LEDs
173
- PLAT_LOG (" Initialize LEDs" );
174
- LED_init ();
175
-
176
- LED_Params_init (&ledParams); // default PWM LED
177
- sAppRedHandle = LED_open (CONFIG_LED_RED, &ledParams);
178
- LED_setOff (sAppRedHandle );
179
-
180
- LED_Params_init (&ledParams); // default PWM LED
181
- sAppGreenHandle = LED_open (CONFIG_LED_GREEN, &ledParams);
182
- LED_setOff (sAppGreenHandle );
183
-
184
- // Initialize buttons
185
- PLAT_LOG (" Initialize buttons" );
186
- Button_init ();
187
-
188
- Button_Params_init (&buttonParams);
189
- buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
190
- buttonParams.longPressDuration = 1000U ; // ms
191
- sAppLeftHandle = Button_open (CONFIG_BTN_LEFT, &buttonParams);
192
- Button_setCallback (sAppLeftHandle , ButtonLeftEventHandler);
193
-
194
- Button_Params_init (&buttonParams);
195
- buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
196
- buttonParams.longPressDuration = 1000U ; // ms
197
- sAppRightHandle = Button_open (CONFIG_BTN_RIGHT, &buttonParams);
198
- Button_setCallback (sAppRightHandle , ButtonRightEventHandler);
176
+ uiInit ();
199
177
200
178
// Init Chip memory management before the stack
201
179
Platform::MemoryInit ();
@@ -218,11 +196,12 @@ int AppTask::Init()
218
196
219
197
#if CHIP_DEVICE_CONFIG_THREAD_FTD
220
198
ret = ConnectivityMgr ().SetThreadDeviceType (ConnectivityManager::kThreadDeviceType_Router );
221
- #elif CONFIG_OPENTHREAD_MTD_SED
199
+ #elif CHIP_CONFIG_ENABLE_ICD_SERVER
222
200
ret = ConnectivityMgr ().SetThreadDeviceType (ConnectivityManager::kThreadDeviceType_SleepyEndDevice );
223
201
#else
224
202
ret = ConnectivityMgr ().SetThreadDeviceType (ConnectivityManager::kThreadDeviceType_MinimalEndDevice );
225
203
#endif
204
+
226
205
if (ret != CHIP_NO_ERROR)
227
206
{
228
207
PLAT_LOG (" ConnectivityMgr().SetThreadDeviceType() failed" );
@@ -312,46 +291,6 @@ void AppTask::PostEvent(const AppEvent * aEvent)
312
291
}
313
292
}
314
293
315
- void AppTask::ButtonLeftEventHandler (Button_Handle handle, Button_EventMask events)
316
- {
317
- AppEvent event;
318
- event.Type = AppEvent::kEventType_ButtonLeft ;
319
-
320
- if (events & Button_EV_CLICKED)
321
- {
322
- event.ButtonEvent .Type = AppEvent::kAppEventButtonType_Clicked ;
323
- }
324
- else if (events & Button_EV_LONGCLICKED)
325
- {
326
- event.ButtonEvent .Type = AppEvent::kAppEventButtonType_LongClicked ;
327
- }
328
- // button callbacks are in ISR context
329
- if (xQueueSendFromISR (sAppEventQueue , &event, NULL ) != pdPASS)
330
- {
331
- /* Failed to post the message */
332
- }
333
- }
334
-
335
- void AppTask::ButtonRightEventHandler (Button_Handle handle, Button_EventMask events)
336
- {
337
- AppEvent event;
338
- event.Type = AppEvent::kEventType_ButtonRight ;
339
-
340
- if (events & Button_EV_CLICKED)
341
- {
342
- event.ButtonEvent .Type = AppEvent::kAppEventButtonType_Clicked ;
343
- }
344
- else if (events & Button_EV_LONGCLICKED)
345
- {
346
- event.ButtonEvent .Type = AppEvent::kAppEventButtonType_LongClicked ;
347
- }
348
- // button callbacks are in ISR context
349
- if (xQueueSendFromISR (sAppEventQueue , &event, NULL ) != pdPASS)
350
- {
351
- /* Failed to post the message */
352
- }
353
- }
354
-
355
294
void AppTask::DispatchEvent (AppEvent * aEvent)
356
295
{
357
296
switch (aEvent->Type )
@@ -405,3 +344,85 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
405
344
break ;
406
345
}
407
346
}
347
+
348
+ #if (BUTTON_ENABLE == 1)
349
+ void AppTask::ButtonLeftEventHandler (Button_Handle handle, Button_EventMask events)
350
+ {
351
+ AppEvent event;
352
+ event.Type = AppEvent::kEventType_ButtonLeft ;
353
+
354
+ if (events & Button_EV_CLICKED)
355
+ {
356
+ event.ButtonEvent .Type = AppEvent::kAppEventButtonType_Clicked ;
357
+ }
358
+ else if (events & Button_EV_LONGCLICKED)
359
+ {
360
+ event.ButtonEvent .Type = AppEvent::kAppEventButtonType_LongClicked ;
361
+ }
362
+ // button callbacks are in ISR context
363
+ if (xQueueSendFromISR (sAppEventQueue , &event, NULL ) != pdPASS)
364
+ {
365
+ /* Failed to post the message */
366
+ }
367
+ }
368
+
369
+ void AppTask::ButtonRightEventHandler (Button_Handle handle, Button_EventMask events)
370
+ {
371
+ AppEvent event;
372
+ event.Type = AppEvent::kEventType_ButtonRight ;
373
+
374
+ if (events & Button_EV_CLICKED)
375
+ {
376
+ event.ButtonEvent .Type = AppEvent::kAppEventButtonType_Clicked ;
377
+ }
378
+ else if (events & Button_EV_LONGCLICKED)
379
+ {
380
+ event.ButtonEvent .Type = AppEvent::kAppEventButtonType_LongClicked ;
381
+ }
382
+ // button callbacks are in ISR context
383
+ if (xQueueSendFromISR (sAppEventQueue , &event, NULL ) != pdPASS)
384
+ {
385
+ /* Failed to post the message */
386
+ }
387
+ }
388
+ #endif // BUTTON_ENABLE
389
+
390
+ void AppTask::uiInit (void )
391
+ {
392
+ #if (LED_ENABLE == 1)
393
+
394
+ LED_Params ledParams;
395
+
396
+ // Initialize LEDs
397
+ PLAT_LOG (" Initialize LEDs" );
398
+ LED_init ();
399
+
400
+ LED_Params_init (&ledParams); // default PWM LED
401
+ sAppRedHandle = LED_open (CONFIG_LED_RED, &ledParams);
402
+ LED_setOff (sAppRedHandle );
403
+
404
+ LED_Params_init (&ledParams); // default PWM LED
405
+ sAppGreenHandle = LED_open (CONFIG_LED_GREEN, &ledParams);
406
+ LED_setOff (sAppGreenHandle );
407
+ #endif // LED ENABLE
408
+
409
+ #if (BUTTON_ENABLE == 1)
410
+ Button_Params buttonParams;
411
+
412
+ // Initialize buttons
413
+ PLAT_LOG (" Initialize buttons" );
414
+ Button_init ();
415
+
416
+ Button_Params_init (&buttonParams);
417
+ buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
418
+ buttonParams.longPressDuration = 1000U ; // ms
419
+ sAppLeftHandle = Button_open (CONFIG_BTN_LEFT, &buttonParams);
420
+ Button_setCallback (sAppLeftHandle , ButtonLeftEventHandler);
421
+
422
+ Button_Params_init (&buttonParams);
423
+ buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
424
+ buttonParams.longPressDuration = 1000U ; // ms
425
+ sAppRightHandle = Button_open (CONFIG_BTN_RIGHT, &buttonParams);
426
+ Button_setCallback (sAppRightHandle , ButtonRightEventHandler);
427
+ #endif // BUTTON ENABLE
428
+ }
0 commit comments