Skip to content

Commit

Permalink
[EFR32] Link the door lock relock behaviour with the app UI (#23331)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Oct 30, 2023
1 parent 3f7660d commit 1139467
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
10 changes: 9 additions & 1 deletion examples/lock-app/efr32/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DoorLock::DlLockState *>(value));
ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI " state %d", ChipLogValueMEI(clusterId),
to_underlying(lockState));
}
}

Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
// =============================================================================
Expand Down
8 changes: 4 additions & 4 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class DoorLockClusterFabricDelegate : public chip::FabricTable::Delegate
};
static DoorLockClusterFabricDelegate gFabricDelegate;

void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId);

/**********************************************************
* DoorLockServer public methods
*********************************************************/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
11 changes: 9 additions & 2 deletions src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ class DoorLockServer
*/
void ScheduleAutoRelock(chip::EndpointId endpointId, uint32_t timeoutSec);

static void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId);

/**
* @brief Send generic event
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -887,6 +887,13 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const O
bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & 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.
*
Expand Down

0 comments on commit 1139467

Please sign in to comment.