Skip to content

Commit

Permalink
[nrfconnect] Fixed auto relock attribute and Lock Operation event (#1…
Browse files Browse the repository at this point in the history
…9562)

There are two issues with the nrfconnect door lock:
* It has auto-relock-time value set to 60, while it should be 0
* It emits Lock Operation event on init, while no operation
was done.

* Set auto relock time to 0
* Added invoking lock/unlock operation only if lock state is not
null (uninitialized)
* By the way of this change aligned lighting app extended discovery
timeout to other nrfconnect examples
  • Loading branch information
kkasperczyk-no authored and pull[bot] committed Jun 28, 2022
1 parent b4eba1a commit 1096704
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 0 additions & 2 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace {

constexpr int kFactoryResetTriggerTimeout = 3000;
constexpr int kFactoryResetCancelWindowTimeout = 3000;
constexpr int kExtDiscoveryTimeoutSecs = 20;
constexpr int kAppEventQueueSize = 10;
constexpr uint8_t kButtonPushEvent = 1;
constexpr uint8_t kButtonReleaseEvent = 0;
Expand Down Expand Up @@ -170,7 +169,6 @@ CHIP_ERROR AppTask::Init()

// Initialize CHIP server
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(kExtDiscoveryTimeoutSecs);

static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand Down
30 changes: 22 additions & 8 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ CHIP_ERROR AppTask::Init()
// between the main and the CHIP threads.
PlatformMgr().AddEventHandler(ChipEventHandler, 0);

// Disable auto-relock time feature.
DoorLockServer::Instance().SetAutoRelockTime(kLockEndpointId, 0);

err = PlatformMgr().StartEventLoopTask();
if (err != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -533,27 +536,38 @@ void AppTask::DispatchEvent(AppEvent * aEvent)

void AppTask::UpdateClusterState(BoltLockManager::State state, BoltLockManager::OperationSource source)
{
DlLockState lockState;
DlLockState newLockState;

switch (state)
{
case BoltLockManager::State::kLockingCompleted:
lockState = DlLockState::kLocked;
newLockState = DlLockState::kLocked;
break;
case BoltLockManager::State::kUnlockingCompleted:
lockState = DlLockState::kUnlocked;
newLockState = DlLockState::kUnlocked;
break;
default:
lockState = DlLockState::kNotFullyLocked;
newLockState = DlLockState::kNotFullyLocked;
break;
}

SystemLayer().ScheduleLambda([lockState, source] {
LOG_INF("Updating LockState attribute");
SystemLayer().ScheduleLambda([newLockState, source] {
chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> currentLockState;
chip::app::Clusters::DoorLock::Attributes::LockState::Get(kLockEndpointId, currentLockState);

if (!DoorLockServer::Instance().SetLockState(kLockEndpointId, lockState, source))
if (currentLockState.IsNull())
{
// Initialize lock state with start value, but not invoke lock/unlock.
chip::app::Clusters::DoorLock::Attributes::LockState::Set(kLockEndpointId, newLockState);
}
else
{
LOG_ERR("Failed to update LockState attribute");
LOG_INF("Updating LockState attribute");

if (!DoorLockServer::Instance().SetLockState(kLockEndpointId, newLockState, source))
{
LOG_ERR("Failed to update LockState attribute");
}
}
});
}

0 comments on commit 1096704

Please sign in to comment.