diff --git a/examples/lock-app/silabs/include/LockManager.h b/examples/lock-app/silabs/include/LockManager.h index 7345782d69..00a4407c34 100644 --- a/examples/lock-app/silabs/include/LockManager.h +++ b/examples/lock-app/silabs/include/LockManager.h @@ -199,10 +199,12 @@ class LockManager private: struct UnlatchContext { + static constexpr uint8_t kMaxPinLength = UINT8_MAX; + uint8_t mPinBuffer[kMaxPinLength]; + uint8_t mPinLength; chip::EndpointId mEndpointId; Nullable mFabricIdx; Nullable mNodeId; - Optional mPin; OperationErrorEnum mErr; void Update(chip::EndpointId endpointId, const Nullable & fabricIdx, @@ -211,8 +213,18 @@ class LockManager mEndpointId = endpointId; mFabricIdx = fabricIdx; mNodeId = nodeId; - mPin = pin; mErr = err; + + if (pin.HasValue()) + { + memcpy(mPinBuffer, pin.Value().data(), pin.Value().size()); + mPinLength = static_cast(pin.Value().size()); + } + else + { + memset(mPinBuffer, 0, kMaxPinLength); + mPinLength = 0; + } } }; UnlatchContext mUnlatchContext; @@ -242,11 +254,7 @@ class LockManager uint8_t mCredentialData[kNumCredentialTypes][kMaxCredentials][kMaxCredentialSize]; CredentialStruct mCredentials[kMaxUsers][kMaxCredentials]; - static LockManager sLock; EFR32DoorLock::LockInitParams::LockParam LockParams; }; -inline LockManager & LockMgr() -{ - return LockManager::sLock; -} +LockManager & LockMgr(); diff --git a/examples/lock-app/silabs/src/LockManager.cpp b/examples/lock-app/silabs/src/LockManager.cpp index 04527e53ac..8ad82dafb9 100644 --- a/examples/lock-app/silabs/src/LockManager.cpp +++ b/examples/lock-app/silabs/src/LockManager.cpp @@ -25,11 +25,18 @@ #include #include -LockManager LockManager::sLock; - using namespace ::chip::DeviceLayer::Internal; using namespace EFR32DoorLock::LockInitParams; +namespace { + LockManager sLock; +} // namespace + +LockManager & LockMgr() +{ + return sLock; +} + CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable state, LockParam lockParam) { @@ -258,7 +265,7 @@ void LockManager::UnlockAfterUnlatch() if (mUnlatchContext.mEndpointId != kInvalidEndpointId) { succes = setLockState(mUnlatchContext.mEndpointId, mUnlatchContext.mFabricIdx, mUnlatchContext.mNodeId, - DlLockState::kUnlocked, mUnlatchContext.mPin, mUnlatchContext.mErr); + DlLockState::kUnlocked, MakeOptional(chip::ByteSpan(mUnlatchContext.mPinBuffer, mUnlatchContext.mPinLength)), mUnlatchContext.mErr); } if (!succes)