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. #3133

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
21 changes: 21 additions & 0 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "Server.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 @@ -99,6 +102,9 @@ int AppTask::Init()
InitServer();
PrintQRCode(chip::RendezvousInformationFlags::kBLE);

// Initialize cluster state to meet with the real light state
UpdateClusterState();

return 0;
}

Expand Down Expand Up @@ -360,6 +366,8 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction)
{
LOG_INF("Turn Off Action has been completed");
}

sAppTask.UpdateClusterState();
}

void AppTask::PostLightingActionRequest(LightingManager::Action_t aAction)
Expand Down Expand Up @@ -390,3 +398,16 @@ 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);
}
}
1 change: 1 addition & 0 deletions examples/lighting-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AppTask
void CancelTimer(void);

void DispatchEvent(AppEvent * event);
void UpdateClusterState();

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
Expand Down
21 changes: 21 additions & 0 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "Server.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 @@ -90,6 +93,9 @@ int AppTask::Init()
InitServer();
PrintQRCode(chip::RendezvousInformationFlags::kBLE);

// Initialize cluster state to meet with the real lock state
UpdateClusterState();

return 0;
}

Expand Down Expand Up @@ -372,6 +378,8 @@ void AppTask::ActionCompleted(BoltLockManager::Action_t aAction)
LOG_INF("Unlock Action has been completed");
sLockLED.Set(false);
}

sAppTask.UpdateClusterState();
}

void AppTask::PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction)
Expand Down Expand Up @@ -403,3 +411,16 @@ 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);
}
}
1 change: 1 addition & 0 deletions examples/lock-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AppTask
void CancelTimer(void);

void DispatchEvent(AppEvent * event);
void UpdateClusterState();

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
Expand Down