Skip to content

Commit

Permalink
Merge branch 'evergreen22-airplane-mode' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JF002 committed Feb 20, 2022
2 parents 69e4ab6 + ef44b76 commit 0e2b27d
Show file tree
Hide file tree
Showing 26 changed files with 370 additions and 107 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingSetTime.cpp
displayapp/screens/settings/SettingChimes.cpp
displayapp/screens/settings/SettingShakeThreshold.cpp
displayapp/screens/settings/SettingAirplaneMode.cpp

## Watch faces
displayapp/icons/bg_clock.c
Expand Down
16 changes: 16 additions & 0 deletions src/components/ble/BleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

using namespace Pinetime::Controllers;

bool Ble::IsConnected() const {
return isConnected;
}

void Ble::Connect() {
isConnected = true;
}
Expand All @@ -10,6 +14,18 @@ void Ble::Disconnect() {
isConnected = false;
}

bool Ble::IsRadioEnabled() const {
return isRadioEnabled;
}

void Ble::EnableRadio() {
isRadioEnabled = true;
}

void Ble::DisableRadio() {
isRadioEnabled = false;
}

void Ble::StartFirmwareUpdate() {
isFirmwareUpdating = true;
}
Expand Down
9 changes: 6 additions & 3 deletions src/components/ble/BleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ namespace Pinetime {
enum class AddressTypes { Public, Random, RPA_Public, RPA_Random };

Ble() = default;
bool IsConnected() const {
return isConnected;
}
bool IsConnected() const;
void Connect();
void Disconnect();

bool IsRadioEnabled() const;
void EnableRadio();
void DisableRadio();

void StartFirmwareUpdate();
void StopFirmwareUpdate();
void FirmwareUpdateTotalBytes(uint32_t totalBytes);
Expand Down Expand Up @@ -57,6 +59,7 @@ namespace Pinetime {

private:
bool isConnected = false;
bool isRadioEnabled = true;
bool isFirmwareUpdating = false;
uint32_t firmwareUpdateTotalBytes = 0;
uint32_t firmwareUpdateCurrentBytes = 0;
Expand Down
41 changes: 31 additions & 10 deletions src/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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};
Expand Down
37 changes: 15 additions & 22 deletions src/components/ble/NimbleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "components/ble/CurrentTimeService.h"
#include "components/ble/DeviceInformationService.h"
#include "components/ble/DfuService.h"
#include "components/ble/FSService.h"
#include "components/ble/HeartRateService.h"
#include "components/ble/ImmediateAlertService.h"
#include "components/ble/MusicService.h"
Expand All @@ -22,7 +23,6 @@
#include "components/ble/MotionService.h"
#include "components/ble/weather/WeatherService.h"
#include "components/fs/FS.h"
#include "components/ble/FSService.h"

namespace Pinetime {
namespace Drivers {
Expand All @@ -42,27 +42,17 @@ namespace Pinetime {

public:
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,
Pinetime::Controllers::FS& fs);
HeartRateController& heartRateController,
MotionController& motionController,
FS& fs);
void Init();
void StartAdvertising();
int OnGAPEvent(ble_gap_event* event);

int OnDiscoveryEvent(uint16_t i, const ble_gatt_error* pError, const ble_gatt_svc* pSvc);
int OnCTSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
int OnANSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
int OnCurrentTimeReadResult(uint16_t connectionHandle, const ble_gatt_error* error, ble_gatt_attr* attribute);
int OnANSDescriptorDiscoveryEventCallback(uint16_t connectionHandle,
const ble_gatt_error* error,
uint16_t characteristicValueHandle,
const ble_gatt_dsc* descriptor);

void StartDiscovery();

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

void RestartFastAdv() {
fastAdvCount = 0;
}
};

void EnableRadio();
void DisableRadio();

private:
void PersistBond(struct ble_gap_conn_desc& desc);
void RestoreBond();

static constexpr const char* deviceName = "InfiniTime";
Pinetime::System::SystemTask& systemTask;
Pinetime::Controllers::Ble& bleController;
Ble& bleController;
DateTime& dateTimeController;
Pinetime::Controllers::NotificationManager& notificationManager;
NotificationManager& notificationManager;
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
Pinetime::Controllers::FS& fs;
Pinetime::Controllers::DfuService dfuService;
FS& fs;
DfuService dfuService;

DeviceInformationService deviceInformationService;
CurrentTimeClient currentTimeClient;
Expand Down
39 changes: 35 additions & 4 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ namespace Pinetime {
Shake = 3,
};
enum class Colors : uint8_t {
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
White,
Silver,
Gray,
Black,
Red,
Maroon,
Yellow,
Olive,
Lime,
Green,
Cyan,
Teal,
Blue,
Navy,
Magenta,
Purple,
Orange
};
struct PineTimeStyle {
Colors ColorTime = Colors::Teal;
Expand Down Expand Up @@ -170,18 +186,29 @@ namespace Pinetime {
}
settings.brightLevel = level;
};

Controllers::BrightnessController::Levels GetBrightness() const {
return settings.brightLevel;
};

void SetStepsGoal( uint32_t goal ) {
if ( goal != settings.stepsGoal ) {
void SetStepsGoal(uint32_t goal) {
if (goal != settings.stepsGoal) {
settingsChanged = true;
}
settings.stepsGoal = goal;
};

uint32_t GetStepsGoal() const { return settings.stepsGoal; };
uint32_t GetStepsGoal() const {
return settings.stepsGoal;
};

void SetBleRadioEnabled(bool enabled) {
bleRadioEnabled = enabled;
};

bool GetBleRadioEnabled() const {
return bleRadioEnabled;
};

private:
Pinetime::Controllers::FS& fs;
Expand Down Expand Up @@ -210,6 +237,10 @@ namespace Pinetime {

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

void LoadSettingsFromFile();
void SaveSettingsToFile();
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Pinetime {
SettingSetTime,
SettingChimes,
SettingShakeThreshold,
SettingAirplaneMode,
Error
};
}
Expand Down
8 changes: 8 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "displayapp/screens/settings/SettingSetTime.h"
#include "displayapp/screens/settings/SettingChimes.h"
#include "displayapp/screens/settings/SettingShakeThreshold.h"
#include "displayapp/screens/settings/SettingAirplaneMode.h"

#include "libs/lv_conf.h"

Expand Down Expand Up @@ -292,6 +293,9 @@ void DisplayApp::Refresh() {
case Messages::BleFirmwareUpdateStarted:
LoadApp(Apps::FirmwareUpdate, DisplayApp::FullRefreshDirections::Down);
break;
case Messages::BleRadioEnableToggle:
PushMessageToSystemTask(System::Messages::BleRadioEnableToggle);
break;
case Messages::UpdateDateTime:
// Added to remove warning
// What should happen here?
Expand Down Expand Up @@ -430,6 +434,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController, motionController, *systemTask);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingAirplaneMode:
currentScreen = std::make_unique<Screens::SettingAirplaneMode>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::BatteryInfo:
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
Expand Down
3 changes: 2 additions & 1 deletion src/displayapp/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace Pinetime {
RestoreBrightness,
ShowPairingKey,
AlarmTriggered,
Clock
Clock,
BleRadioEnableToggle
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/fonts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Do not enable font compression and horizontal subpixel hinting
* 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`
* Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following
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`
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`
* Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts`
* Add the font .c file path to src/CMakeLists.txt
* Add an LV_FONT_DECLARE line in src/libs/lv_conf.h
Expand Down
Loading

0 comments on commit 0e2b27d

Please sign in to comment.