Skip to content

Commit 1182560

Browse files
jepenven-silabspull[bot]
authored andcommitted
Complete Button Abstraction (#26581)
1 parent 700c109 commit 1182560

File tree

14 files changed

+46
-63
lines changed

14 files changed

+46
-63
lines changed

examples/chef/efr32/src/AppTask.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ AppTask AppTask::sAppTask;
125125
CHIP_ERROR AppTask::Init()
126126
{
127127
CHIP_ERROR err = CHIP_NO_ERROR;
128-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
129128
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
130-
#endif
131129

132130
err = BaseApplication::Init(&gIdentify);
133131
if (err != CHIP_NO_ERROR)
@@ -169,7 +167,6 @@ void AppTask::AppTaskMain(void * pvParameter)
169167
}
170168
}
171169

172-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
173170
void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
174171
{
175172
AppEvent button_event = {};
@@ -182,4 +179,3 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
182179
sAppTask.PostEvent(&button_event);
183180
}
184181
}
185-
#endif // SL_CATALOG_SIMPLE_BUTTON_PRESENT

examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ constexpr chip::EndpointId kGenericSwitchEndpoint = 2;
6969

7070
using namespace chip;
7171
using namespace ::chip::DeviceLayer;
72+
using namespace ::chip::DeviceLayer::Silabs;
7273

7374
namespace {
7475

@@ -239,7 +240,7 @@ void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
239240

240241
static bool mCurrentButtonState = false;
241242

242-
if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_PRESSED)
243+
if (aEvent->ButtonEvent.Action == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
243244
{
244245
mCurrentButtonState = !mCurrentButtonState;
245246
LightSwitchMgr::LightSwitchAction action =
@@ -252,7 +253,7 @@ void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
252253
sAppTask.GetLCD().WriteDemoUI(mCurrentButtonState);
253254
#endif
254255
}
255-
else if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_RELEASED)
256+
else if (aEvent->ButtonEvent.Action == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonReleased))
256257
{
257258
LightSwitchMgr::GetInstance().GenericSwitchOnShortRelease();
258259
}
@@ -268,7 +269,7 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
268269
button_event.Handler = SwitchActionEventHandler;
269270
sAppTask.PostEvent(&button_event);
270271
}
271-
else if (button == SIWx917_BTN0 && btnAction == SL_SIMPLE_BUTTON_PRESSED)
272+
else if (button == SIWx917_BTN0 && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
272273
{
273274
button_event.Handler = BaseApplication::ButtonHandler;
274275
sAppTask.PostEvent(&button_event);

examples/light-switch-app/silabs/efr32/src/AppTask.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ constexpr chip::EndpointId kGenericSwitchEndpoint = 2;
6868

6969
using namespace chip;
7070
using namespace ::chip::DeviceLayer;
71+
using namespace ::chip::DeviceLayer::Silabs;
7172

7273
namespace {
7374

@@ -153,9 +154,7 @@ AppTask AppTask::sAppTask;
153154
CHIP_ERROR AppTask::Init()
154155
{
155156
CHIP_ERROR err = CHIP_NO_ERROR;
156-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
157157
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
158-
#endif
159158

160159
#ifdef DISPLAY_ENABLED
161160
GetLCD().Init((uint8_t *) "Light Switch");
@@ -229,14 +228,13 @@ void AppTask::OnIdentifyStop(Identify * identify)
229228
#endif
230229
}
231230

232-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
233231
void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
234232
{
235233
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_Button);
236234

237235
static bool mCurrentButtonState = false;
238236

239-
if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_PRESSED)
237+
if (aEvent->ButtonEvent.Action == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
240238
{
241239
mCurrentButtonState = !mCurrentButtonState;
242240
LightSwitchMgr::LightSwitchAction action =
@@ -249,7 +247,7 @@ void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
249247
sAppTask.GetLCD().WriteDemoUI(mCurrentButtonState);
250248
#endif
251249
}
252-
else if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_RELEASED)
250+
else if (aEvent->ButtonEvent.Action == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonReleased))
253251
{
254252
LightSwitchMgr::GetInstance().GenericSwitchOnShortRelease();
255253
}
@@ -272,4 +270,3 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
272270
sAppTask.PostEvent(&button_event);
273271
}
274272
}
275-
#endif // SL_CATALOG_SIMPLE_BUTTON_PRESENT

examples/lighting-app/silabs/SiWx917/src/AppTask.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
using namespace chip;
4545
using namespace ::chip::DeviceLayer;
46+
using namespace ::chip::DeviceLayer::Silabs;
4647

4748
namespace {
4849

@@ -240,12 +241,12 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
240241
AppEvent button_event = {};
241242
button_event.Type = AppEvent::kEventType_Button;
242243
button_event.ButtonEvent.Action = btnAction;
243-
if (button == SIWx917_BTN1 && btnAction == SL_SIMPLE_BUTTON_PRESSED)
244+
if (button == SIWx917_BTN1 && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
244245
{
245246
button_event.Handler = LightActionEventHandler;
246247
sAppTask.PostEvent(&button_event);
247248
}
248-
else if (button == SIWx917_BTN0 && btnAction == SL_SIMPLE_BUTTON_PRESSED)
249+
else if (button == SIWx917_BTN0 && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
249250
{
250251
button_event.Handler = BaseApplication::ButtonHandler;
251252
sAppTask.PostEvent(&button_event);

examples/lighting-app/silabs/efr32/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class AppTask : public BaseApplication
6868
static void AppTaskMain(void * pvParameter);
6969

7070
CHIP_ERROR StartAppTask();
71-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
71+
7272
/**
7373
* @brief Event handler when a button is pressed
7474
* Function posts an event for button processing
@@ -78,7 +78,7 @@ class AppTask : public BaseApplication
7878
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
7979
*/
8080
static void ButtonEventHandler(uint8_t button, uint8_t btnAction);
81-
#endif
81+
8282
/**
8383
* @brief Callback called by the identify-server when an identify command is received
8484
*

examples/lighting-app/silabs/efr32/src/AppTask.cpp

100755100644
+5-14
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@
4646
#define LIGHT_LED 0
4747
#endif
4848

49-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
50-
5149
#define APP_FUNCTION_BUTTON 0
5250
#define APP_LIGHT_SWITCH 1
53-
#endif
5451

5552
using namespace chip;
5653
using namespace ::chip::DeviceLayer;
54+
using namespace ::chip::DeviceLayer::Silabs;
5755

5856
namespace {
5957

@@ -132,9 +130,7 @@ AppTask AppTask::sAppTask;
132130
CHIP_ERROR AppTask::Init()
133131
{
134132
CHIP_ERROR err = CHIP_NO_ERROR;
135-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
136133
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
137-
#endif
138134

139135
#ifdef DISPLAY_ENABLED
140136
GetLCD().Init((uint8_t *) "Lighting-App");
@@ -241,13 +237,11 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
241237
action = static_cast<LightingManager::Action_t>(aEvent->LightEvent.Action);
242238
actor = aEvent->LightEvent.Actor;
243239
}
244-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
245240
else if (aEvent->Type == AppEvent::kEventType_Button)
246241
{
247242
action = (LightMgr().IsLightOn()) ? LightingManager::OFF_ACTION : LightingManager::ON_ACTION;
248243
actor = AppEvent::kEventType_Button;
249244
}
250-
#endif
251245
else
252246
{
253247
err = APP_ERROR_UNHANDLED_EVENT;
@@ -263,14 +257,14 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
263257
}
264258
}
265259
}
266-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
260+
267261
void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
268262
{
269263
AppEvent button_event = {};
270264
button_event.Type = AppEvent::kEventType_Button;
271265
button_event.ButtonEvent.Action = btnAction;
272266

273-
if (button == APP_LIGHT_SWITCH && btnAction == SL_SIMPLE_BUTTON_PRESSED)
267+
if (button == APP_LIGHT_SWITCH && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
274268
{
275269
button_event.Handler = LightActionEventHandler;
276270
AppTask::GetAppTask().PostEvent(&button_event);
@@ -281,7 +275,6 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
281275
AppTask::GetAppTask().PostEvent(&button_event);
282276
}
283277
}
284-
#endif
285278

286279
void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
287280
{
@@ -294,12 +287,11 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
294287
#ifdef DISPLAY_ENABLED
295288
sAppTask.GetLCD().WriteDemoUI(lightOn);
296289
#endif
297-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
290+
298291
if (aActor == AppEvent::kEventType_Button)
299292
{
300293
sAppTask.mSyncClusterToButtonAction = true;
301294
}
302-
#endif
303295
}
304296

305297
void AppTask::ActionCompleted(LightingManager::Action_t aAction)
@@ -313,13 +305,12 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction)
313305
{
314306
SILABS_LOG("Light OFF")
315307
}
316-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
308+
317309
if (sAppTask.mSyncClusterToButtonAction)
318310
{
319311
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));
320312
sAppTask.mSyncClusterToButtonAction = false;
321313
}
322-
#endif
323314
}
324315

325316
void AppTask::PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction)

examples/lock-app/silabs/SiWx917/src/AppTask.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ using chip::app::Clusters::DoorLock::OperationSourceEnum;
6161

6262
using namespace chip;
6363
using namespace ::chip::DeviceLayer;
64+
using namespace ::chip::DeviceLayer::Silabs;
6465
using namespace ::chip::DeviceLayer::Internal;
6566
using namespace SI917DoorLock::LockInitParams;
6667

@@ -348,12 +349,12 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
348349
button_event.Type = AppEvent::kEventType_Button;
349350
button_event.ButtonEvent.Action = btnAction;
350351

351-
if (button == SIWx917_BTN1 && btnAction == SL_SIMPLE_BUTTON_PRESSED)
352+
if (button == SIWx917_BTN1 && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
352353
{
353354
button_event.Handler = LockActionEventHandler;
354355
sAppTask.PostEvent(&button_event);
355356
}
356-
else if (button == SIWx917_BTN0 && btnAction == SL_SIMPLE_BUTTON_PRESSED)
357+
else if (button == SIWx917_BTN0 && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
357358
{
358359
button_event.Handler = BaseApplication::ButtonHandler;
359360
sAppTask.PostEvent(&button_event);

examples/lock-app/silabs/efr32/src/AppTask.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ using chip::app::Clusters::DoorLock::OperationSourceEnum;
6464

6565
using namespace chip;
6666
using namespace ::chip::DeviceLayer;
67+
using namespace ::chip::DeviceLayer::Silabs;
6768
using namespace ::chip::DeviceLayer::Internal;
6869
using namespace EFR32DoorLock::LockInitParams;
6970

@@ -143,9 +144,7 @@ CHIP_ERROR AppTask::Init()
143144
{
144145
CHIP_ERROR err = CHIP_NO_ERROR;
145146

146-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
147147
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
148-
#endif // SL_CATALOG_SIMPLE_BUTTON_PRESENT
149148

150149
#ifdef DISPLAY_ENABLED
151150
GetLCD().Init((uint8_t *) "Lock-App", true);
@@ -361,14 +360,13 @@ void AppTask::LockActionEventHandler(AppEvent * aEvent)
361360
}
362361
}
363362

364-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
365363
void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
366364
{
367365
AppEvent button_event = {};
368366
button_event.Type = AppEvent::kEventType_Button;
369367
button_event.ButtonEvent.Action = btnAction;
370368

371-
if (button == APP_LOCK_SWITCH && btnAction == SL_SIMPLE_BUTTON_PRESSED)
369+
if (button == APP_LOCK_SWITCH && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
372370
{
373371
button_event.Handler = LockActionEventHandler;
374372
sAppTask.PostEvent(&button_event);
@@ -379,7 +377,6 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
379377
sAppTask.PostEvent(&button_event);
380378
}
381379
}
382-
#endif // SL_CATALOG_SIMPLE_BUTTON_PRESENT
383380

384381
void AppTask::ActionInitiated(LockManager::Action_t aAction, int32_t aActor)
385382
{

examples/platform/silabs/SiWx917/BaseApplication.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
4848
#include <setup_payload/SetupPayload.h>
4949

50+
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
51+
5052
#ifdef SL_WIFI
5153
#include "wfx_host_events.h"
5254
#include <app/clusters/network-commissioning/network-commissioning.h>
@@ -70,6 +72,7 @@
7072

7173
using namespace chip;
7274
using namespace ::chip::DeviceLayer;
75+
using namespace ::chip::DeviceLayer::Silabs;
7376

7477
namespace {
7578

@@ -355,7 +358,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
355358
// FACTORY_RESET_TRIGGER_TIMEOUT to signal factory reset has been initiated.
356359
// To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs
357360
// start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT
358-
if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_PRESSED)
361+
if (aEvent->ButtonEvent.Action == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
359362
{
360363
if ((!mFunctionTimerActive) && (mFunction == kFunction_NoneSelected))
361364
{

examples/platform/silabs/efr32/BaseApplication.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include <platform/silabs/ThreadStackManagerImpl.h>
5454
#endif // CHIP_ENABLE_OPENTHREAD
5555

56+
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
57+
5658
#ifdef SL_WIFI
5759
#include "wfx_host_events.h"
5860
#include <app/clusters/network-commissioning/network-commissioning.h>
@@ -75,12 +77,11 @@
7577
#if defined(ENABLE_WSTK_LEDS) && defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT)
7678
#define SYSTEM_STATE_LED 0
7779
#endif // ENABLE_WSTK_LEDS
78-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
7980
#define APP_FUNCTION_BUTTON 0
80-
#endif
8181

8282
using namespace chip;
8383
using namespace ::chip::DeviceLayer;
84+
using namespace ::chip::DeviceLayer::Silabs;
8485

8586
namespace {
8687

@@ -397,7 +398,7 @@ void BaseApplication::LightEventHandler()
397398
sStatusLED.Animate();
398399
#endif // ENABLE_WSTK_LEDS
399400
}
400-
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
401+
401402
void BaseApplication::ButtonHandler(AppEvent * aEvent)
402403
{
403404
// To trigger software update: press the APP_FUNCTION_BUTTON button briefly (<
@@ -407,7 +408,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
407408
// FACTORY_RESET_TRIGGER_TIMEOUT to signal factory reset has been initiated.
408409
// To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs
409410
// start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT
410-
if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_PRESSED)
411+
if (aEvent->ButtonEvent.Action == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
411412
{
412413
if (!mFunctionTimerActive && mFunction == kFunction_NoneSelected)
413414
{
@@ -444,10 +445,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
444445
SILABS_LOG("Failed to open the Basic Commissioning Window");
445446
}
446447
}
447-
else
448-
{
449-
SILABS_LOG("Network is already provisioned, Ble advertissement not enabled");
450-
}
448+
else { SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); }
451449
}
452450
else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset)
453451
{
@@ -464,7 +462,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
464462
}
465463
}
466464
}
467-
#endif
465+
468466
void BaseApplication::CancelFunctionTimer()
469467
{
470468
if (xTimerStop(sFunctionTimer, pdMS_TO_TICKS(0)) == pdFAIL)

0 commit comments

Comments
 (0)