Skip to content

Commit

Permalink
[qpg]Update attribute access api for lock, lighting app (project-chip…
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-s-wrk authored and isiu-apple committed Sep 16, 2022
1 parent 39856ed commit 57ee73b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
18 changes: 8 additions & 10 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/on-off-server/on-off-server.h>
Expand All @@ -44,6 +45,8 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

using namespace ::chip;
using namespace ::chip::app;
using namespace ::chip::TLV;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
Expand All @@ -55,6 +58,7 @@ using namespace ::chip::DeviceLayer;
#define APP_TASK_STACK_SIZE (3 * 1024)
#define APP_TASK_PRIORITY 2
#define APP_EVENT_QUEUE_SIZE 10
#define QPG_LIGHT_ENDPOINT_ID (1)

namespace {
TaskHandle_t sAppTaskHandle;
Expand Down Expand Up @@ -587,23 +591,17 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
*/
void AppTask::UpdateClusterState(void)
{
uint8_t newValue;

ChipLogProgress(NotSpecified, "UpdateClusterState");

// write the new on/off value
newValue = LightingMgr().IsTurnedOn();
EmberAfStatus status =
emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, (uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
// Write the new on/off value
EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(QPG_LIGHT_ENDPOINT_ID, LightingMgr().IsTurnedOn());
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
}

newValue = LightingMgr().GetLevel();
status = emberAfWriteAttribute(1, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, (uint8_t *) &newValue,
ZCL_INT8U_ATTRIBUTE_TYPE);

// Write new level value
status = Clusters::LevelControl::Attributes::CurrentLevel::Set(QPG_LIGHT_ENDPOINT_ID, LightingMgr().GetLevel());
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating level %x", status);
Expand Down
9 changes: 5 additions & 4 deletions examples/lock-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/Dnssd.h>
#include <app/server/Server.h>
Expand All @@ -41,6 +42,8 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

using namespace ::chip;
using namespace ::chip::app;
using namespace chip::TLV;
using namespace chip::Credentials;
using namespace chip::DeviceLayer;
Expand All @@ -54,6 +57,7 @@ using namespace chip::DeviceLayer;
#define APP_TASK_STACK_SIZE (3 * 1024)
#define APP_TASK_PRIORITY 2
#define APP_EVENT_QUEUE_SIZE 10
#define QPG_LOCK_ENDPOINT_ID (1)

namespace {
TaskHandle_t sAppTaskHandle;
Expand Down Expand Up @@ -538,13 +542,10 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
*/
void AppTask::UpdateClusterState(void)
{
uint8_t newValue = !BoltLockMgr().IsUnlocked();

ChipLogProgress(NotSpecified, "UpdateClusterState");

// write the new on/off value
EmberAfStatus status =
emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, (uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(QPG_LOCK_ENDPOINT_ID, !BoltLockMgr().IsUnlocked());
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
Expand Down

0 comments on commit 57ee73b

Please sign in to comment.