Skip to content

Commit

Permalink
Use a common main files accross All examples (#26342)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Oct 19, 2023
1 parent f895998 commit 1131312
Show file tree
Hide file tree
Showing 43 changed files with 170 additions and 698 deletions.
2 changes: 1 addition & 1 deletion examples/chef/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AppTask : public BaseApplication
* @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
*/
void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) override;
static void ButtonEventHandler(uint8_t button, uint8_t btnAction) override;

/**
* @brief Callback called by the identify-server when an identify command is received
Expand Down
16 changes: 8 additions & 8 deletions examples/chef/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

#include <assert.h>

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

Expand All @@ -49,7 +51,7 @@
#include <platform/CHIPDeviceLayer.h>

#define SYSTEM_STATE_LED 0
#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_FUNCTION_BUTTON 0

using namespace chip;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -123,6 +125,9 @@ AppTask AppTask::sAppTask;
CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
#endif

err = BaseApplication::Init(&gIdentify);
if (err != CHIP_NO_ERROR)
Expand Down Expand Up @@ -164,18 +169,13 @@ void AppTask::AppTaskMain(void * pvParameter)
}
}

void AppTask::ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction)
void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
{
if (buttonHandle == NULL)
{
return;
}

AppEvent button_event = {};
button_event.Type = AppEvent::kEventType_Button;
button_event.ButtonEvent.Action = btnAction;

if (buttonHandle == APP_FUNCTION_BUTTON)
if (button == APP_FUNCTION_BUTTON)
{
button_event.Handler = BaseApplication::ButtonHandler;
sAppTask.PostEvent(&button_event);
Expand Down
84 changes: 0 additions & 84 deletions examples/chef/efr32/src/main.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion examples/light-switch-app/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ silabs_executable("light_switch_app") {
sources = [
"${chip_root}/examples/light-switch-app/silabs/common/BindingHandler.cpp",
"${chip_root}/examples/light-switch-app/silabs/common/LightSwitchMgr.cpp",
"${examples_common_plat_dir}/main.cpp",
"src/AppTask.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]

deps = [
Expand Down
2 changes: 2 additions & 0 deletions examples/light-switch-app/silabs/SiWx917/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#define APP_TASK_NAME "Lit"

#define BLE_DEV_NAME "SiLabs-Light-Switch"

// Time it takes in ms for the simulated actuator to move from one
// state to another.
#define ACTUATOR_MOVEMENT_PERIOS_MS 10
Expand Down
5 changes: 5 additions & 0 deletions examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

#include <app/clusters/identify-server/identify-server.h>

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

/**********************************************************
* Defines and Constants
*********************************************************/
Expand Down Expand Up @@ -152,6 +154,9 @@ AppTask AppTask::sAppTask;
CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);

#ifdef DISPLAY_ENABLED
GetLCD().Init((uint8_t *) "Light Switch");
#endif
Expand Down
87 changes: 0 additions & 87 deletions examples/light-switch-app/silabs/SiWx917/src/main.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion examples/light-switch-app/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ silabs_executable("light_switch_app") {
sources = [
"${chip_root}/examples/light-switch-app/silabs/common/BindingHandler.cpp",
"${chip_root}/examples/light-switch-app/silabs/common/LightSwitchMgr.cpp",
"${examples_common_plat_dir}/main.cpp",
"src/AppTask.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]

deps = [
Expand Down
2 changes: 2 additions & 0 deletions examples/light-switch-app/silabs/efr32/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#define APP_TASK_NAME "Lit"

#define BLE_DEV_NAME "SiLabs-Light-Switch"

// Time it takes in ms for the simulated actuator to move from one
// state to another.
#define ACTUATOR_MOVEMENT_PERIOS_MS 10
Expand Down
2 changes: 1 addition & 1 deletion examples/light-switch-app/silabs/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AppTask : public BaseApplication
* @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
*/
void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) override;
static void ButtonEventHandler(uint8_t button, uint8_t btnAction);

/**
* @brief Callback called by the identify-server when an identify command is received
Expand Down
18 changes: 11 additions & 7 deletions examples/light-switch-app/silabs/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@

#include <app/clusters/identify-server/identify-server.h>

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

/**********************************************************
* Defines and Constants
*********************************************************/

#define SYSTEM_STATE_LED &sl_led_led0

#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_LIGHT_SWITCH &sl_button_btn1
#define APP_FUNCTION_BUTTON 0
#define APP_LIGHT_SWITCH 1

namespace {

Expand Down Expand Up @@ -151,6 +153,10 @@ AppTask AppTask::sAppTask;
CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
#endif

#ifdef DISPLAY_ENABLED
GetLCD().Init((uint8_t *) "Light Switch");
#endif
Expand Down Expand Up @@ -248,20 +254,18 @@ void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
}
}

void AppTask::ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction)
void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
{
VerifyOrReturn(buttonHandle != NULL);

AppEvent button_event = {};
button_event.Type = AppEvent::kEventType_Button;
button_event.ButtonEvent.Action = btnAction;

if (buttonHandle == APP_LIGHT_SWITCH)
if (button == APP_LIGHT_SWITCH)
{
button_event.Handler = SwitchActionEventHandler;
sAppTask.PostEvent(&button_event);
}
else if (buttonHandle == APP_FUNCTION_BUTTON)
else if (button == APP_FUNCTION_BUTTON)
{
button_event.Handler = BaseApplication::ButtonHandler;
sAppTask.PostEvent(&button_event);
Expand Down
Loading

0 comments on commit 1131312

Please sign in to comment.