mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-10-22 15:11:51 +02:00
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:
parent
bcd353f060
commit
8010e1e970
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
#include "components/ble/MusicService.h"
|
||||
#include "components/ble/NimbleController.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include <cstring>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
@ -55,7 +56,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,
|
||||
|
@ -154,6 +156,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 +=
|
||||
|
|
|
@ -28,12 +28,17 @@
|
|||
#include <FreeRTOS.h>
|
||||
|
||||
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();
|
||||
|
||||
|
@ -88,6 +93,7 @@ namespace Pinetime {
|
|||
bool repeat {false};
|
||||
bool shuffle {false};
|
||||
|
||||
Pinetime::System::SystemTask& systemTask;
|
||||
NimbleController& nimble;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -339,6 +339,14 @@ void DisplayApp::Refresh() {
|
|||
case Messages::NewNotification:
|
||||
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
|
||||
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:
|
||||
if (state != States::Running) {
|
||||
PushMessageToSystemTask(System::Messages::GoToRunning);
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Pinetime {
|
|||
ButtonLongerPressed,
|
||||
ButtonDoubleClicked,
|
||||
NewNotification,
|
||||
MusicStarted,
|
||||
TimerDone,
|
||||
BleFirmwareUpdateStarted,
|
||||
// Resets the screen timeout timer when awake
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Pinetime {
|
|||
OnNewHalfHour,
|
||||
OnChargingEvent,
|
||||
OnPairing,
|
||||
OnMusicStarted,
|
||||
SetOffAlarm,
|
||||
MeasureBatteryTimerExpired,
|
||||
BatteryPercentageUpdated,
|
||||
|
|
|
@ -352,6 +352,9 @@ void SystemTask::Work() {
|
|||
nimbleController.DisableRadio();
|
||||
}
|
||||
break;
|
||||
case Messages::OnMusicStarted:
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue