2525#include < app-common/zap-generated/attributes/Accessors.h>
2626#include < app-common/zap-generated/ids/Attributes.h>
2727#include < app-common/zap-generated/ids/Clusters.h>
28+ #include < app/clusters/identify-server/identify-server.h>
2829#include < setup_payload/OnboardingCodesUtil.h>
2930
3031#ifdef CONFIG_BRIDGED_DEVICE_BT
@@ -41,21 +42,32 @@ LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
4142using namespace ::chip;
4243using namespace ::chip::app;
4344using namespace ::chip::DeviceLayer;
45+
4446namespace
4547{
4648
49+ constexpr EndpointId kBridgeEndpointId = 1 ;
50+ constexpr uint16_t kTriggerEffectTimeout = 5000 ;
51+ constexpr uint16_t kTriggerEffectFinishTimeout = 1000 ;
52+
53+ k_timer sTriggerEffectTimer ;
54+ bool sIsTriggerEffectActive ;
55+
56+ Identify sIdentify = { kBridgeEndpointId , AppTask::IdentifyStartHandler, AppTask::IdentifyStopHandler,
57+ Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator , AppTask::TriggerIdentifyEffectHandler };
58+
4759#ifdef CONFIG_BRIDGED_DEVICE_BT
48- static const bt_uuid *sUuidLbs = BT_UUID_LBS;
49- static const bt_uuid *sUuidEs = BT_UUID_ESS;
50- static const bt_uuid *sUuidServices [] = { sUuidLbs , sUuidEs };
51- static constexpr uint8_t kUuidServicesNumber = ARRAY_SIZE(sUuidServices );
60+ const bt_uuid *sUuidLbs = BT_UUID_LBS;
61+ const bt_uuid *sUuidEs = BT_UUID_ESS;
62+ const bt_uuid *sUuidServices [] = { sUuidLbs , sUuidEs };
63+ constexpr uint8_t kUuidServicesNumber = ARRAY_SIZE(sUuidServices );
5264/* *
5365 * @brief Blink rates for indication the BLE Connectivity Manager state.
5466 *
5567 */
56- constexpr static uint32_t kPairingBlinkRate { 100 };
57- constexpr static uint32_t kScanningBlinkRate_ms { 300 };
58- constexpr static uint32_t kLostBlinkRate_ms { 1000 };
68+ constexpr uint32_t kPairingBlinkRate { 100 };
69+ constexpr uint32_t kScanningBlinkRate_ms { 300 };
70+ constexpr uint32_t kLostBlinkRate_ms { 1000 };
5971#ifndef CONFIG_BRIDGE_SMART_PLUG_SUPPORT
6072void BLEStateChangeCallback (Nrf::BLEConnectivityManager::State state)
6173{
@@ -103,6 +115,67 @@ void AppFactoryResetHandler(const ChipDeviceEvent *event, intptr_t /* unused */)
103115
104116} /* namespace */
105117
118+ void AppTask::IdentifyStartHandler (Identify *)
119+ {
120+ Nrf::PostTask (
121+ [] { Nrf::GetBoard ().GetLED (Nrf::DeviceLeds::LED2).Blink (Nrf::LedConsts::kIdentifyBlinkRate_ms ); });
122+ }
123+
124+ void AppTask::IdentifyStopHandler (Identify *)
125+ {
126+ Nrf::PostTask ([] {
127+ Nrf::GetBoard ().GetLED (Nrf::DeviceLeds::LED2).Set (false );
128+ });
129+ }
130+
131+ void AppTask::TriggerEffectTimerTimeoutCallback (k_timer *timer)
132+ {
133+ LOG_INF (" Identify effect completed" );
134+
135+ sIsTriggerEffectActive = false ;
136+
137+ Nrf::GetBoard ().GetLED (Nrf::DeviceLeds::LED2).Set (false );
138+
139+ }
140+
141+ void AppTask::TriggerIdentifyEffectHandler (Identify *identify)
142+ {
143+ switch (identify->mCurrentEffectIdentifier ) {
144+ /* Just handle all effects in the same way. */
145+ case Clusters::Identify::EffectIdentifierEnum::kBlink :
146+ case Clusters::Identify::EffectIdentifierEnum::kBreathe :
147+ case Clusters::Identify::EffectIdentifierEnum::kOkay :
148+ case Clusters::Identify::EffectIdentifierEnum::kChannelChange :
149+ LOG_INF (" Identify effect identifier changed to %d" ,
150+ static_cast <uint8_t >(identify->mCurrentEffectIdentifier ));
151+
152+ sIsTriggerEffectActive = false ;
153+
154+ k_timer_stop (&sTriggerEffectTimer );
155+ k_timer_start (&sTriggerEffectTimer , K_MSEC (kTriggerEffectTimeout ), K_NO_WAIT);
156+
157+ Nrf::GetBoard ().GetLED (Nrf::DeviceLeds::LED2).Blink (Nrf::LedConsts::kIdentifyBlinkRate_ms );
158+ break ;
159+ case Clusters::Identify::EffectIdentifierEnum::kFinishEffect :
160+ LOG_INF (" Identify effect finish triggered" );
161+ k_timer_stop (&sTriggerEffectTimer );
162+ k_timer_start (&sTriggerEffectTimer , K_MSEC (kTriggerEffectFinishTimeout ), K_NO_WAIT);
163+ break ;
164+ case Clusters::Identify::EffectIdentifierEnum::kStopEffect :
165+ if (sIsTriggerEffectActive ) {
166+ sIsTriggerEffectActive = false ;
167+
168+ k_timer_stop (&sTriggerEffectTimer );
169+
170+ Nrf::GetBoard ().GetLED (Nrf::DeviceLeds::LED2).Set (false );
171+ }
172+ break ;
173+ default :
174+ LOG_ERR (" Received invalid effect identifier." );
175+ break ;
176+ }
177+ }
178+
106179CHIP_ERROR AppTask::RestoreBridgedDevices ()
107180{
108181 uint8_t count;
@@ -216,6 +289,9 @@ CHIP_ERROR AppTask::Init()
216289 ReturnErrorOnFailure (Nrf::Matter::RegisterEventHandler (AppFactoryResetHandler, 0 ));
217290#endif
218291
292+ /* Initialize trigger effect timer */
293+ k_timer_init (&sTriggerEffectTimer , &AppTask::TriggerEffectTimerTimeoutCallback, nullptr );
294+
219295 return Nrf::Matter::StartServer ();
220296}
221297
0 commit comments