From 4155043d733a23b9479e58be130a6fe22002597d Mon Sep 17 00:00:00 2001 From: doru91 Date: Wed, 11 Aug 2021 16:35:56 +0300 Subject: [PATCH] [K32W] Sync button push with cluster state (#8761) * [K32W] Sync button push with cluster state If buttons are used for locking/unlocking the elock or for turn off/down of the lighting then this change needs to be propagated to the cluster state. Signed-off-by: Doru Gucea * [K32W] Sync button push with cluster state If buttons are used for locking/unlocking the elock or for turn off/down of the lighting then this change needs to be propagated to the cluster state. Signed-off-by: Doru Gucea * Restyled by clang-format Co-authored-by: Restyled.io --- examples/lighting-app/k32w/main/AppTask.cpp | 12 ++++++++++++ examples/lighting-app/k32w/main/include/AppTask.h | 5 +++-- examples/lock-app/k32w/main/AppTask.cpp | 12 ++++++++++++ examples/lock-app/k32w/main/include/AppTask.h | 5 +++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/lighting-app/k32w/main/AppTask.cpp b/examples/lighting-app/k32w/main/AppTask.cpp index fc5cb164275ec1..b05671e9709377 100644 --- a/examples/lighting-app/k32w/main/AppTask.cpp +++ b/examples/lighting-app/k32w/main/AppTask.cpp @@ -100,6 +100,7 @@ CHIP_ERROR AppTask::Init() sLightLED.Init(LIGHT_STATE_LED); sLightLED.Set(LightingMgr().IsTurnedOff()); + UpdateClusterState(); /* intialize the Keyboard and button press calback */ KBD_Init(KBD_Callback); @@ -565,6 +566,11 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor) K32W_LOG("Turn off Action has been initiated") } + if (aActor == AppEvent::kEventType_Button) + { + sAppTask.mSyncClusterToButtonAction = true; + } + sAppTask.mFunction = kFunctionTurnOnTurnOff; } @@ -583,6 +589,12 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction) sLightLED.Set(false); } + if (sAppTask.mSyncClusterToButtonAction) + { + sAppTask.UpdateClusterState(); + sAppTask.mSyncClusterToButtonAction = false; + } + sAppTask.mFunction = kFunction_NoneSelected; } diff --git a/examples/lighting-app/k32w/main/include/AppTask.h b/examples/lighting-app/k32w/main/include/AppTask.h index 5e86c5e920c143..7099eb2ea297c5 100644 --- a/examples/lighting-app/k32w/main/include/AppTask.h +++ b/examples/lighting-app/k32w/main/include/AppTask.h @@ -87,8 +87,9 @@ class AppTask kFunction_Invalid } Function; - Function_t mFunction; - bool mResetTimerActive; + Function_t mFunction = kFunction_NoneSelected; + bool mResetTimerActive = false; + bool mSyncClusterToButtonAction = false; static AppTask sAppTask; }; diff --git a/examples/lock-app/k32w/main/AppTask.cpp b/examples/lock-app/k32w/main/AppTask.cpp index cad8371f800d27..8ae6838cf4a320 100644 --- a/examples/lock-app/k32w/main/AppTask.cpp +++ b/examples/lock-app/k32w/main/AppTask.cpp @@ -97,6 +97,7 @@ CHIP_ERROR AppTask::Init() sLockLED.Init(LOCK_STATE_LED); sLockLED.Set(!BoltLockMgr().IsUnlocked()); + UpdateClusterState(); /* intialize the Keyboard and button press calback */ KBD_Init(KBD_Callback); @@ -570,6 +571,11 @@ void AppTask::ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor) K32W_LOG("Unlock Action has been initiated") } + if (aActor == AppEvent::kEventType_Button) + { + sAppTask.mSyncClusterToButtonAction = true; + } + sAppTask.mFunction = kFunctionLockUnlock; sLockLED.Blink(50, 50); } @@ -590,6 +596,12 @@ void AppTask::ActionCompleted(BoltLockManager::Action_t aAction) sLockLED.Set(false); } + if (sAppTask.mSyncClusterToButtonAction) + { + sAppTask.UpdateClusterState(); + sAppTask.mSyncClusterToButtonAction = false; + } + sAppTask.mFunction = kFunction_NoneSelected; } diff --git a/examples/lock-app/k32w/main/include/AppTask.h b/examples/lock-app/k32w/main/include/AppTask.h index 82e73499cff2c1..f862abe4eeb9f4 100644 --- a/examples/lock-app/k32w/main/include/AppTask.h +++ b/examples/lock-app/k32w/main/include/AppTask.h @@ -79,8 +79,9 @@ class AppTask kFunction_Invalid } Function; - Function_t mFunction; - bool mResetTimerActive; + Function_t mFunction = kFunction_NoneSelected; + bool mResetTimerActive = false; + bool mSyncClusterToButtonAction = false; static AppTask sAppTask; };