From 0c64921eff96cb0c172eec9244be2968d9e4952f Mon Sep 17 00:00:00 2001 From: Sarthak Shaha Date: Fri, 11 Oct 2024 14:55:17 -0400 Subject: [PATCH] using dynamic initialization for indentify endpoints --- examples/platform/silabs/BaseApplication.cpp | 89 +++++++++++--------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index b7ce3e9fed8bdf..11c5db9c0fc8cb 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -74,6 +74,10 @@ #include #endif // PERFORMANCE_TEST_ENABLED +#ifdef MATTER_DM_PLUGIN_IDENTIFY_SERVER +#include +#endif + /********************************************************** * Defines and Constants *********************************************************/ @@ -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 IdentifyPool; #endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER @@ -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 @@ -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); +} \ No newline at end of file