Skip to content

Commit

Permalink
MusicService: Autostart music app on music start
Browse files Browse the repository at this point in the history
When starting music on a paired device, the music service will
automatically trigger the music app to open.
  • Loading branch information
vkareh committed Feb 7, 2024
1 parent 44be356 commit e9df27a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/components/ble/MusicService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
#include "components/ble/MusicService.h"
#include "components/ble/NimbleController.h"
#include "systemtask/SystemTask.h"
#include <cstring>

namespace {
Expand Down Expand Up @@ -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,
.access_cb = MusicCallback,
.arg = this,
Expand Down Expand Up @@ -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,
// leading to getProgress() returning an incorrect position.
if (playing) {
systemTask.PushMessage(Pinetime::System::Messages::OnMusicStarted);
trackProgressUpdateTime = xTaskGetTickCount();
} else {
trackProgress +=
Expand Down
8 changes: 7 additions & 1 deletion src/components/ble/MusicService.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@
#undef min

namespace Pinetime {

namespace System {
class SystemTask;
}

namespace Controllers {
class NimbleController;

class MusicService {
public:
explicit MusicService(NimbleController& nimble);
explicit MusicService(Pinetime::System::SystemTask& systemTask, NimbleController& nimble);

void Init();

Expand Down Expand Up @@ -87,6 +92,7 @@ namespace Pinetime {
bool repeat {false};
bool shuffle {false};

Pinetime::System::SystemTask& systemTask;
NimbleController& nimble;
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
anService {systemTask, notificationManager},
alertNotificationClient {systemTask, notificationManager},
currentTimeService {dateTimeController},
musicService {*this},
musicService {systemTask, *this},
weatherService {dateTimeController},
batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager},
Expand Down
9 changes: 9 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ void DisplayApp::Refresh() {
case Messages::NewNotification:
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
break;
case Messages::MusicStarted:
if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning);
}
// Load music app if not loaded
if (currentApp != Apps::Music) {
LoadNewScreen(Apps::Music, 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 @@ -15,6 +15,7 @@ namespace Pinetime {
ButtonLongerPressed,
ButtonDoubleClicked,
NewNotification,
MusicStarted,
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 @@ -24,6 +24,7 @@ namespace Pinetime {
OnNewHalfHour,
OnChargingEvent,
OnPairing,
OnMusicStarted,
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 @@ -385,6 +385,9 @@ void SystemTask::Work() {
nimbleController.DisableRadio();
}
break;
case Messages::OnMusicStarted:
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
break;
default:
break;
}
Expand Down

0 comments on commit e9df27a

Please sign in to comment.