From 10317368d1ca3b6e795f9b6ac2e2ca16eefeb932 Mon Sep 17 00:00:00 2001 From: jmartinez-silabs <67972863+jmartinez-silabs@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:16:25 -0400 Subject: [PATCH] [EFR32] Link the door lock relock behaviour with the app UI (#23331) * Make the relock callback weak, implement it on the app side and link our app ui * address PR comments, Create a new functions that deal with the cluster and calls the application callback --- examples/lock-app/efr32/src/ZclCallbacks.cpp | 10 +++++++++- .../door-lock-server/door-lock-server-callback.cpp | 2 ++ .../clusters/door-lock-server/door-lock-server.cpp | 8 ++++---- src/app/clusters/door-lock-server/door-lock-server.h | 11 +++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/examples/lock-app/efr32/src/ZclCallbacks.cpp b/examples/lock-app/efr32/src/ZclCallbacks.cpp index 650aba7d2d73de..9c1812a90c0a04 100644 --- a/examples/lock-app/efr32/src/ZclCallbacks.cpp +++ b/examples/lock-app/efr32/src/ZclCallbacks.cpp @@ -41,7 +41,9 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & if (clusterId == DoorLock::Id && attributeId == DoorLock::Attributes::LockState::Id) { - ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); + DoorLock::DlLockState lockState = *(reinterpret_cast(value)); + ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI " state %d", ChipLogValueMEI(clusterId), + to_underlying(lockState)); } } @@ -146,3 +148,9 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t h { return LockMgr().SetHolidaySchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode); } + +void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) +{ + // Apply the relock state in the application control + LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION); +} diff --git a/src/app/clusters/door-lock-server/door-lock-server-callback.cpp b/src/app/clusters/door-lock-server/door-lock-server-callback.cpp index 699c0d9c03a759..c9c38f3fb23b5d 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-callback.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-callback.cpp @@ -61,6 +61,8 @@ emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Opti return false; } +void __attribute__((weak)) emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) {} + // ============================================================================= // 'Default' pre-change callbacks for cluster attributes // ============================================================================= diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 1465f22809cb5d..4b46b80ffe6f5f 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -69,8 +69,6 @@ class DoorLockClusterFabricDelegate : public chip::FabricTable::Delegate }; static DoorLockClusterFabricDelegate gFabricDelegate; -void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId); - /********************************************************** * DoorLockServer public methods *********************************************************/ @@ -3380,7 +3378,7 @@ void DoorLockServer::ScheduleAutoRelock(chip::EndpointId endpointId, uint32_t ti emberEventControlSetInactive(&AutolockEvent); AutolockEvent.endpoint = endpointId; - AutolockEvent.callback = emberAfPluginDoorLockOnAutoRelock; + AutolockEvent.callback = DoorLockOnAutoRelockCallback; uint32_t timeoutMs = (DOOR_LOCK_MAX_LOCK_TIMEOUT_SEC >= timeoutSec) ? timeoutSec * MILLISECOND_TICKS_PER_SECOND : DOOR_LOCK_MAX_LOCK_TIMEOUT_SEC; @@ -3751,8 +3749,10 @@ void MatterDoorLockClusterServerAttributeChangedCallback(const app::ConcreteAttr // Timer callbacks // ============================================================================= -void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) +void DoorLockServer::DoorLockOnAutoRelockCallback(chip::EndpointId endpointId) { + emberAfDoorLockClusterPrintln("Door Auto relock timer expired. Locking..."); emberEventControlSetInactive(&DoorLockServer::Instance().AutolockEvent); DoorLockServer::Instance().SetLockState(endpointId, DlLockState::kLocked, DlOperationSource::kAuto); + emberAfPluginDoorLockOnAutoRelock(endpointId); } diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index c0dc7aef6aa8f9..c7ddf369f8871a 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -410,6 +410,8 @@ class DoorLockServer */ void ScheduleAutoRelock(chip::EndpointId endpointId, uint32_t timeoutSec); + static void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId); + /** * @brief Send generic event * @@ -463,8 +465,6 @@ class DoorLockServer chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::UnlockWithTimeout::DecodableType & commandData); - friend void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId); - friend bool emberAfDoorLockClusterSetHolidayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetHolidaySchedule::DecodableType & commandData); @@ -887,6 +887,13 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const O bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional & pinCode, DlOperationError & err); +/** + * @brief This callback is called when the AutoRelock timer is expired. + * + * @param endpointId ID of the endpoint that contains the door lock to be relocked. + */ +void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId); + /** * @brief This callback is called when Door Lock cluster needs to access the users database. *