Skip to content

Commit

Permalink
using dynamic initialization for indentify endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak-Shaha committed Oct 11, 2024
1 parent 7287041 commit 0c64921
Showing 1 changed file with 47 additions and 42 deletions.
89 changes: 47 additions & 42 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
#include <performance_test_commands.h>
#endif // PERFORMANCE_TEST_ENABLED

#ifdef MATTER_DM_PLUGIN_IDENTIFY_SERVER
#include <app-common/zap-generated/callback.h>
#endif

/**********************************************************
* Defines and Constants
*********************************************************/
Expand Down Expand Up @@ -151,13 +155,7 @@ SilabsLCD slLCD;
#ifdef MATTER_DM_PLUGIN_IDENTIFY_SERVER
Clusters::Identify::EffectIdentifierEnum sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;

Identify gIdentify = {
chip::EndpointId{ 1 },
BaseApplication::OnIdentifyStart,
BaseApplication::OnIdentifyStop,
Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator,
BaseApplication::OnTriggerIdentifyEffect,
};
ObjectPool<Identify, MATTER_DM_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT> IdentifyPool;

#endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER

Expand Down Expand Up @@ -355,48 +353,51 @@ bool BaseApplication::ActivateStatusLedPatterns()
bool isPatternSet = false;
#if (defined(ENABLE_WSTK_LEDS) && (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT)))
#ifdef MATTER_DM_PLUGIN_IDENTIFY_SERVER
if (gIdentify.mActive)
{
// Identify in progress
// Do a steady blink on the status led
sStatusLED.Blink(250, 250);
isPatternSet = true;
}
else if (sIdentifyEffect != Clusters::Identify::EffectIdentifierEnum::kStopEffect)
for(const auto& obj: IdentifyPool)
{
// Identify trigger effect received. Do some on/off patterns on the status led
if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kBlink)
{
// Fast blink
sStatusLED.Blink(50, 50);
}
else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kBreathe)
{
// Slow blink
sStatusLED.Blink(1000, 1000);
}
else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kOkay)
if (obj->mActive)
{
// Pulse effect
sStatusLED.Blink(300, 700);
// Identify in progress
// Do a steady blink on the status led
sStatusLED.Blink(250, 250);
isPatternSet = true;
}
else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kChannelChange)
else if (sIdentifyEffect != Clusters::Identify::EffectIdentifierEnum::kStopEffect)
{
// Alternate between Short and Long pulses effect
static uint64_t mLastChangeTimeMS = 0;
static bool alternatePattern = false;
uint32_t onTimeMS = alternatePattern ? 50 : 700;
uint32_t offTimeMS = alternatePattern ? 950 : 300;

uint64_t nowMS = chip::System::SystemClock().GetMonotonicMilliseconds64().count();
if (nowMS >= mLastChangeTimeMS + 1000) // each pattern is done over a 1 second period
// Identify trigger effect received. Do some on/off patterns on the status led
if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kBlink)
{
mLastChangeTimeMS = nowMS;
alternatePattern = !alternatePattern;
sStatusLED.Blink(onTimeMS, offTimeMS);
// Fast blink
sStatusLED.Blink(50, 50);
}
else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kBreathe)
{
// Slow blink
sStatusLED.Blink(1000, 1000);
}
else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kOkay)
{
// Pulse effect
sStatusLED.Blink(300, 700);
}
else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kChannelChange)
{
// Alternate between Short and Long pulses effect
static uint64_t mLastChangeTimeMS = 0;
static bool alternatePattern = false;
uint32_t onTimeMS = alternatePattern ? 50 : 700;
uint32_t offTimeMS = alternatePattern ? 950 : 300;

uint64_t nowMS = chip::System::SystemClock().GetMonotonicMilliseconds64().count();
if (nowMS >= mLastChangeTimeMS + 1000) // each pattern is done over a 1 second period
{
mLastChangeTimeMS = nowMS;
alternatePattern = !alternatePattern;
sStatusLED.Blink(onTimeMS, offTimeMS);
}
}
isPatternSet = true;
}
isPatternSet = true;
}
#endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER

Expand Down Expand Up @@ -955,3 +956,7 @@ bool BaseApplication::GetProvisionStatus()
{
return BaseApplication::sIsProvisioned;
}
void emberAfIdentifyClusterInitCallback(chip::EndpointId endpoint)
{
IdentifyPool.CreateObject(endpoint, BaseApplication::OnIdentifyStart, BaseApplication::OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator, BaseApplication::OnTriggerIdentifyEffect);
}

0 comments on commit 0c64921

Please sign in to comment.