Skip to content

Commit

Permalink
NavigationService: Autostart navigation app on nav command
Browse files Browse the repository at this point in the history
When a paired device sends a navigation message, the navigation service
will automatically trigger the navigation app to open if there is no app
already loaded.
  • Loading branch information
vkareh committed Feb 12, 2024
1 parent 34d8149 commit 77850c5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/ble/NavigationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "components/ble/NavigationService.h"
#include "systemtask/SystemTask.h"

namespace {
// 0001yyxx-78fc-48fe-8e23-433b3a1942d0
Expand All @@ -43,7 +44,7 @@ namespace {
}
} // namespace

Pinetime::Controllers::NavigationService::NavigationService() {
Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& systemTask) : systemTask {systemTask} {
characteristicDefinition[0] = {.uuid = &navFlagCharUuid.u,
.access_cb = NAVCallback,
.arg = this,
Expand Down Expand Up @@ -96,6 +97,7 @@ int Pinetime::Controllers::NavigationService::OnCommand(struct ble_gatt_access_c
} else if (ble_uuid_cmp(ctxt->chr->uuid, &navProgressCharUuid.u) == 0) {
m_progress = data[0];
}
systemTask.PushMessage(Pinetime::System::Messages::OnNavChange);
}
return 0;
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/ble/NavigationService.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
#undef min

namespace Pinetime {

namespace System {
class SystemTask;
}

namespace Controllers {

class NavigationService {
public:
NavigationService();
explicit NavigationService(Pinetime::System::SystemTask& systemTask);

void Init();

Expand All @@ -53,6 +58,8 @@ namespace Pinetime {
std::string m_narrative;
std::string m_manDist;
int m_progress;

Pinetime::System::SystemTask& systemTask;
};
}
}
1 change: 1 addition & 0 deletions src/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
currentTimeService {dateTimeController},
musicService {systemTask, *this},
weatherService {dateTimeController},
navService {systemTask},
batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager},
heartRateService {*this, heartRateController},
Expand Down
8 changes: 8 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ void DisplayApp::Refresh() {
LoadNewScreen(Apps::Music, DisplayApp::FullRefreshDirections::Up);
}
break;
case Messages::NavStarted:
if (currentApp == Apps::Clock) {
if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning);
}
LoadNewScreen(Apps::Navigation, DisplayApp::FullRefreshDirections::Up);
}
break;
case Messages::TimerDone:
if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning);
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Pinetime {
ButtonDoubleClicked,
NewNotification,
MusicStarted,
NavStarted,
TimerDone,
BleFirmwareUpdateStarted,
DimScreen,
Expand Down
1 change: 1 addition & 0 deletions src/systemtask/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Pinetime {
OnChargingEvent,
OnPairing,
OnMusicStarted,
OnNavChange,
SetOffAlarm,
MeasureBatteryTimerExpired,
BatteryPercentageUpdated,
Expand Down
3 changes: 3 additions & 0 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ void SystemTask::Work() {
case Messages::OnMusicStarted:
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
break;
case Messages::OnNavChange:
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NavStarted);
break;
default:
break;
}
Expand Down

0 comments on commit 77850c5

Please sign in to comment.