Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
connectionHandle = event->connect.conn_handle;
bleController.Connect();
systemTask.PushMessage(Pinetime::System::Messages::BleConnected);
// Service discovery is deferred via systemtask

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment no longer true?

ble_gap_security_initiate(event->connect.conn_handle);
}
break;
Expand Down Expand Up @@ -269,6 +268,10 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
desc.sec_state.authenticated,
desc.sec_state.bonded,
desc.sec_state.key_size);

if (desc.sec_state.encrypted) {
systemTask.PushMessage(Pinetime::System::Messages::BleStartDiscovery);
}
}
break;

Expand Down
1 change: 1 addition & 0 deletions src/systemtask/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Pinetime {
OnNewHalfHour,
OnChargingEvent,
OnPairing,
BleStartDiscovery,
SetOffAlarm,
MeasureBatteryTimerExpired,
BatteryPercentageUpdated,
Expand Down
19 changes: 7 additions & 12 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,13 @@ void SystemTask::Work() {
break;
case Messages::BleConnected:
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NotifyDeviceActivity);
isBleDiscoveryTimerRunning = true;
bleDiscoveryTimer = 5;
isBleDiscoveryStarted = false;
break;
case Messages::BleStartDiscovery:
if (!isBleDiscoveryStarted) {
isBleDiscoveryStarted = true;
nimbleController.StartDiscovery();
}
Comment on lines -240 to +246

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My one concern with this change is that only the success case is explicitly covered in the code. When the nimbleController starts discovering, the isBleDiscoveryStarted member is set to true; when the discovery is successful and a connection is made, it is set back to false. I can imagine that discovery might time out or that a connection might fail, but neither of those conditions is represented in the Messages enum or in members of the SystemTask class. NimbleController might have this information (I did not check whether this is the case), but SystemTask does not seem to access the information if it exists. As far as I can tell, that means that SystemTask will keep the isBleDiscoveryStarted == true state indefinitely when things don't go as planned.

break;
case Messages::BleFirmwareUpdateStarted:
GoToRunning();
Expand Down Expand Up @@ -380,16 +385,6 @@ void SystemTask::Work() {
elapsed = xTaskGetTickCount() - lastStateUpdate;
if (elapsed >= stateUpdatePeriod) {
UpdateMotion();
if (isBleDiscoveryTimerRunning) {
if (bleDiscoveryTimer == 0) {
isBleDiscoveryTimerRunning = false;
// Services discovery is deferred from 3 seconds to avoid the conflicts between the host communicating with the
// target and vice-versa. I'm not sure if this is the right way to handle this...
nimbleController.StartDiscovery();
} else {
bleDiscoveryTimer--;
}
}
monitor.Process();
NoInit_BackUpTime = dateTimeController.CurrentDateTime();
if (nrf_gpio_pin_read(PinMap::Button) == 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/systemtask/SystemTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ namespace Pinetime {

static void Process(void* instance);
void Work();
bool isBleDiscoveryTimerRunning = false;
uint8_t bleDiscoveryTimer = 0;
bool isBleDiscoveryStarted = false;
TimerHandle_t measureBatteryTimer;
uint8_t wakeLocksHeld = 0;
SystemTaskState state = SystemTaskState::Running;
Expand Down