Skip to content

Commit

Permalink
Add start BLE advertising after push button
Browse files Browse the repository at this point in the history
Remove unnecessary code in AppTask.cpp files
  • Loading branch information
ATmobica committed Jan 27, 2022
1 parent 613dd3b commit f98b484
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
7 changes: 0 additions & 7 deletions examples/all-clusters-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ int AppTask::Init()
},
0);

// Start BLE advertising if needed
if (!CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART)
{
ChipLogProgress(NotSpecified, "Enabling BLE advertising.");
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}

chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();

// Init ZCL Data Model and start server
Expand Down
27 changes: 16 additions & 11 deletions examples/lighting-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ int AppTask::Init()
LightingMgr().Init(MBED_CONF_APP_LIGHTING_STATE_LED);
LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted);

// Start BLE advertising if needed
if (!CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART)
{
ChipLogProgress(NotSpecified, "Enabling BLE advertising.");
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}

chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();

// Init ZCL Data Model and start server
Expand Down Expand Up @@ -380,7 +373,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
return;

// If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, initiate factory reset
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv)
{
ChipLogProgress(NotSpecified, "Factory Reset Triggered. Release button within %ums to cancel.",
FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);
Expand Down Expand Up @@ -418,17 +411,29 @@ void AppTask::FunctionHandler(AppEvent * aEvent)
{
sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);

sAppTask.mFunction = kFunction_SoftwareUpdate;
sAppTask.mFunction = kFunction_StartBleAdv;
}
}
else
{
// If the button was released before factory reset got initiated, trigger a software update.
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv)
{
sAppTask.CancelTimer();
sAppTask.mFunction = kFunction_NoneSelected;
ChipLogError(NotSpecified, "Software Update not supported.");

chip::Server::GetInstance().GetFabricTable().DeleteAllFabrics();

if (ConnectivityMgr().IsBLEAdvertisingEnabled())
{
ChipLogProgress(NotSpecified, "BLE advertising is already enabled");
return;
}

if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR)
{
ChipLogProgress(NotSpecified, "OpenBasicCommissioningWindow() failed");
}
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/mbed/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class AppTask
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_StartBleAdv = 1,
kFunction_FactoryReset,

kFunction_Invalid
Expand Down
27 changes: 16 additions & 11 deletions examples/lock-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ int AppTask::Init()
BoltLockMgr().Init();
BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted);

// Start BLE advertising if needed
if (!CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART)
{
ChipLogProgress(NotSpecified, "Enabling BLE advertising.");
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}

chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();

// Init ZCL Data Model and start server
Expand Down Expand Up @@ -370,7 +363,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
return;

// If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, initiate factory reset
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv)
{
ChipLogProgress(NotSpecified, "Factory Reset Triggered. Release button within %ums to cancel.",
FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);
Expand Down Expand Up @@ -415,17 +408,29 @@ void AppTask::FunctionHandler(AppEvent * aEvent)
{
sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);

sAppTask.mFunction = kFunction_SoftwareUpdate;
sAppTask.mFunction = kFunction_StartBleAdv;
}
}
else
{
// If the button was released before factory reset got initiated, trigger a software update.
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv)
{
sAppTask.CancelTimer();
sAppTask.mFunction = kFunction_NoneSelected;
ChipLogError(NotSpecified, "Software Update not supported.");

chip::Server::GetInstance().GetFabricTable().DeleteAllFabrics();

if (ConnectivityMgr().IsBLEAdvertisingEnabled())
{
ChipLogProgress(NotSpecified, "BLE advertising is already enabled");
return;
}

if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR)
{
ChipLogProgress(NotSpecified, "OpenBasicCommissioningWindow() failed");
}
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/mbed/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class AppTask
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_StartBleAdv = 1,
kFunction_FactoryReset,

kFunction_Invalid
Expand Down

0 comments on commit f98b484

Please sign in to comment.