-
-
Notifications
You must be signed in to change notification settings - Fork 968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Airplane mode feature (redesigned) #888
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
} | ||
} | ||
|
||
Comment on lines
+383
to
+398
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather have this be two functions without a boolean parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree. I see no reason to make the code larger. |
||
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}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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 { | ||
|
@@ -42,18 +42,19 @@ 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); | ||
|
||
/* these are not implemented yet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can safely remove those declarations of the methods are not implemented in NimbleController.cpp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't remove them because I wasn't sure if they had any value from a documentation standpoint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I forgot to remove them a long time ago. They are not needed since these functionalities are implemented is services. |
||
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); | ||
|
@@ -62,6 +63,7 @@ namespace Pinetime { | |
const ble_gatt_error* error, | ||
uint16_t characteristicValueHandle, | ||
const ble_gatt_dsc* descriptor); | ||
*/ | ||
|
||
void StartDiscovery(); | ||
|
||
|
@@ -83,20 +85,22 @@ namespace Pinetime { | |
|
||
void RestartFastAdv() { | ||
fastAdvCount = 0; | ||
} | ||
}; | ||
|
||
void SwitchAirplaneMode(bool enabled); | ||
|
||
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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should mix "connection state" (connected and disconnected are implemented, and other future states could be "error", "failed", "refused",...) with an "operating mode" (normal and airplane mode).
I think they are 2 distinct concept that should be kept separate :
What do you think?