diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index ec45f9241d46e0..55b0da045bb5a7 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -19,6 +19,7 @@ #include "AppTaskCommon.h" #include "AppTask.h" +#include "BLEManagerImpl.h" #include "ButtonManager.h" #include "ThreadUtil.h" @@ -115,6 +116,22 @@ Identify sIdentify = { uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; #endif + +class AppCallbacks : public AppDelegate +{ + bool isComissioningStarted; + +public: + void OnCommissioningSessionStarted() override { isComissioningStarted = true; } + void OnCommissioningSessionStopped() override { isComissioningStarted = false; } + void OnCommissioningWindowClosed() override + { + if (!isComissioningStarted) + chip::DeviceLayer::Internal::BLEMgr().Shutdown(); + } +}; + +AppCallbacks sCallbacks; } // namespace class AppFabricTableDelegate : public FabricTable::Delegate @@ -260,6 +277,7 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) // Init ZCL Data Model and start server static CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.appDelegate = &sCallbacks; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); #if APP_SET_DEVICE_INFO_PROVIDER diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index dd912e5e581b3c..0d488c5c917c31 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -176,6 +176,12 @@ CHIP_ERROR BLEManagerImpl::_Init(void) return CHIP_NO_ERROR; } +void BLEManagerImpl::_Shutdown() +{ + bt_disable(); + mBLERadioInitialized = false; +} + void BLEManagerImpl::DriveBLEState(intptr_t arg) { BLEMgrImpl().DriveBLEState(); diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index a2fd31fc6d8a5a..1e1c4c94d67638 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -54,7 +54,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); - void _Shutdown() {} + void _Shutdown(); bool _IsAdvertisingEnabled(void); CHIP_ERROR _SetAdvertisingEnabled(bool val); bool _IsAdvertising(void);