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

[Telink]: Shut down BLE after commissioning window closes #26786

Merged
18 changes: 18 additions & 0 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "AppTaskCommon.h"
#include "AppTask.h"

#include "BLEManagerImpl.h"
#include "ButtonManager.h"

#include "ThreadUtil.h"
Expand Down Expand Up @@ -108,6 +109,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; }
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
void OnCommissioningWindowClosed() override
{
if (!isComissioningStarted)
s07641069 marked this conversation as resolved.
Show resolved Hide resolved
chip::DeviceLayer::Internal::BLEMgr().Shutdown();
}
};

AppCallbacks sCallbacks;
} // namespace

class AppFabricTableDelegate : public FabricTable::Delegate
Expand Down Expand Up @@ -213,6 +230,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
Expand Down
6 changes: 6 additions & 0 deletions src/platform/telink/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/platform/telink/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down