Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/lighting-app/silabs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ silabs_executable("lighting_app") {
"${examples_common_plat_dir}/main.cpp",
"src/AppTask.cpp",
"src/DataModelCallbacks.cpp",
"src/LightingManager.cpp",
]

deps = [
Expand Down
70 changes: 45 additions & 25 deletions examples/lighting-app/silabs/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#endif //(defined(SL_MATTER_RGB_LED_ENABLED) && SL_MATTER_RGB_LED_ENABLED == 1)
#include "AppEvent.h"
#include "BaseApplication.h"
#include "LightingManager.h"
#include "LightTypes.h"

#include <app/clusters/on-off-server/on-off-server.h>
#include <app/persistence/DeferredAttributePersistenceProvider.h>
#include <ble/Ble.h>
#include <cmsis_os2.h>
Expand Down Expand Up @@ -60,7 +61,7 @@ class AppTask : public BaseApplication
public:
AppTask() = default;

static AppTask & GetAppTask() { return sAppTask; }
static AppTask & GetAppTask();

/**
* @brief AppTask task main loop function
Expand All @@ -85,40 +86,59 @@ class AppTask : public BaseApplication
void PostLightControlActionRequest(int32_t aActor, LightingManager::Action_t aAction, RGBLEDWidget::ColorData_t * aValue);
#endif // (defined(SL_MATTER_RGB_LED_ENABLED) && SL_MATTER_RGB_LED_ENABLED)

private:
static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor, uint8_t * value);
static void ActionCompleted(LightingManager::Action_t aAction);
CHIP_ERROR InitLight();
bool IsLightOn() const;
void EnableAutoTurnOff(bool aOn);
void SetAutoTurnOffDuration(uint32_t aDurationInSecs);
bool IsActionInProgress() const;
bool InitiateAction(int32_t aActor, LightingManager::Action_t aAction, uint8_t * aValue);
#if (defined(SL_MATTER_RGB_LED_ENABLED) && SL_MATTER_RGB_LED_ENABLED == 1)
bool InitiateLightCtrlAction(int32_t aActor, LightingManager::Action_t aAction, uint32_t aAttributeId, uint8_t * value);
#endif
static void OnTriggerOffWithEffect(OnOffEffect * effect);

protected:
virtual void OnLightActionInitiated(LightingManager::Action_t aAction, int32_t aActor, uint8_t * aValue);
virtual void OnLightActionCompleted(LightingManager::Action_t aAction);
virtual void StartLightTimer(uint32_t aTimeoutMs);
virtual void CancelLightTimer();
static void LightTimerEventHandler(void * timerCbArg);
static void AutoTurnOffTimerEventHandler(AppEvent * aEvent);
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
static void OffEffectTimerEventHandler(AppEvent * aEvent);

static void LightActionEventHandler(AppEvent * aEvent);
#if (defined(SL_MATTER_RGB_LED_ENABLED) && SL_MATTER_RGB_LED_ENABLED == 1)
static void LightControlEventHandler(AppEvent * aEvent);
#endif // (defined(SL_MATTER_RGB_LED_ENABLED) && SL_MATTER_RGB_LED_ENABLED)

static void UpdateClusterState(intptr_t context);

/**
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
*
* @return CHIP_ERROR
*/
CHIP_ERROR AppInit() override;

/**
* @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 AppTask sAppTask;
private:
chip::app::DeferredAttributePersistenceProvider * pDeferredAttributePersister = nullptr;

LightingManager::State_t mLightState;
uint8_t mCurrentLevel = 254;
#if (defined(SL_MATTER_RGB_LED_ENABLED) && SL_MATTER_RGB_LED_ENABLED == 1)
uint8_t mCurrentHue = 0;
uint8_t mCurrentSaturation = 0;
uint16_t mCurrentX = 0;
uint16_t mCurrentY = 0;
uint16_t mCurrentCTMireds = 250;
#endif
bool mAutoTurnOff = false;
uint32_t mAutoTurnOffDuration = 0;
bool mAutoTurnOffTimerArmed = false;
bool mOffEffectArmed = false;
osTimerId_t mLightTimer = nullptr;
};

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