MusicService: Autostart music app on music start

When starting music on a paired device, the music service will
automatically trigger the music app to open if there is no app already
loaded.
This commit is contained in:
Victor Kareh 2024-02-06 15:41:59 -05:00
parent 57944151ba
commit ada69987c2
7 changed files with 25 additions and 3 deletions

View file

@ -17,6 +17,7 @@
*/ */
#include "components/ble/MusicService.h" #include "components/ble/MusicService.h"
#include "components/ble/NimbleController.h" #include "components/ble/NimbleController.h"
#include "systemtask/SystemTask.h"
#include <cstring> #include <cstring>
namespace { namespace {
@ -53,7 +54,8 @@ namespace {
} }
} }
Pinetime::Controllers::MusicService::MusicService(Pinetime::Controllers::NimbleController& nimble) : nimble(nimble) { Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::NimbleController& nimble)
: systemTask {systemTask}, nimble(nimble) {
characteristicDefinition[0] = {.uuid = &msEventCharUuid.u, characteristicDefinition[0] = {.uuid = &msEventCharUuid.u,
.access_cb = MusicCallback, .access_cb = MusicCallback,
.arg = this, .arg = this,
@ -152,6 +154,7 @@ int Pinetime::Controllers::MusicService::OnCommand(struct ble_gatt_access_ctxt*
// These variables need to be updated, because the progress may not be updated immediately, // These variables need to be updated, because the progress may not be updated immediately,
// leading to getProgress() returning an incorrect position. // leading to getProgress() returning an incorrect position.
if (playing) { if (playing) {
systemTask.PushMessage(Pinetime::System::Messages::OnMusicStarted);
trackProgressUpdateTime = xTaskGetTickCount(); trackProgressUpdateTime = xTaskGetTickCount();
} else { } else {
trackProgress += trackProgress +=

View file

@ -27,12 +27,17 @@
#undef min #undef min
namespace Pinetime { namespace Pinetime {
namespace System {
class SystemTask;
}
namespace Controllers { namespace Controllers {
class NimbleController; class NimbleController;
class MusicService { class MusicService {
public: public:
explicit MusicService(NimbleController& nimble); explicit MusicService(Pinetime::System::SystemTask& systemTask, NimbleController& nimble);
void Init(); void Init();
@ -87,6 +92,7 @@ namespace Pinetime {
bool repeat {false}; bool repeat {false};
bool shuffle {false}; bool shuffle {false};
Pinetime::System::SystemTask& systemTask;
NimbleController& nimble; NimbleController& nimble;
}; };
} }

View file

@ -42,7 +42,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
anService {systemTask, notificationManager}, anService {systemTask, notificationManager},
alertNotificationClient {systemTask, notificationManager}, alertNotificationClient {systemTask, notificationManager},
currentTimeService {dateTimeController}, currentTimeService {dateTimeController},
musicService {*this}, musicService {systemTask, *this},
weatherService {dateTimeController}, weatherService {dateTimeController},
batteryInformationService {batteryController}, batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager}, immediateAlertService {systemTask, notificationManager},

View file

@ -327,6 +327,14 @@ void DisplayApp::Refresh() {
case Messages::NewNotification: case Messages::NewNotification:
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down); LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
break; break;
case Messages::MusicStarted:
if (currentApp == Apps::Clock && AppAvailable(Apps::Music)) {
if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning);
}
LoadNewScreen(Apps::Music, DisplayApp::FullRefreshDirections::Up);
}
break;
case Messages::TimerDone: case Messages::TimerDone:
if (state != States::Running) { if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning); PushMessageToSystemTask(System::Messages::GoToRunning);

View file

@ -15,6 +15,7 @@ namespace Pinetime {
ButtonLongerPressed, ButtonLongerPressed,
ButtonDoubleClicked, ButtonDoubleClicked,
NewNotification, NewNotification,
MusicStarted,
TimerDone, TimerDone,
BleFirmwareUpdateStarted, BleFirmwareUpdateStarted,
DimScreen, DimScreen,

View file

@ -24,6 +24,7 @@ namespace Pinetime {
OnNewHalfHour, OnNewHalfHour,
OnChargingEvent, OnChargingEvent,
OnPairing, OnPairing,
OnMusicStarted,
SetOffAlarm, SetOffAlarm,
MeasureBatteryTimerExpired, MeasureBatteryTimerExpired,
BatteryPercentageUpdated, BatteryPercentageUpdated,

View file

@ -402,6 +402,9 @@ void SystemTask::Work() {
nimbleController.DisableRadio(); nimbleController.DisableRadio();
} }
break; break;
case Messages::OnMusicStarted:
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
break;
default: default:
break; break;
} }