Skip to content

Commit 0e2b27d

Browse files
committed
Merge branch 'evergreen22-airplane-mode' into develop
2 parents 69e4ab6 + ef44b76 commit 0e2b27d

26 files changed

Lines changed: 370 additions & 107 deletions

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ list(APPEND SOURCE_FILES
449449
displayapp/screens/settings/SettingSetTime.cpp
450450
displayapp/screens/settings/SettingChimes.cpp
451451
displayapp/screens/settings/SettingShakeThreshold.cpp
452+
displayapp/screens/settings/SettingAirplaneMode.cpp
452453

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

src/components/ble/BleController.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
using namespace Pinetime::Controllers;
44

5+
bool Ble::IsConnected() const {
6+
return isConnected;
7+
}
8+
59
void Ble::Connect() {
610
isConnected = true;
711
}
@@ -10,6 +14,18 @@ void Ble::Disconnect() {
1014
isConnected = false;
1115
}
1216

17+
bool Ble::IsRadioEnabled() const {
18+
return isRadioEnabled;
19+
}
20+
21+
void Ble::EnableRadio() {
22+
isRadioEnabled = true;
23+
}
24+
25+
void Ble::DisableRadio() {
26+
isRadioEnabled = false;
27+
}
28+
1329
void Ble::StartFirmwareUpdate() {
1430
isFirmwareUpdating = true;
1531
}

src/components/ble/BleController.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ namespace Pinetime {
1212
enum class AddressTypes { Public, Random, RPA_Public, RPA_Random };
1313

1414
Ble() = default;
15-
bool IsConnected() const {
16-
return isConnected;
17-
}
15+
bool IsConnected() const;
1816
void Connect();
1917
void Disconnect();
2018

19+
bool IsRadioEnabled() const;
20+
void EnableRadio();
21+
void DisableRadio();
22+
2123
void StartFirmwareUpdate();
2224
void StopFirmwareUpdate();
2325
void FirmwareUpdateTotalBytes(uint32_t totalBytes);
@@ -57,6 +59,7 @@ namespace Pinetime {
5759

5860
private:
5961
bool isConnected = false;
62+
bool isRadioEnabled = true;
6063
bool isFirmwareUpdating = false;
6164
uint32_t firmwareUpdateTotalBytes = 0;
6265
uint32_t firmwareUpdateCurrentBytes = 0;

src/components/ble/NimbleController.cpp

Lines changed: 31 additions & 10 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.IsRadioEnabled() && !bleController.IsConnected()) {
188+
StartAdvertising();
189+
}
188190
break;
189191

190192
case BLE_GAP_EVENT_CONNECT:
@@ -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.IsConnected()) {
226+
bleController.Disconnect();
227+
fastAdvCount = 0;
228+
StartAdvertising();
229+
}
226230
break;
227231

228232
case BLE_GAP_EVENT_CONN_UPDATE:
@@ -397,6 +401,23 @@ void NimbleController::NotifyBatteryLevel(uint8_t level) {
397401
}
398402
}
399403

404+
void NimbleController::EnableRadio() {
405+
bleController.EnableRadio();
406+
bleController.Disconnect();
407+
fastAdvCount = 0;
408+
StartAdvertising();
409+
}
410+
411+
void NimbleController::DisableRadio() {
412+
bleController.DisableRadio();
413+
if (bleController.IsConnected()) {
414+
ble_gap_terminate(connectionHandle, BLE_ERR_REM_USER_CONN_TERM);
415+
bleController.Disconnect();
416+
} else {
417+
ble_gap_adv_stop();
418+
}
419+
}
420+
400421
void NimbleController::PersistBond(struct ble_gap_conn_desc& desc) {
401422
union ble_store_key key;
402423
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: 15 additions & 22 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,27 +42,17 @@ 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);
56-
57-
int OnDiscoveryEvent(uint16_t i, const ble_gatt_error* pError, const ble_gatt_svc* pSvc);
58-
int OnCTSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
59-
int OnANSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
60-
int OnCurrentTimeReadResult(uint16_t connectionHandle, const ble_gatt_error* error, ble_gatt_attr* attribute);
61-
int OnANSDescriptorDiscoveryEventCallback(uint16_t connectionHandle,
62-
const ble_gatt_error* error,
63-
uint16_t characteristicValueHandle,
64-
const ble_gatt_dsc* descriptor);
65-
6656
void StartDiscovery();
6757

