Skip to content

Commit

Permalink
Complete AppTask update (#21605)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Jan 16, 2024
1 parent d4ae4ac commit 4430546
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 946 deletions.
1 change: 1 addition & 0 deletions examples/chef/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ efr32_executable("chef_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
115 changes: 71 additions & 44 deletions examples/chef/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,27 @@

#pragma once

/**********************************************************
* Includes
*********************************************************/

#include <stdbool.h>
#include <stdint.h>

#include "AppEvent.h"
#include "LightingManager.h"
#include "sl_simple_button_instances.h"

#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "sl_simple_button_instances.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
#include <ble/BLEEndPoint.h>
#include <lib/core/CHIPError.h>
#include <platform/CHIPDeviceLayer.h>

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

// 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,57 +48,75 @@
#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();
AppTask() = default;

static AppTask & GetAppTask() { return sAppTask; }

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

void PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction);
void PostEvent(const AppEvent * event);
CHIP_ERROR StartAppTask();

void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction);
/**
* @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);

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

/**
* @brief AppTask initialisation function
*
* @return CHIP_ERROR
*/
CHIP_ERROR Init();

static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(LightingManager::Action_t aAction);

void CancelTimer(void);

void DispatchEvent(AppEvent * event);

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
/**
* @brief PB0 Button event processing function
* Press and hold will trigger a factory reset timer start
* Press and release will restart BLEAdvertising if not commisionned
*
* @param aEvent button event being processed
*/
static void ButtonHandler(AppEvent * aEvent);

/**
* @brief PB1 Button event processing function
* Function triggers a switch action sent to the CHIP task
*
* @param aEvent button event being processed
*/
static void SwitchActionEventHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);

static void UpdateClusterState(void);

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;
bool mSyncClusterToButtonAction;

static AppTask sAppTask;
};

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

0 comments on commit 4430546

Please sign in to comment.