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

[nrfconnect] Fixed auto relock attribute and Lock Operation event #19562

Merged
merged 1 commit into from
Jun 15, 2022
Merged
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
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");
}
}
});
}