Skip to content

Commit

Permalink
[Silabs] Consolidated Identify callback implementation to common file (
Browse files Browse the repository at this point in the history
…#26928)

* Fix identify server callbacks in silabs app. Move app code to the common BaseApplication. (lighting-app done)

* Remove identify callbacks implementation from the remaining silabs appTask.cpp

* remove invalid cast on qpg platform
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Nov 13, 2023
1 parent 43f4ae7 commit 3023645
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 576 deletions.
15 changes: 0 additions & 15 deletions examples/chef/silabs/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "BaseApplication.h"
#include "FreeRTOS.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>
Expand Down Expand Up @@ -78,20 +77,6 @@ class AppTask : public BaseApplication
*/
static void ButtonEventHandler(uint8_t button, 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:
static AppTask sAppTask;

Expand Down
67 changes: 1 addition & 66 deletions examples/chef/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
#include <app/util/attribute-storage.h>
#include <app/util/config.h>

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

#include <assert.h>

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
Expand All @@ -57,67 +53,6 @@ using namespace chip;
using namespace chip::app;
using namespace ::chip::DeviceLayer;

namespace {

#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
Clusters::Identify::EffectIdentifierEnum sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;
#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER

namespace {
#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState)
{
sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;
}
#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER
} // namespace

#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
void OnTriggerIdentifyEffect(Identify * identify)
{
sIdentifyEffect = identify->mCurrentEffectIdentifier;

if (identify->mCurrentEffectIdentifier == Clusters::Identify::EffectIdentifierEnum::kChannelChange)
{
ChipLogProgress(Zcl, "IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE - Not supported, use effect varriant %d",
to_underlying(identify->mEffectVariant));
sIdentifyEffect = static_cast<Clusters::Identify::EffectIdentifierEnum>(identify->mEffectVariant);
}

switch (sIdentifyEffect)
{
case Clusters::Identify::EffectIdentifierEnum::kBlink:
case Clusters::Identify::EffectIdentifierEnum::kBreathe:
case Clusters::Identify::EffectIdentifierEnum::kOkay:
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted,
identify);
break;
case Clusters::Identify::EffectIdentifierEnum::kFinishEffect:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted,
identify);
break;
case Clusters::Identify::EffectIdentifierEnum::kStopEffect:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;
break;
default:
ChipLogProgress(Zcl, "No identifier effect");
}
}
#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER

#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
Identify gIdentify = {
chip::EndpointId{ 1 },
[](Identify *) { ChipLogProgress(Zcl, "onIdentifyStart"); },
[](Identify *) { ChipLogProgress(Zcl, "onIdentifyStop"); },
Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator,
OnTriggerIdentifyEffect,
};
#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER

} // namespace
using namespace chip::TLV;
using namespace ::chip::DeviceLayer;

Expand All @@ -128,7 +63,7 @@ CHIP_ERROR AppTask::Init()
CHIP_ERROR err = CHIP_NO_ERROR;
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);

err = BaseApplication::Init(&gIdentify);
err = BaseApplication::Init();
if (err != CHIP_NO_ERROR)
{
SILABS_LOG("BaseApplication::Init() failed");
Expand Down
15 changes: 0 additions & 15 deletions examples/light-switch-app/silabs/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "BaseApplication.h"
#include "FreeRTOS.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>
Expand Down Expand Up @@ -78,20 +77,6 @@ class AppTask : public BaseApplication
*/
static void ButtonEventHandler(uint8_t button, uint8_t btnAction);

/**
* @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:
static AppTask sAppTask;

Expand Down
96 changes: 1 addition & 95 deletions examples/light-switch-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

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

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

/**********************************************************
Expand All @@ -60,89 +58,15 @@
#define APP_LIGHT_SWITCH 1

namespace {

constexpr chip::EndpointId kLightSwitchEndpoint = 1;
constexpr chip::EndpointId kGenericSwitchEndpoint = 2;

} // namespace

using namespace chip;
using namespace chip::app;
using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Silabs;

namespace {

/**********************************************************
* Variable declarations
*********************************************************/

Clusters::Identify::EffectIdentifierEnum sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;

/**********************************************************
* Identify Callbacks
*********************************************************/

namespace {
void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState)
{
ChipLogProgress(Zcl, "Trigger Identify Complete");
sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
AppTask::GetAppTask().StopStatusLEDTimer();
#endif
}
} // namespace

