2021-05-16 23:16:50 +00:00
|
|
|
/* Copyright (C) 2020-2021 JF, Adam Pigg, Avamander
|
2020-10-11 00:11:55 +00:00
|
|
|
|
|
|
|
This file is part of InfiniTime.
|
|
|
|
|
|
|
|
InfiniTime is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
InfiniTime is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-13 11:40:39 +00:00
|
|
|
#pragma once
|
2020-07-20 20:28:21 +00:00
|
|
|
|
2020-07-13 11:40:39 +00:00
|
|
|
#include <cstdint>
|
2020-11-15 14:05:51 +00:00
|
|
|
#include <string>
|
|
|
|
#define min // workaround: nimble's min/max macros conflict with libstdc++
|
|
|
|
#define max
|
2020-07-13 11:40:39 +00:00
|
|
|
#include <host/ble_gap.h>
|
|
|
|
#include <host/ble_uuid.h>
|
2020-11-15 14:05:51 +00:00
|
|
|
#undef max
|
|
|
|
#undef min
|
2020-07-13 11:40:39 +00:00
|
|
|
|
|
|
|
namespace Pinetime {
|
2020-07-20 20:28:21 +00:00
|
|
|
namespace System {
|
|
|
|
class SystemTask;
|
|
|
|
}
|
2020-07-13 11:40:39 +00:00
|
|
|
namespace Controllers {
|
|
|
|
class MusicService {
|
2021-04-24 09:00:45 +00:00
|
|
|
public:
|
2021-04-18 17:28:14 +00:00
|
|
|
explicit MusicService(Pinetime::System::SystemTask& system);
|
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
void Init();
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
int OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt);
|
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
void event(char event);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-05-16 23:08:12 +00:00
|
|
|
std::string getArtist() const;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-05-16 23:08:12 +00:00
|
|
|
std::string getTrack() const;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-05-16 23:08:12 +00:00
|
|
|
std::string getAlbum() const;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-05-16 23:08:12 +00:00
|
|
|
int getProgress() const;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-05-16 23:08:12 +00:00
|
|
|
int getTrackLength() const;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-05-16 23:08:12 +00:00
|
|
|
float getPlaybackSpeed() const;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-05-16 23:08:12 +00:00
|
|
|
bool isPlaying() const;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
static const char EVENT_MUSIC_OPEN = 0xe0;
|
|
|
|
static const char EVENT_MUSIC_PLAY = 0x00;
|
|
|
|
static const char EVENT_MUSIC_PAUSE = 0x01;
|
|
|
|
static const char EVENT_MUSIC_NEXT = 0x03;
|
|
|
|
static const char EVENT_MUSIC_PREV = 0x04;
|
|
|
|
static const char EVENT_MUSIC_VOLUP = 0x05;
|
|
|
|
static const char EVENT_MUSIC_VOLDOWN = 0x06;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
enum MusicStatus { NotPlaying = 0x00, Playing = 0x01 };
|
|
|
|
|
2021-04-24 09:00:45 +00:00
|
|
|
private:
|
2020-10-11 00:11:55 +00:00
|
|
|
struct ble_gatt_chr_def characteristicDefinition[14];
|
|
|
|
struct ble_gatt_svc_def serviceDefinition[2];
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
uint16_t eventHandle;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
std::string artistName;
|
|
|
|
std::string albumName;
|
|
|
|
std::string trackName;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
bool playing;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
int trackProgress;
|
|
|
|
int trackLength;
|
|
|
|
int trackNumber;
|
|
|
|
int tracksTotal;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
float playbackSpeed;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2020-10-11 00:11:55 +00:00
|
|
|
bool repeat;
|
|
|
|
bool shuffle;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
Pinetime::System::SystemTask& m_system;
|
2020-07-13 11:40:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|