25
25
#include < app-common/zap-generated/attributes/Accessors.h>
26
26
#include < app-common/zap-generated/ids/Attributes.h>
27
27
#include < app-common/zap-generated/ids/Clusters.h>
28
+ #include < app/clusters/identify-server/identify-server.h>
28
29
#include < setup_payload/OnboardingCodesUtil.h>
29
30
30
31
#ifdef CONFIG_BRIDGED_DEVICE_BT
@@ -41,21 +42,32 @@ LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
41
42
using namespace ::chip;
42
43
using namespace ::chip::app;
43
44
using namespace ::chip::DeviceLayer;
45
+
44
46
namespace
45
47
{
46
48
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
+
47
59
#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 );
52
64
/* *
53
65
* @brief Blink rates for indication the BLE Connectivity Manager state.
54
66
*
55
67
*/
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 };
59
71
#ifndef CONFIG_BRIDGE_SMART_PLUG_SUPPORT
60
72
void BLEStateChangeCallback (Nrf::BLEConnectivityManager::State state)
61
73
{
@@ -103,6 +115,67 @@ void AppFactoryResetHandler(const ChipDeviceEvent *event, intptr_t /* unused */)
103
115
104
116
} /* namespace */
105
117
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
+
106
179
CHIP_ERROR AppTask::RestoreBridgedDevices ()
107
180
{
108
181
uint8_t count;
@@ -216,6 +289,9 @@ CHIP_ERROR AppTask::Init()
216
289
ReturnErrorOnFailure (Nrf::Matter::RegisterEventHandler (AppFactoryResetHandler, 0 ));
217
290
#endif
218
291
292
+ /* Initialize trigger effect timer */
293
+ k_timer_init (&sTriggerEffectTimer , &AppTask::TriggerEffectTimerTimeoutCallback, nullptr );
294
+
219
295
return Nrf::Matter::StartServer ();
220
296
}
221
297
0 commit comments