Skip to content

Commit

Permalink
Pull request #97: Refactoring of onoffplug app to use the BaseApplica…
Browse files Browse the repository at this point in the history
…tion files

Merge in WMN_TOOLS/matter from MATTER-753-refactor-onoff-plug-apptask-to-inherit-from-base-application to silabs

Squashed commit of the following:

commit 2d4848a34b9eb516734b3be0494e82ace7f1318f
Author: Louis-Philip Béliveau <lobelive@0018239.silabs.com>
Date:   Wed Sep 14 10:56:37 2022 -0400

    Refactoring of onoffplug app to use the BaseApplication files
  • Loading branch information
lpbeliveau-silabs authored and jmartinez-silabs committed Feb 15, 2023
1 parent c79be9a commit b0e2169
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 420 deletions.
1 change: 1 addition & 0 deletions silabs_examples/onoff-plug-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ efr32_executable("onoff_plug_app") {
defines = []

sources = [
"${examples_plat_dir}/BaseApplication.cpp",
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/efr32_utils.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
Expand Down
93 changes: 56 additions & 37 deletions silabs_examples/onoff-plug-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@
#include <stdint.h>

#include "AppEvent.h"
#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "OnOffPlugManager.h"
#include "sl_simple_button_instances.h"

#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <ble/BLEEndPoint.h>
#include <platform/CHIPDeviceLayer.h>

/**********************************************************
* Defines
*********************************************************/

// Application-defined error codes in the CHIP_ERROR space.

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
Expand All @@ -39,53 +45,66 @@
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

class AppTask
/**********************************************************
* AppTask Declaration
*********************************************************/
class AppTask : public BaseApplication
{

public:
CHIP_ERROR StartAppTask();
static void AppTaskMain(void * pvParameter);

void PostEvent(const AppEvent * event);
void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction);
AppTask() = default;

private:
friend AppTask & GetAppTask(void);
static AppTask & GetAppTask() { return sAppTask; }

CHIP_ERROR Init();
/**
* @brief AppTask task main loop function
*
* @param pvParameter FreeRTOS task parameter
*/
static void AppTaskMain(void * pvParameter);

static void ApplyAction(OnOffPlugManager::Action_t aAction, int32_t aActor);
CHIP_ERROR StartAppTask();

void CancelTimer(void);
/**
* @brief Event handler when a button is pressed
* Function posts an event for button processing
*
* @param buttonHandle APP_LIGHT_SWITCH or APP_FUNCTION_BUTTON
* @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;

/**
* @brief Callback called by the identify-server when an identify command is received
*
* @param identify identify structure the command applies on
*/
static void OnIdentifyStart(Identify * identify);

/**
* @brief Callback called by the identify-server when an identify command is stopped or finished
*
* @param identify identify structure the command applies on
*/
static void OnIdentifyStop(Identify * identify);

void DispatchEvent(AppEvent * event);
private:
static AppTask sAppTask;

static void OnOffButtonHandler(AppEvent * aEvent);
static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);
static void ActionInitiated(OnOffPlugManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(OnOffPlugManager::Action_t aAction);
static void OnOffActionEventHandler(AppEvent * aEvent);

static void UpdateClusterState(intptr_t context);

void StartTimer(uint32_t aTimeoutMs);

enum Function_t
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_StartBleAdv = 1,
kFunction_FactoryReset = 2,

kFunction_Invalid
} Function;

Function_t mFunction;
bool mFunctionTimerActive;
/**
* @brief AppTask initialisation function
*
* @return CHIP_ERROR
*/
CHIP_ERROR Init();

static AppTask sAppTask;
static void TimerEventHandler(TimerHandle_t xTimer);
};

inline AppTask & GetAppTask(void)
{
return AppTask::sAppTask;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ class OnOffPlugManager
void SetAutoTurnOffDuration(uint32_t aDurationInSecs);
bool InitiateAction(int32_t aActor, Action_t aAction);

typedef void (*Callback_fn_apply)(Action_t, int32_t aActor);
void SetCallbacks(Callback_fn_apply mApplyAction_CB);
typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor);
typedef void (*Callback_fn_completed)(Action_t);
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);

static void OnTriggerOffWithEffect(OnOffEffect * effect);

private:
friend OnOffPlugManager & PlugMgr(void);

Callback_fn_apply mApplyAction_CB;
Callback_fn_initiated mActionInitiated_CB;
Callback_fn_completed mActionCompleted_CB;

bool mIsOn;
bool mAutoTurnOff;
Expand Down
Loading

0 comments on commit b0e2169

Please sign in to comment.