From f985202491c04ce667992248e7f7495e9fb6fe15 Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Fri, 9 Feb 2024 13:35:28 -0500 Subject: [PATCH] NavigationService: Autostart navigation app on nav command 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. --- src/components/ble/NavigationService.cpp | 4 +++- src/components/ble/NavigationService.h | 9 ++++++++- src/components/ble/NimbleController.cpp | 1 + src/displayapp/DisplayApp.cpp | 8 ++++++++ src/displayapp/Messages.h | 1 + src/systemtask/Messages.h | 1 + src/systemtask/SystemTask.cpp | 3 +++ 7 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index 4922237cb3..0e6563b200 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -17,6 +17,7 @@ */ #include "components/ble/NavigationService.h" +#include "systemtask/SystemTask.h" namespace { // 0001yyxx-78fc-48fe-8e23-433b3a1942d0 @@ -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, @@ -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; } diff --git a/src/components/ble/NavigationService.h b/src/components/ble/NavigationService.h index 03e79ac587..bab2cb77a4 100644 --- a/src/components/ble/NavigationService.h +++ b/src/components/ble/NavigationService.h @@ -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(); @@ -53,6 +58,8 @@ namespace Pinetime { std::string m_narrative; std::string m_manDist; int m_progress; + + Pinetime::System::SystemTask& systemTask; }; } } diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 1a8ef38797..4cecd76690 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -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}, diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 14d1f67e38..b5513842e7 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -347,6 +347,14 @@ void DisplayApp::Refresh() { LoadNewScreen(Apps::Music, DisplayApp::FullRefreshDirections::Up); } break; + case Messages::NavStarted: + if (currentApp == Apps::Clock && AppAvailable(Apps::Navigation)) { + 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); diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index 68d1abc86e..ce35f930d0 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -16,6 +16,7 @@ namespace Pinetime { ButtonDoubleClicked, NewNotification, MusicStarted, + NavStarted, TimerDone, BleFirmwareUpdateStarted, DimScreen, diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index 2cb63a399c..c53d6c5818 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -25,6 +25,7 @@ namespace Pinetime { OnChargingEvent, OnPairing, OnMusicStarted, + OnNavChange, SetOffAlarm, MeasureBatteryTimerExpired, BatteryPercentageUpdated, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 6e3bfe56a4..1b31b79efe 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -405,6 +405,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; }