@@ -56,7 +56,7 @@ AppEvent LightSwitchMgr::CreateNewEvent(AppEvent::AppEventTypes type)
56
56
void LightSwitchMgr::Timer::Start ()
57
57
{
58
58
// Starts or restarts the function timer
59
- if (osTimerStart (mHandler , pdMS_TO_TICKS (100 )) != osOK)
59
+ if (osTimerStart (mHandler , pdMS_TO_TICKS (LONG_PRESS_TIMEOUT )) != osOK)
60
60
{
61
61
SILABS_LOG (" Timer start() failed" );
62
62
appError (CHIP_ERROR_INTERNAL);
@@ -80,7 +80,7 @@ void LightSwitchMgr::HandleLongPress()
80
80
event.Handler = AppEventHandler;
81
81
LightSwitchMgr * lightSwitch = &LightSwitchMgr::GetInstance ();
82
82
event.LightSwitchEvent .Context = lightSwitch;
83
- if (mDownPressed )
83
+ if (mFunctionButtonPressed )
84
84
{
85
85
if (!mResetWarning )
86
86
{
@@ -89,6 +89,13 @@ void LightSwitchMgr::HandleLongPress()
89
89
AppTask::GetAppTask ().PostEvent (&event);
90
90
}
91
91
}
92
+ else if (mActionButtonPressed )
93
+ {
94
+ mActionButtonSuppressed = true ;
95
+ // Long press button up : Trigger Level Control Action
96
+ event.Type = AppEvent::kEventType_TriggerLevelControlAction ;
97
+ AppTask::GetAppTask ().PostEvent (&event);
98
+ }
92
99
}
93
100
94
101
void LightSwitchMgr::OnLongPressTimeout (LightSwitchMgr::Timer & timer)
@@ -201,6 +208,10 @@ void LightSwitchMgr::GenericSwitchOnShortRelease()
201
208
DeviceLayer::PlatformMgr ().ScheduleWork (GenericSwitchWorkerFunction, reinterpret_cast <intptr_t >(data));
202
209
}
203
210
211
+ StepModeEnum LightSwitchMgr::getStepMode (){
212
+ return stepDirection;
213
+ }
214
+
204
215
void LightSwitchMgr::TriggerLightSwitchAction (LightSwitchAction action, bool isGroupCommand)
205
216
{
206
217
BindingCommandData * data = Platform::New<BindingCommandData>();
@@ -290,11 +301,11 @@ void LightSwitchMgr::ButtonEventHandler(uint8_t button, uint8_t btnAction)
290
301
AppEvent event = {};
291
302
if (btnAction == to_underlying (SilabsPlatform::ButtonAction::ButtonPressed))
292
303
{
293
- event = LightSwitchMgr::GetInstance ().CreateNewEvent (button ? AppEvent::kEventType_UpPressed : AppEvent::kEventType_DownPressed );
304
+ event = LightSwitchMgr::GetInstance ().CreateNewEvent (button ? AppEvent::kEventType_ActionButtonPressed : AppEvent::kEventType_FunctionButtonPressed );
294
305
}
295
306
else
296
307
{
297
- event = LightSwitchMgr::GetInstance ().CreateNewEvent (button ? AppEvent::kEventType_UpReleased : AppEvent::kEventType_DownReleased );
308
+ event = LightSwitchMgr::GetInstance ().CreateNewEvent (button ? AppEvent::kEventType_ActionButtonReleased : AppEvent::kEventType_FunctionButtonReleased );
298
309
}
299
310
AppTask::GetAppTask ().PostEvent (&event);
300
311
}
@@ -312,17 +323,21 @@ void LightSwitchMgr::AppEventHandler(AppEvent * aEvent)
312
323
lightSwitch->mResetWarning = false ;
313
324
AppTask::GetAppTask ().CancelFactoryResetSequence ();
314
325
break ;
315
- case AppEvent::kEventType_DownPressed :
316
- aEvent->Handler = LightSwitchMgr::SwitchActionEventHandler;
317
- AppTask::GetAppTask ().PostEvent (aEvent);
318
- lightSwitch->mDownPressed = true ;
326
+ case AppEvent::kEventType_FunctionButtonPressed :
327
+ lightSwitch->mFunctionButtonPressed = true ;
319
328
if (lightSwitch->mLongPressTimer )
320
329
{
321
330
lightSwitch->mLongPressTimer ->Start ();
322
331
}
332
+ if (lightSwitch->mActionButtonPressed )
333
+ {
334
+ lightSwitch->mActionButtonSuppressed = true ;
335
+ lightSwitch->stepDirection = (lightSwitch->stepDirection == StepModeEnum::kUp ) ? StepModeEnum::kDown : StepModeEnum::kUp ;
336
+ ChipLogProgress (AppServer, " Step direction changed. Current Step Direction : %s" , ((lightSwitch->stepDirection == StepModeEnum::kUp ) ? " kUp" : " kDown" ));
337
+ }
323
338
break ;
324
- case AppEvent::kEventType_DownReleased :
325
- lightSwitch->mDownPressed = false ;
339
+ case AppEvent::kEventType_FunctionButtonReleased :
340
+ lightSwitch->mFunctionButtonPressed = false ;
326
341
if (lightSwitch->mLongPressTimer )
327
342
{
328
343
lightSwitch->mLongPressTimer ->Stop ();
@@ -333,11 +348,44 @@ void LightSwitchMgr::AppEventHandler(AppEvent * aEvent)
333
348
AppTask::GetAppTask ().PostEvent (aEvent);
334
349
}
335
350
break ;
336
- case AppEvent::kEventType_UpPressed :
337
- case AppEvent::kEventType_UpReleased :
351
+ case AppEvent::kEventType_ActionButtonPressed :
352
+ lightSwitch->mActionButtonPressed = true ;
353
+ aEvent->Handler = LightSwitchMgr::SwitchActionEventHandler;
354
+ AppTask::GetAppTask ().PostEvent (aEvent);
355
+ if (lightSwitch->mLongPressTimer )
356
+ {
357
+ lightSwitch->mLongPressTimer ->Start ();
358
+ }
359
+ if (lightSwitch->mFunctionButtonPressed )
360
+ {
361
+ lightSwitch->mActionButtonSuppressed = true ;
362
+ lightSwitch->stepDirection = (lightSwitch->stepDirection == StepModeEnum::kUp ) ? StepModeEnum::kDown : StepModeEnum::kUp ;
363
+ ChipLogProgress (AppServer, " Step direction changed. Current Step Direction : %s" , ((lightSwitch->stepDirection == StepModeEnum::kUp ) ? " kUp" : " kDown" ));
364
+ }
365
+ break ;
366
+ case AppEvent::kEventType_ActionButtonReleased :
367
+ lightSwitch->mActionButtonPressed = false ;
368
+ if (lightSwitch->mLongPressTimer )
369
+ {
370
+ lightSwitch->mLongPressTimer ->Stop ();
371
+ }
372
+ if (lightSwitch->mActionButtonSuppressed )
373
+ {
374
+ lightSwitch->mActionButtonSuppressed = false ;
375
+ }
376
+ else
377
+ {
378
+ aEvent->Type = AppEvent::kEventType_TriggerToggle ;
379
+ aEvent->Handler = LightSwitchMgr::SwitchActionEventHandler;
380
+ AppTask::GetAppTask ().PostEvent (aEvent);
381
+ }
382
+ aEvent->Type = AppEvent::kEventType_ActionButtonReleased ;
338
383
aEvent->Handler = LightSwitchMgr::SwitchActionEventHandler;
339
384
AppTask::GetAppTask ().PostEvent (aEvent);
340
385
break ;
386
+ case AppEvent::kEventType_TriggerLevelControlAction :
387
+ aEvent->Handler = LightSwitchMgr::SwitchActionEventHandler;
388
+ AppTask::GetAppTask ().PostEvent (aEvent);
341
389
default :
342
390
break ;
343
391
}
@@ -347,20 +395,18 @@ void LightSwitchMgr::SwitchActionEventHandler(AppEvent * aEvent)
347
395
{
348
396
switch (aEvent->Type )
349
397
{
350
- case AppEvent::kEventType_UpPressed : {
351
- LightSwitchMgr::GetInstance ().TriggerLightSwitchAction (LightSwitchMgr::LightSwitchAction::Toggle);
398
+ case AppEvent::kEventType_ActionButtonPressed :
352
399
LightSwitchMgr::GetInstance ().GenericSwitchOnInitialPress ();
353
- }
354
400
break ;
355
- case AppEvent::kEventType_UpReleased :
401
+ case AppEvent::kEventType_ActionButtonReleased :
356
402
LightSwitchMgr::GetInstance ().GenericSwitchOnShortRelease ();
357
403
break ;
358
- #if 0
359
- // TODO: Fix the button handling for the btn0 and btn1
360
- case AppEvent::kEventType_DownPressed:
361
- LightSwitchMgr::GetInstance().TriggerLevelControlAction(LevelControl::StepModeEnum::kDown);
404
+ case AppEvent::kEventType_TriggerLevelControlAction :
405
+ LightSwitchMgr::GetInstance ().TriggerLevelControlAction (LightSwitchMgr::GetInstance ().getStepMode ());
406
+ break ;
407
+ case AppEvent::kEventType_TriggerToggle :
408
+ LightSwitchMgr::GetInstance ().TriggerLightSwitchAction (LightSwitchMgr::LightSwitchAction::Toggle);
362
409
break ;
363
- #endif
364
410
default :
365
411
break ;
366
412
}
0 commit comments