Skip to content

Commit

Permalink
[K32W] Sync button push with cluster state
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
doru91 committed Aug 3, 2021
1 parent 3d8d542 commit 2647982
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 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 @@ int 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
1 change: 1 addition & 0 deletions examples/lighting-app/k32w/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class AppTask

Function_t mFunction;
bool mResetTimerActive;
bool mSyncClusterToButtonAction;

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 @@ int 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
1 change: 1 addition & 0 deletions examples/lock-app/k32w/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class AppTask

Function_t mFunction;
bool mResetTimerActive;
bool mSyncClusterToButtonAction;

static AppTask sAppTask;
};
Expand Down

0 comments on commit 2647982

Please sign in to comment.