Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle [samples/nrfconnect] Added updating ZCL cluster state to fit actual light/lock state. #3194

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "Service.h"
#include "ThreadUtil.h"

#include "attribute-storage.h"
#include "gen/cluster-id.h"

#include <platform/CHIPDeviceLayer.h>

#include <setup_payload/QRCodeSetupPayloadGenerator.h>
Expand Down Expand Up @@ -360,6 +363,8 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction)
{
LOG_INF("Turn Off Action has been initiated");
}

sAppTask.mButtonTriggeredActon = (aActor == AppEvent::kEventType_Button) ? true : false;
}

void AppTask::ActionCompleted(LightingManager::Action_t aAction)
Expand All @@ -372,6 +377,12 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction)
{
LOG_INF("Turn Off Action has been completed");
}

if (sAppTask.mButtonTriggeredActon)
{
sAppTask.UpdateClusterState();
sAppTask.mButtonTriggeredActon = false;
}
}

void AppTask::PostLightingActionRequest(LightingManager::Action_t aAction)
Expand Down Expand Up @@ -402,3 +413,21 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
LOG_INF("Event received with no handler. Dropping event.");
}
}

void AppTask::UpdateClusterState()
{
uint8_t newValue = LightingMgr().IsTurnedOn();

// write the new on/off value
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &newValue,
ZCL_BOOLEAN_ATTRIBUTE_TYPE);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
LOG_ERR("Updating on/off %x", status);
}
}

void emberAfPluginOnOffClusterServerPostInitCallback(uint8_t endpoint)
{
GetAppTask().UpdateClusterState();
}
3 changes: 2 additions & 1 deletion examples/lighting-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AppTask

void PostLightingActionRequest(LightingManager::Action_t aAction);
void PostEvent(AppEvent * event);
void UpdateClusterState();

private:
friend AppTask & GetAppTask(void);
Expand Down Expand Up @@ -67,7 +68,7 @@ class AppTask

Function_t mFunction;
bool mFunctionTimerActive;

bool mButtonTriggeredActon;
static AppTask sAppTask;
};

Expand Down
29 changes: 29 additions & 0 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "Service.h"
#include "ThreadUtil.h"

#include "attribute-storage.h"
#include "gen/cluster-id.h"

#include <platform/CHIPDeviceLayer.h>

#include <dk_buttons_and_leds.h>
Expand Down Expand Up @@ -367,6 +370,8 @@ void AppTask::ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor)
LOG_INF("Unlock Action has been initiated");
}

sAppTask.mButtonTriggeredActon = (aActor == AppEvent::kEventType_Button) ? true : false;

sLockLED.Blink(50, 50);
}

Expand All @@ -385,6 +390,12 @@ void AppTask::ActionCompleted(BoltLockManager::Action_t aAction)
LOG_INF("Unlock Action has been completed");
sLockLED.Set(false);
}

if (sAppTask.mButtonTriggeredActon)
{
sAppTask.UpdateClusterState();
sAppTask.mButtonTriggeredActon = false;
}
}

void AppTask::PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction)
Expand Down Expand Up @@ -416,3 +427,21 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
LOG_INF("Event received with no handler. Dropping event.");
}
}

void AppTask::UpdateClusterState()
{
uint8_t newValue = !BoltLockMgr().IsUnlocked();

// write the new on/off value
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &newValue,
ZCL_BOOLEAN_ATTRIBUTE_TYPE);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
LOG_ERR("Updating on/off %x", status);
}
}

void emberAfPluginOnOffClusterServerPostInitCallback(uint8_t endpoint)
{
GetAppTask().UpdateClusterState();
}
3 changes: 2 additions & 1 deletion examples/lock-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AppTask

void PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction);
void PostEvent(AppEvent * event);
void UpdateClusterState();

private:
friend AppTask & GetAppTask(void);
Expand Down Expand Up @@ -66,7 +67,7 @@ class AppTask

Function_t mFunction;
bool mFunctionTimerActive;

bool mButtonTriggeredActon;
static AppTask sAppTask;
};

Expand Down