23
23
#include " AppTask.h"
24
24
#include < FreeRTOS.h>
25
25
26
- #include < app/clusters/on-off-server/on-off-server.h>
27
-
28
26
using namespace chip ;
29
27
using namespace ::chip::DeviceLayer;
30
28
31
29
LightingManager LightingManager::sLight ;
32
30
33
31
TimerHandle_t sLightTimer ;
34
32
33
+ namespace {
34
+
35
+ /* *********************************************************
36
+ * OffWithEffect Callbacks
37
+ *********************************************************/
38
+
39
+ OnOffEffect gEffect = {
40
+ chip::EndpointId{ 1 },
41
+ LightMgr ().OnTriggerOffWithEffect ,
42
+ EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF,
43
+ static_cast <uint8_t >(EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS),
44
+ };
45
+
46
+ } // namespace
47
+
35
48
CHIP_ERROR LightingManager::Init ()
36
49
{
37
50
// Create FreeRTOS sw timer for light timer.
@@ -58,6 +71,7 @@ CHIP_ERROR LightingManager::Init()
58
71
mAutoTurnOffTimerArmed = false ;
59
72
mAutoTurnOff = false ;
60
73
mAutoTurnOffDuration = 0 ;
74
+ mOffEffectArmed = false ;
61
75
62
76
return CHIP_NO_ERROR;
63
77
}
@@ -94,13 +108,13 @@ bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction)
94
108
State_t new_state;
95
109
96
110
// Initiate Turn On/Off Action only when the previous one is complete.
97
- if (mState == kState_OffCompleted && aAction == ON_ACTION)
111
+ if ((( mState == kState_OffCompleted ) || mOffEffectArmed ) && aAction == ON_ACTION)
98
112
{
99
113
action_initiated = true ;
100
114
101
115
new_state = kState_OnInitiated ;
102
116
}
103
- else if (mState == kState_OnCompleted && aAction == OFF_ACTION)
117
+ else if (mState == kState_OnCompleted && aAction == OFF_ACTION && mOffEffectArmed == false )
104
118
{
105
119
action_initiated = true ;
106
120
@@ -118,6 +132,12 @@ bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction)
118
132
CancelTimer ();
119
133
}
120
134
135
+ if (mOffEffectArmed && new_state == kState_OnInitiated )
136
+ {
137
+ CancelTimer ();
138
+ mOffEffectArmed = false ;
139
+ }
140
+
121
141
StartTimer (ACTUATOR_MOVEMENT_PERIOS_MS);
122
142
123
143
// Since the timer started successfully, update the state and trigger callback
@@ -174,6 +194,10 @@ void LightingManager::TimerEventHandler(TimerHandle_t xTimer)
174
194
{
175
195
event.Handler = AutoTurnOffTimerEventHandler;
176
196
}
197
+ else if (light->mOffEffectArmed )
198
+ {
199
+ event.Handler = OffEffectTimerEventHandler;
200
+ }
177
201
else
178
202
{
179
203
event.Handler = ActuatorMovementTimerEventHandler;
@@ -184,7 +208,7 @@ void LightingManager::TimerEventHandler(TimerHandle_t xTimer)
184
208
void LightingManager::AutoTurnOffTimerEventHandler (AppEvent * aEvent)
185
209
{
186
210
LightingManager * light = static_cast <LightingManager *>(aEvent->TimerEvent .Context );
187
- int32_t actor = 0 ;
211
+ int32_t actor = AppEvent:: kEventType_Timer ;
188
212
189
213
// Make sure auto turn off timer is still armed.
190
214
if (!light->mAutoTurnOffTimerArmed )
@@ -199,6 +223,24 @@ void LightingManager::AutoTurnOffTimerEventHandler(AppEvent * aEvent)
199
223
light->InitiateAction (actor, OFF_ACTION);
200
224
}
201
225
226
+ void LightingManager::OffEffectTimerEventHandler (AppEvent * aEvent)
227
+ {
228
+ LightingManager * light = static_cast <LightingManager *>(aEvent->TimerEvent .Context );
229
+ int32_t actor = AppEvent::kEventType_Timer ;
230
+
231
+ // Make sure auto turn off timer is still armed.
232
+ if (!light->mOffEffectArmed )
233
+ {
234
+ return ;
235
+ }
236
+
237
+ light->mOffEffectArmed = false ;
238
+
239
+ EFR32_LOG (" OffEffect completed" );
240
+
241
+ light->InitiateAction (actor, OFF_ACTION);
242
+ }
243
+
202
244
void LightingManager::ActuatorMovementTimerEventHandler (AppEvent * aEvent)
203
245
{
204
246
Action_t actionCompleted = INVALID_ACTION;
@@ -234,3 +276,47 @@ void LightingManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent)
234
276
}
235
277
}
236
278
}
279
+
280
+ void LightingManager::OnTriggerOffWithEffect (OnOffEffect * effect)
281
+ {
282
+ chip::app::Clusters::OnOff::OnOffEffectIdentifier effectId = effect->mEffectIdentifier ;
283
+ uint8_t effectVariant = effect->mEffectVariant ;
284
+ uint32_t offEffectDuration = 0 ;
285
+
286
+ // Temporary print outs and delay to test OffEffect behaviour
287
+ // Until dimming is supported for dev boards.
288
+ if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF)
289
+ {
290
+ if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS)
291
+ {
292
+ offEffectDuration = 800 ;
293
+ ChipLogProgress (Zcl, " EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS" );
294
+ }
295
+ else if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE)
296
+ {
297
+ offEffectDuration = 800 ;
298
+ ChipLogProgress (Zcl, " EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE" );
299
+ }
300
+ else if (effectVariant ==
301
+ EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_IN_12_SECONDS)
302
+ {
303
+ offEffectDuration = 12800 ;
304
+ ChipLogProgress (Zcl,
305
+ " EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_"
306
+ " IN_12_SECONDS" );
307
+ }
308
+ }
309
+ else if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DYING_LIGHT)
310
+ {
311
+ if (effectVariant ==
312
+ EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND)
313
+ {
314
+ offEffectDuration = 1500 ;
315
+ ChipLogProgress (
316
+ Zcl, " EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND" );
317
+ }
318
+ }
319
+
320
+ LightMgr ().mOffEffectArmed = true ;
321
+ LightMgr ().StartTimer (offEffectDuration);
322
+ }
0 commit comments