Skip to content

Commit

Permalink
[EFR32] Cleanup AppTask part 1 (#21551)
Browse files Browse the repository at this point in the history
* Refactor light-switch

* Update Lighting-app

* Update Lock-app

* Apply PR comments
  • Loading branch information
jepenven-silabs authored Aug 3, 2022
1 parent a494b1c commit 63ad9f7
Show file tree
Hide file tree
Showing 17 changed files with 919 additions and 1,341 deletions.
1 change: 1 addition & 0 deletions examples/light-switch-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ efr32_executable("light_switch_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
114 changes: 7 additions & 107 deletions examples/light-switch-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdint.h>

#include "AppEvent.h"
#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "sl_simple_button_instances.h"
#include "timers.h" // provides FreeRTOS timer support
Expand All @@ -51,21 +52,13 @@
* AppTask Declaration
*********************************************************/

class AppTask
class AppTask : public BaseApplication
{

public:
/**********************************************************
* Public Function Declaration
*********************************************************/
AppTask() = default;

/**
* @brief Create AppTask task and Event Queue
* If an error occurs during creation, application will hang after printing out error code
*
* @return CHIP_ERROR CHIP_NO_ERROR if no errors
*/
CHIP_ERROR StartAppTask();
static AppTask & GetAppTask() { return sAppTask; }

/**
* @brief AppTask task main loop function
Expand All @@ -74,12 +67,7 @@ class AppTask
*/
static void AppTaskMain(void * pvParameter);

/**
* @brief PostEvent function that add event to AppTask queue for processing
*
* @param event AppEvent to post
*/
void PostEvent(const AppEvent * event);
CHIP_ERROR StartAppTask();

/**
* @brief Event handler when a button is pressed
Expand All @@ -89,7 +77,7 @@ class AppTask
* @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);
void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) override;

/**
* @brief Callback called by the identify-server when an identify command is received
Expand All @@ -105,23 +93,8 @@ class AppTask
*/
static void OnIdentifyStop(Identify * identify);

/**
* @brief Function called to start the LED light timer
*/
void StartLightTimer(void);

/**
* @brief Function to stop LED light timer
* Turns off Status LED before stopping timer
*/
void CancelLightTimer(void);

private:
/**********************************************************
* Private Function Declaration
*********************************************************/

friend AppTask & GetAppTask(void);
static AppTask sAppTask;

/**
* @brief AppTask initialisation function
Expand All @@ -130,41 +103,6 @@ class AppTask
*/
CHIP_ERROR Init();

/**
* @brief Function called to start the function timer
*
* @param aTimeoutMs timer duration in ms
*/
void StartFunctionTimer(uint32_t aTimeoutMs);

/**
* @brief Function to stop function timer
*/
void CancelFunctionTimer(void);

/**
* @brief Function call event callback function for processing
*
* @param event triggered event to be processed
*/
void DispatchEvent(AppEvent * event);

/**
* @brief Function Timer finished callback function
* Post an FunctionEventHandler event
*
* @param xTimer timer that finished
*/
static void FunctionTimerEventHandler(TimerHandle_t xTimer);

/**
* @brief Timer Event processing function
* Trigger factory if Press and Hold duration is respected
*
* @param aEvent post event being processed
*/
static void FunctionEventHandler(AppEvent * aEvent);

/**
* @brief PB0 Button event processing function
* Press and hold will trigger a factory reset timer start
Expand All @@ -181,42 +119,4 @@ class AppTask
* @param aEvent button event being processed
*/
static void SwitchActionEventHandler(AppEvent * aEvent);

/**
* @brief Light Timer finished callback function
* Calls LED processing function
*
* @param xTimer timer that finished
*/
static void LightTimerEventHandler(TimerHandle_t xTimer);

/**
* @brief Updates device LEDs
*/
static void LightEventHandler();

/**********************************************************
* Private Attributes declaration
*********************************************************/

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

kFunction_Invalid
} Function;

Function_t mFunction;
bool mFunctionTimerActive;
bool mSyncClusterToButtonAction;

static AppTask sAppTask;
};

inline AppTask & GetAppTask(void)
{
return AppTask::sAppTask;
}
Loading

0 comments on commit 63ad9f7

Please sign in to comment.