Skip to content

Commit

Permalink
Merge 8d72a73 into c38773d
Browse files Browse the repository at this point in the history
  • Loading branch information
kkasperczyk-no authored Oct 12, 2020
2 parents c38773d + 8d72a73 commit 3562036
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
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

0 comments on commit 3562036

Please sign in to comment.