Skip to content

Commit

Permalink
[Telink]: Shut down BLE after commissioning window closes (#26786)
Browse files Browse the repository at this point in the history
* [Telink]: Added delegate to shut down BLE after commissioning window timed out

Signed-off-by: Misha Tkachenko <[email protected]>

* Restyled by clang-format

* [Telink]: Fixed wrong behavior on Commissioning window close

Signed-off-by: Misha Tkachenko <[email protected]>

* Restyled by whitespace

* Restyled by clang-format

---------

Signed-off-by: Misha Tkachenko <[email protected]>
Co-authored-by: Misha Tkachenko <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Misha Tkachenko <[email protected]>
  • Loading branch information
4 people authored and pull[bot] committed Sep 15, 2023
1 parent 380eb6e commit 2531376
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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 @@ -131,6 +132,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
Expand Down Expand Up @@ -276,6 +293,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

0 comments on commit 2531376

Please sign in to comment.