void OnTriggerIdentifyEffect(Identify * identify)
{
ChipLogProgress(Zcl, "Trigger Identify Effect");
sIdentifyEffect = identify->mCurrentEffectIdentifier;

if (identify->mCurrentEffectIdentifier == Clusters::Identify::EffectIdentifierEnum::kChannelChange)
{
ChipLogProgress(Zcl, "IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE - Not supported, use effect varriant %d",
to_underlying(identify->mEffectVariant));
sIdentifyEffect = static_cast<Clusters::Identify::EffectIdentifierEnum>(identify->mEffectVariant);
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
AppTask::GetAppTask().StartStatusLEDTimer();
#endif

switch (sIdentifyEffect)
{
case Clusters::Identify::EffectIdentifierEnum::kBlink:
case Clusters::Identify::EffectIdentifierEnum::kBreathe:
case Clusters::Identify::EffectIdentifierEnum::kOkay:
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted,
identify);
break;
case Clusters::Identify::EffectIdentifierEnum::kFinishEffect:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted,
identify);
break;
case Clusters::Identify::EffectIdentifierEnum::kStopEffect:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;
break;
default:
ChipLogProgress(Zcl, "No identifier effect");
}
}

Identify gIdentify = {
chip::EndpointId{ 1 },
AppTask::GetAppTask().OnIdentifyStart,
AppTask::GetAppTask().OnIdentifyStop,
Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator,
OnTriggerIdentifyEffect,
};

} // namespace

using namespace chip::TLV;
using namespace ::chip::DeviceLayer;

Expand All @@ -161,7 +85,7 @@ CHIP_ERROR AppTask::Init()
GetLCD().Init((uint8_t *) "Light Switch");
#endif

err = BaseApplication::Init(&gIdentify);
err = BaseApplication::Init();
if (err != CHIP_NO_ERROR)
{
SILABS_LOG("BaseApplication::Init() failed");
Expand Down Expand Up @@ -211,24 +135,6 @@ void AppTask::AppTaskMain(void * pvParameter)
}
}

void AppTask::OnIdentifyStart(Identify * identify)
{
ChipLogProgress(Zcl, "onIdentifyStart");

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
sAppTask.StartStatusLEDTimer();
#endif
}

void AppTask::OnIdentifyStop(Identify * identify)
{
ChipLogProgress(Zcl, "onIdentifyStop");

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
sAppTask.StopStatusLEDTimer();
#endif
}

void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
{
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_Button);
Expand Down
7 changes: 3 additions & 4 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,17 @@ void OnTriggerIdentifyEffect(Identify * identify)
{
sIdentifyEffect = identify->mCurrentEffectIdentifier;

if (identify->mCurrentEffectIdentifier == Clusters::Identify::EffectIdentifierEnum::kChannelChange)
if (identify->mEffectVariant != Clusters::Identify::EffectVariantEnum::kDefault)
{
ChipLogProgress(Zcl, "IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE - Not supported, use effect variant %d",
to_underlying(identify->mEffectVariant));
sIdentifyEffect = static_cast<Clusters::Identify::EffectIdentifierEnum>(identify->mEffectVariant);
ChipLogDetail(AppServer, "Identify Effect Variant unsupported. Using default");
}

switch (sIdentifyEffect)
{
case Clusters::Identify::EffectIdentifierEnum::kBlink:
case Clusters::Identify::EffectIdentifierEnum::kBreathe:
case Clusters::Identify::EffectIdentifierEnum::kOkay:
case Clusters::Identify::EffectIdentifierEnum::kChannelChange:
SystemLayer().ScheduleLambda([identify] {
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted,
identify);
Expand Down
16 changes: 0 additions & 16 deletions examples/lighting-app/silabs/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "FreeRTOS.h"
#include "LightingManager.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>
Expand Down Expand Up @@ -78,21 +77,6 @@ class AppTask : public BaseApplication
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
*/
static void ButtonEventHandler(uint8_t button, uint8_t btnAction);

/**
* @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 PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction);

private:
Expand Down
Loading

0 comments on commit 3023645

Please sign in to comment.