6858
Pinetime::Controllers::MusicService& music() {
@@ -83,20 +73,23 @@ namespace Pinetime {
8373

8474
void RestartFastAdv() {
8575
fastAdvCount = 0;
86-
}
76+
};
77+
78+
void EnableRadio();
79+
void DisableRadio();
8780

8881
private:
8982
void PersistBond(struct ble_gap_conn_desc& desc);
9083
void RestoreBond();
9184

9285
static constexpr const char* deviceName = "InfiniTime";
9386
Pinetime::System::SystemTask& systemTask;
94-
Pinetime::Controllers::Ble& bleController;
87+
Ble& bleController;
9588
DateTime& dateTimeController;
96-
Pinetime::Controllers::NotificationManager& notificationManager;
89+
NotificationManager& notificationManager;
9790
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
98-
Pinetime::Controllers::FS& fs;
99-
Pinetime::Controllers::DfuService dfuService;
91+
FS& fs;
92+
DfuService dfuService;
10093

10194
DeviceInformationService deviceInformationService;
10295
CurrentTimeClient currentTimeClient;

src/components/settings/Settings.h

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,23 @@ namespace Pinetime {
1818
Shake = 3,
1919
};
2020
enum class Colors : uint8_t {
21-
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
21+
White,
22+
Silver,
23+
Gray,
24+
Black,
25+
Red,
26+
Maroon,
27+
Yellow,
28+
Olive,
29+
Lime,
30+
Green,
31+
Cyan,
32+
Teal,
33+
Blue,
34+
Navy,
35+
Magenta,
36+
Purple,
37+
Orange
2238
};
2339
struct PineTimeStyle {
2440
Colors ColorTime = Colors::Teal;
@@ -170,18 +186,29 @@ namespace Pinetime {
170186
}
171187
settings.brightLevel = level;
172188
};
189+
173190
Controllers::BrightnessController::Levels GetBrightness() const {
174191
return settings.brightLevel;
175192
};
176193

177-
void SetStepsGoal( uint32_t goal ) {
178-
if ( goal != settings.stepsGoal ) {
194+
void SetStepsGoal(uint32_t goal) {
195+
if (goal != settings.stepsGoal) {
179196
settingsChanged = true;
180197
}
181198
settings.stepsGoal = goal;
182199
};
183200

184-
uint32_t GetStepsGoal() const { return settings.stepsGoal; };
201+
uint32_t GetStepsGoal() const {
202+
return settings.stepsGoal;
203+
};
204+
205+
void SetBleRadioEnabled(bool enabled) {
206+
bleRadioEnabled = enabled;
207+
};
208+
209+
bool GetBleRadioEnabled() const {
210+
return bleRadioEnabled;
211+
};
185212

186213
private:
187214
Pinetime::Controllers::FS& fs;
@@ -210,6 +237,10 @@ namespace Pinetime {
210237

211238
uint8_t appMenu = 0;
212239
uint8_t settingsMenu = 0;
240+
/* airplaneMode is intentionally not saved with the other watch settings and initialized
241+
* to off (false) on every boot because we always want ble to be enabled on startup
242+
*/
243+
bool bleRadioEnabled = true;
213244

214245
void LoadSettingsFromFile();
215246
void SaveSettingsToFile();

src/displayapp/Apps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace Pinetime {
3838
SettingSetTime,
3939
SettingChimes,
4040
SettingShakeThreshold,
41+
SettingAirplaneMode,
4142
Error
4243
};
4344
}

src/displayapp/DisplayApp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "displayapp/screens/settings/SettingSetTime.h"
5050
#include "displayapp/screens/settings/SettingChimes.h"
5151
#include "displayapp/screens/settings/SettingShakeThreshold.h"
52+
#include "displayapp/screens/settings/SettingAirplaneMode.h"
5253

5354
#include "libs/lv_conf.h"
5455

@@ -292,6 +293,9 @@ void DisplayApp::Refresh() {
292293
case Messages::BleFirmwareUpdateStarted:
293294
LoadApp(Apps::FirmwareUpdate, DisplayApp::FullRefreshDirections::Down);
294295
break;
296+
case Messages::BleRadioEnableToggle:
297+
PushMessageToSystemTask(System::Messages::BleRadioEnableToggle);
298+
break;
295299
case Messages::UpdateDateTime:
296300
// Added to remove warning
297301
// What should happen here?
@@ -430,6 +434,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
430434
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController, motionController, *systemTask);
431435
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
432436
break;
437+
case Apps::SettingAirplaneMode:
438+
currentScreen = std::make_unique<Screens::SettingAirplaneMode>(this, settingsController);
439+
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
440+
break;
433441
case Apps::BatteryInfo:
434442
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
435443
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
@@ -21,7 +21,8 @@ namespace Pinetime {
2121
RestoreBrightness,
2222
ShowPairingKey,
2323
AlarmTriggered,
24-
Clock
24+
Clock,
25+
BleRadioEnableToggle
2526
};
2627
}
2728
}

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)