Skip to content

Commit

Permalink
[K32W] Sync button push with cluster state (#8761)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>

* [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 <[email protected]>

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 11, 2021
1 parent afc731a commit 4155043
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions examples/lighting-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions examples/lighting-app/k32w/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
12 changes: 12 additions & 0 deletions examples/lock-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions examples/lock-app/k32w/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 4155043

Please sign in to comment.