summaryrefslogtreecommitdiff
path: root/src/components/ble/NimbleController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ble/NimbleController.cpp')
-rw-r--r--src/components/ble/NimbleController.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp
index 00a394f..f6ab626 100644
--- a/src/components/ble/NimbleController.cpp
+++ b/src/components/ble/NimbleController.cpp
@@ -23,14 +23,14 @@
using namespace Pinetime::Controllers;
NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
- Pinetime::Controllers::Ble& bleController,
+ Ble& bleController,
DateTime& dateTimeController,
- Pinetime::Controllers::NotificationManager& notificationManager,
- Controllers::Battery& batteryController,
+ NotificationManager& notificationManager,
+ Battery& batteryController,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
- Controllers::HeartRateController& heartRateController,
- Controllers::MotionController& motionController,
- Controllers::FS& fs)
+ HeartRateController& heartRateController,
+ MotionController& motionController,
+ FS& fs)
: systemTask {systemTask},
bleController {bleController},
dateTimeController {dateTimeController},
@@ -184,7 +184,9 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
case BLE_GAP_EVENT_ADV_COMPLETE:
NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_ADV_COMPLETE");
NRF_LOG_INFO("reason=%d; status=%0X", event->adv_complete.reason, event->connect.status);
- StartAdvertising();
+ if (bleController.IsRadioEnabled() && !bleController.IsConnected()) {
+ StartAdvertising();
+ }
break;
case BLE_GAP_EVENT_CONNECT:
@@ -220,9 +222,11 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
currentTimeClient.Reset();
alertNotificationClient.Reset();
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
- bleController.Disconnect();
- fastAdvCount = 0;
- StartAdvertising();
+ if(bleController.IsConnected()) {
+ bleController.Disconnect();
+ fastAdvCount = 0;
+ StartAdvertising();
+ }
break;
case BLE_GAP_EVENT_CONN_UPDATE:
@@ -397,6 +401,23 @@ void NimbleController::NotifyBatteryLevel(uint8_t level) {
}
}
+void NimbleController::EnableRadio() {
+ bleController.EnableRadio();
+ bleController.Disconnect();
+ fastAdvCount = 0;
+ StartAdvertising();
+}
+
+void NimbleController::DisableRadio() {
+ bleController.DisableRadio();
+ if (bleController.IsConnected()) {
+ ble_gap_terminate(connectionHandle, BLE_ERR_REM_USER_CONN_TERM);
+ bleController.Disconnect();
+ } else {
+ ble_gap_adv_stop();
+ }
+}
+
void NimbleController::PersistBond(struct ble_gap_conn_desc& desc) {
union ble_store_key key;
union ble_store_value our_sec, peer_sec, peer_cccd_set[MYNEWT_VAL(BLE_STORE_MAX_CCCDS)] = {0};