summaryrefslogtreecommitdiff
path: root/src/components/ble/NimbleController.cpp
diff options
context:
space:
mode:
authorJames A. Jerkins <evergreen@jamesjerkinscomputer.com>2021-12-23 20:30:14 -0600
committerJames A. Jerkins <evergreen@jamesjerkinscomputer.com>2021-12-23 20:30:14 -0600
commit319030d9e16e833cf8bff569a9ecfa452165ea27 (patch)
treeae2890204710ac41fd7f637ac1c367c09f671009 /src/components/ble/NimbleController.cpp
parent3b0b48020d96353fc6cd114aa80fc2fec98363a3 (diff)
Add airplane mode feature
Implements 'Airplane mode' feature to disable and enable bluetooth/ble Adds airplaneMode as a non-persisted setting Adds a setting menu for switching airplane mode on and off Displays an airplane symbol on the Digital watch face and the PineTimeStyle watch face when airplane mode is enabled Always enables bluetooth/ble on boot (disable airplane mode) Alphabetizes the settings menu options Style cleanups Closes #632
Diffstat (limited to 'src/components/ble/NimbleController.cpp')
-rw-r--r--src/components/ble/NimbleController.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp
index d8510bd3..d85ec5dc 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.GetConnectState() == Ble::ConnectStates::Disconnected) {
+ StartAdvertising();
+ }
break;
case BLE_GAP_EVENT_CONNECT:
@@ -197,12 +199,12 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
currentTimeClient.Reset();
alertNotificationClient.Reset();
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
- bleController.Disconnect();
+ bleController.SetConnectState(Ble::ConnectStates::Disconnected);
fastAdvCount = 0;
StartAdvertising();
} else {
connectionHandle = event->connect.conn_handle;
- bleController.Connect();
+ bleController.SetConnectState(Ble::ConnectStates::Connected);
systemTask.PushMessage(Pinetime::System::Messages::BleConnected);
// Service discovery is deferred via systemtask
}
@@ -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.GetConnectState() == Ble::ConnectStates::Connected) {
+ bleController.SetConnectState(Ble::ConnectStates::Disconnected);
+ fastAdvCount = 0;
+ StartAdvertising();
+ }
break;
case BLE_GAP_EVENT_CONN_UPDATE:
@@ -376,6 +380,22 @@ void NimbleController::NotifyBatteryLevel(uint8_t level) {
}
}
+void NimbleController::SwitchAirplaneMode(bool enabled) {
+ if (enabled) {
+ if (bleController.IsConnected()) {
+ bleController.SetConnectState(Ble::ConnectStates::Airplane);
+ ble_gap_terminate(connectionHandle, BLE_ERR_REM_USER_CONN_TERM);
+ } else {
+ bleController.SetConnectState(Ble::ConnectStates::Airplane);
+ ble_gap_adv_stop();
+ }
+ } else {
+ bleController.SetConnectState(Ble::ConnectStates::Disconnected);
+ fastAdvCount = 0;
+ StartAdvertising();
+ }
+}
+
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};