From afc5add7e60aa1b837636601bd36880f381082d3 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 eb3a84c700..bfea93aaff 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 7617986e00..3e6c0e8f35 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -267,6 +267,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 1328f3636a..0e21f36d06 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 99986e78f5..d814b03415 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -396,6 +396,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; }