Skip to content

Commit 319030d

Browse files
committed
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
1 parent 3b0b480 commit 319030d

23 files changed

Lines changed: 307 additions & 99 deletions

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ list(APPEND SOURCE_FILES
448448
displayapp/screens/settings/SettingPineTimeStyle.cpp
449449
displayapp/screens/settings/SettingSetDate.cpp
450450
displayapp/screens/settings/SettingSetTime.cpp
451+
displayapp/screens/settings/SettingAirplaneMode.cpp
451452

452453
## Watch faces
453454
displayapp/icons/bg_clock.c

src/components/ble/BleController.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
using namespace Pinetime::Controllers;
44

5-
void Ble::Connect() {
6-
isConnected = true;
5+
void Ble::SetConnectState(Ble::ConnectStates newState) {
6+
connectionState = newState;
77
}
88

9-
void Ble::Disconnect() {
10-
isConnected = false;
9+
Ble::ConnectStates Ble::GetConnectState() const {
10+
return connectionState;
1111
}
1212

1313
void Ble::StartFirmwareUpdate() {

src/components/ble/BleController.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ namespace Pinetime {
1010
using BleAddress = std::array<uint8_t, 6>;
1111
enum class FirmwareUpdateStates { Idle, Running, Validated, Error };
1212
enum class AddressTypes { Public, Random, RPA_Public, RPA_Random };
13+
enum class ConnectStates { Disconnected, Connected, Airplane };
1314

1415
Ble() = default;
1516
bool IsConnected() const {
16-
return isConnected;
17+
return (connectionState == ConnectStates::Connected);
1718
}
18-
void Connect();
19-
void Disconnect();
19+
void SetConnectState(ConnectStates newState);
20+
ConnectStates GetConnectState() const;
2021

2122
void StartFirmwareUpdate();
2223
void StopFirmwareUpdate();
@@ -56,7 +57,7 @@ namespace Pinetime {
5657
}
5758

5859
private:
59-
bool isConnected = false;
60+
ConnectStates connectionState = ConnectStates::Disconnected;
6061
bool isFirmwareUpdating = false;
6162
uint32_t firmwareUpdateTotalBytes = 0;
6263
uint32_t firmwareUpdateCurrentBytes = 0;

src/components/ble/NimbleController.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
using namespace Pinetime::Controllers;
2424

2525
NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
26-
Pinetime::Controllers::Ble& bleController,
26+
Ble& bleController,
2727
DateTime& dateTimeController,
28-
Pinetime::Controllers::NotificationManager& notificationManager,
29-
Controllers::Battery& batteryController,
28+
NotificationManager& notificationManager,
29+
Battery& batteryController,
3030
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
31-
Controllers::HeartRateController& heartRateController,
32-
Controllers::MotionController& motionController,
33-
Controllers::FS& fs)
31+
HeartRateController& heartRateController,
32+
MotionController& motionController,
33+
FS& fs)
3434
: systemTask {systemTask},
3535
bleController {bleController},
3636
dateTimeController {dateTimeController},
@@ -184,7 +184,9 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
184184
case BLE_GAP_EVENT_ADV_COMPLETE:
185185
NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_ADV_COMPLETE");
186186
NRF_LOG_INFO("reason=%d; status=%0X", event->adv_complete.reason, event->connect.status);
187-
StartAdvertising();
187+
if (bleController.GetConnectState() == Ble::ConnectStates::Disconnected) {
188+
StartAdvertising();
189+
}
188190
break;
189191

190192
case BLE_GAP_EVENT_CONNECT:
@@ -197,12 +199,12 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
197199
currentTimeClient.Reset();
198200
alertNotificationClient.Reset();
199201
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
200-
bleController.Disconnect();
202+
bleController.SetConnectState(Ble::ConnectStates::Disconnected);
201203
fastAdvCount = 0;
202204
StartAdvertising();
203205
} else {
204206
connectionHandle = event->connect.conn_handle;
205-
bleController.Connect();
207+
bleController.SetConnectState(Ble::ConnectStates::Connected);
206208
systemTask.PushMessage(Pinetime::System::Messages::BleConnected);
207209
// Service discovery is deferred via systemtask
208210
}
@@ -220,9 +222,11 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
220222
currentTimeClient.Reset();
221223
alertNotificationClient.Reset();
222224
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
223-
bleController.Disconnect();
224-
fastAdvCount = 0;
225-
StartAdvertising();
225+
if (bleController.GetConnectState() == Ble::ConnectStates::Connected) {
226+
bleController.SetConnectState(Ble::ConnectStates::Disconnected);
227+
fastAdvCount = 0;
228+
StartAdvertising();
229+
}
226230
break;
227231

228232
case BLE_GAP_EVENT_CONN_UPDATE:
@@ -376,6 +380,22 @@ void NimbleController::NotifyBatteryLevel(uint8_t level) {
376380
}
377381
}
378382

383+
void NimbleController::SwitchAirplaneMode(bool enabled) {
384+
if (enabled) {
385+
if (bleController.IsConnected()) {
386+
bleController.SetConnectState(Ble::ConnectStates::Airplane);
387+
ble_gap_terminate(connectionHandle, BLE_ERR_REM_USER_CONN_TERM);
388+
} else {
389+
bleController.SetConnectState(Ble::ConnectStates::Airplane);
390+
ble_gap_adv_stop();
391+
}
392+
} else {
393+
bleController.SetConnectState(Ble::ConnectStates::Disconnected);
394+
fastAdvCount = 0;
395+
StartAdvertising();
396+
}
397+
}
398+
379399
void NimbleController::PersistBond(struct ble_gap_conn_desc& desc) {
380400
union ble_store_key key;
381401
union ble_store_value our_sec, peer_sec, peer_cccd_set[MYNEWT_VAL(BLE_STORE_MAX_CCCDS)] = {0};

src/components/ble/NimbleController.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "components/ble/CurrentTimeService.h"
1515
#include "components/ble/DeviceInformationService.h"
1616
#include "components/ble/DfuService.h"
17+
#include "components/ble/FSService.h"
1718
#include "components/ble/HeartRateService.h"
1819
#include "components/ble/ImmediateAlertService.h"
1920
#include "components/ble/MusicService.h"
@@ -22,7 +23,6 @@
2223
#include "components/ble/MotionService.h"
2324
#include "components/ble/weather/WeatherService.h"
2425
#include "components/fs/FS.h"
25-
#include "components/ble/FSService.h"
2626

2727
namespace Pinetime {
2828
namespace Drivers {
@@ -42,18 +42,19 @@ namespace Pinetime {
4242

4343
public:
4444
NimbleController(Pinetime::System::SystemTask& systemTask,
45-
Pinetime::Controllers::Ble& bleController,
45+
Ble& bleController,
4646
DateTime& dateTimeController,
47-
Pinetime::Controllers::NotificationManager& notificationManager,
48-
Controllers::Battery& batteryController,
47+
NotificationManager& notificationManager,
48+
Battery& batteryController,
4949
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
50-
Controllers::HeartRateController& heartRateController,
51-
Controllers::MotionController& motionController,
52-
Pinetime::Controllers::FS& fs);
50+
HeartRateController& heartRateController,
51+
MotionController& motionController,
52+
FS& fs);
5353
void Init();
5454
void StartAdvertising();
5555
int OnGAPEvent(ble_gap_event* event);
5656

57+
/* these are not implemented yet
5758
int OnDiscoveryEvent(uint16_t i, const ble_gatt_error* pError, const ble_gatt_svc* pSvc);
5859
int OnCTSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
5960
int OnANSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
@@ -62,6 +63,7 @@ namespace Pinetime {
6263
const ble_gatt_error* error,
6364
uint16_t characteristicValueHandle,
6465
const ble_gatt_dsc* descriptor);
66+
*/
6567

6668
void StartDiscovery();
6769

@@ -83,20 +85,22 @@ namespace Pinetime {
8385

8486
void RestartFastAdv() {
8587
fastAdvCount = 0;
86-
}
88+
};
89+
90+
void SwitchAirplaneMode(bool enabled);
8791

8892
private:
8993
void PersistBond(struct ble_gap_conn_desc& desc);
9094
void RestoreBond();
9195

9296
static constexpr const char* deviceName = "InfiniTime";
9397
Pinetime::System::SystemTask& systemTask;
94-
Pinetime::Controllers::Ble& bleController;
98+
Ble& bleController;
9599
DateTime& dateTimeController;
96-
Pinetime::Controllers::NotificationManager& notificationManager;
100+
NotificationManager& notificationManager;
97101
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
98-
Pinetime::Controllers::FS& fs;
99-
Pinetime::Controllers::DfuService dfuService;
102+
FS& fs;
103+
DfuService dfuService;
100104

101105
DeviceInformationService deviceInformationService;
102106
CurrentTimeClient currentTimeClient;

src/components/settings/Settings.h

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@ namespace Pinetime {
1717
RaiseWrist = 2,
1818
};
1919
enum class Colors : uint8_t {
20-
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
20+
White,
21+
Silver,
22+
Gray,
23+
Black,
24+
Red,
25+
Maroon,
26+
Yellow,
27+
Olive,
28+
Lime,
29+
Green,
30+
Cyan,
31+
Teal,
32+
Blue,
33+
Navy,
34+
Magenta,
35+
Purple,
36+
Orange
2137
};
2238
struct PineTimeStyle {
2339
Colors ColorTime = Colors::Teal;
@@ -146,18 +162,29 @@ namespace Pinetime {
146162
}
147163
settings.brightLevel = level;
148164
};
165+
149166
Controllers::BrightnessController::Levels GetBrightness() const {
150167
return settings.brightLevel;
151168
};
152169

153-
void SetStepsGoal( uint32_t goal ) {
154-
if ( goal != settings.stepsGoal ) {
170+
void SetStepsGoal(uint32_t goal) {
171+
if (goal != settings.stepsGoal) {
155172
settingsChanged = true;
156173
}
157174
settings.stepsGoal = goal;
158175
};
159176

160-
uint32_t GetStepsGoal() const { return settings.stepsGoal; };
177+
uint32_t GetStepsGoal() const {
178+
return settings.stepsGoal;
179+
};
180+
181+
void SetAirplaneMode(bool mode) {
182+
airplaneMode = mode;
183+
};
184+
185+
bool GetAirplaneMode() const {
186+
return airplaneMode;
187+
};
161188

162189
private:
163190
Pinetime::Controllers::FS& fs;
@@ -185,6 +212,10 @@ namespace Pinetime {
185212

186213
uint8_t appMenu = 0;
187214
uint8_t settingsMenu = 0;
215+
/* airplaneMode is intentionally not saved with the other watch settings and initialized
216+
* to off (false) on every boot because we always want ble to be enabled on startup
217+
*/
218+
bool airplaneMode = false;
188219

189220
void LoadSettingsFromFile();
190221
void SaveSettingsToFile();

src/displayapp/Apps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ namespace Pinetime {
3737
SettingPineTimeStyle,
3838
SettingSetDate,
3939
SettingSetTime,
40-
Error,
40+
SettingAirplaneMode,
41+
Error
4142
};
4243
}
4344
}

src/displayapp/DisplayApp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "displayapp/screens/settings/SettingPineTimeStyle.h"
4949
#include "displayapp/screens/settings/SettingSetDate.h"
5050
#include "displayapp/screens/settings/SettingSetTime.h"
51+
#include "displayapp/screens/settings/SettingAirplaneMode.h"
5152

5253
#include "libs/lv_conf.h"
5354

@@ -289,6 +290,9 @@ void DisplayApp::Refresh() {
289290
case Messages::BleFirmwareUpdateStarted:
290291
LoadApp(Apps::FirmwareUpdate, DisplayApp::FullRefreshDirections::Down);
291292
break;
293+
case Messages::AirplaneModeToggle:
294+
PushMessageToSystemTask(System::Messages::AirplaneModeToggle);
295+
break;
292296
case Messages::UpdateDateTime:
293297
// Added to remove warning
294298
// What should happen here?
@@ -420,6 +424,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
420424
currentScreen = std::make_unique<Screens::SettingPineTimeStyle>(this, settingsController);
421425
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
422426
break;
427+
case Apps::SettingAirplaneMode:
428+
currentScreen = std::make_unique<Screens::SettingAirplaneMode>(this, settingsController);
429+
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
430+
break;
423431
case Apps::BatteryInfo:
424432
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
425433
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);

src/displayapp/Messages.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace Pinetime {
2020
DimScreen,
2121
RestoreBrightness,
2222
ShowPairingKey,
23-
AlarmTriggered
23+
AlarmTriggered,
24+
AirplaneModeToggle
2425
};
2526
}
2627
}

src/displayapp/fonts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Do not enable font compression and horizontal subpixel hinting
1414
* Load the file `JetBrainsMono-Bold.tff` (use the file in this repo to ensure the version matches) and specify the following range : `0x20-0x7f, 0x410-0x44f`
1515
* Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following
16-
range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015`
16+
range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf072`
1717
* Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts`
1818
* Add the font .c file path to src/CMakeLists.txt
1919
* Add an LV_FONT_DECLARE line in src/libs/lv_conf.h

0 commit comments

Comments
 (0)