Skip to content

Commit ecf24a8

Browse files
committed
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.
1 parent 934e3a3 commit ecf24a8

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

src/components/ble/MusicService.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
#include "components/ble/MusicService.h"
1919
#include "components/ble/NimbleController.h"
20+
#include "systemtask/SystemTask.h"
2021
#include <cstring>
2122
#include <FreeRTOS.h>
2223
#include <task.h>
@@ -55,7 +56,8 @@ namespace {
5556
}
5657
}
5758

58-
Pinetime::Controllers::MusicService::MusicService(Pinetime::Controllers::NimbleController& nimble) : nimble(nimble) {
59+
Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::NimbleController& nimble)
60+
: systemTask {systemTask}, nimble(nimble) {
5961
characteristicDefinition[0] = {.uuid = &msEventCharUuid.u,
6062
.access_cb = MusicCallback,
6163
.arg = this,
@@ -154,6 +156,7 @@ int Pinetime::Controllers::MusicService::OnCommand(struct ble_gatt_access_ctxt*
154156
// These variables need to be updated, because the progress may not be updated immediately,
155157
// leading to getProgress() returning an incorrect position.
156158
if (playing) {
159+
systemTask.PushMessage(Pinetime::System::Messages::OnMusicStarted);
157160
trackProgressUpdateTime = xTaskGetTickCount();
158161
} else {
159162
trackProgress +=

src/components/ble/MusicService.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828
#include <FreeRTOS.h>
2929

3030
namespace Pinetime {
31+
32+
namespace System {
33+
class SystemTask;
34+
}
35+
3136
namespace Controllers {
3237
class NimbleController;
3338

3439
class MusicService {
3540
public:
36-
explicit MusicService(NimbleController& nimble);
41+
explicit MusicService(Pinetime::System::SystemTask& systemTask, NimbleController& nimble);
3742

3843
void Init();
3944

@@ -88,6 +93,7 @@ namespace Pinetime {
8893
bool repeat {false};
8994
bool shuffle {false};
9095

96+
Pinetime::System::SystemTask& systemTask;
9197
NimbleController& nimble;
9298
};
9399
}

src/components/ble/NimbleController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
4242
anService {systemTask, notificationManager},
4343
alertNotificationClient {systemTask, notificationManager},
4444
currentTimeService {dateTimeController},
45-
musicService {*this},
45+
musicService {systemTask, *this},
4646
weatherService {dateTimeController},
4747
batteryInformationService {batteryController},
4848
immediateAlertService {systemTask, notificationManager},

src/displayapp/DisplayApp.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ void DisplayApp::Refresh() {
361361
case Messages::NewNotification:
362362
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
363363
break;
364+
case Messages::MusicStarted:
365+
if (currentApp == Apps::Clock && AppAvailable(Apps::Music)) {
366+
if (state != States::Running) {
367+
PushMessageToSystemTask(System::Messages::GoToRunning);
368+
}
369+
LoadNewScreen(Apps::Music, DisplayApp::FullRefreshDirections::Up);
370+
}
371+
break;
364372
case Messages::TimerDone:
365373
if (state != States::Running) {
366374
PushMessageToSystemTask(System::Messages::GoToRunning);

src/displayapp/Messages.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Pinetime {
1515
ButtonLongerPressed,
1616
ButtonDoubleClicked,
1717
NewNotification,
18+
MusicStarted,
1819
TimerDone,
1920
BleFirmwareUpdateStarted,
2021
// Resets the screen timeout timer when awake

src/systemtask/Messages.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Pinetime {
2424
OnNewHalfHour,
2525
OnChargingEvent,
2626
OnPairing,
27+
OnMusicStarted,
2728
SetOffAlarm,
2829
MeasureBatteryTimerExpired,
2930
BatteryPercentageUpdated,

src/systemtask/SystemTask.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ void SystemTask::Work() {
358358
nimbleController.DisableRadio();
359359
}
360360
break;
361+
case Messages::OnMusicStarted:
362+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
363+
break;
361364
default:
362365
break;
363366
}

0 commit comments

Comments
 (0)