summaryrefslogtreecommitdiff
path: root/src/Components/Ble
diff options
context:
space:
mode:
authorAdam Pigg <adam@piggz.co.uk>2020-07-20 21:28:21 +0100
committerAdam Pigg <adam@piggz.co.uk>2020-07-20 21:28:21 +0100
commit5713eac1045394928de19e76fd00a172f63bffa7 (patch)
treea20e130e01147c4afc89981d7bcfa6773dc6445e /src/Components/Ble
parent686e826f4e656546523e989535c74f286a91855b (diff)
Fully implement music app and service
SystemTask can return a reference to the nimbleController The nimbleController can return a reference to the musicService The musicService get a connection handle from the nimbleController The musicApp communicated directly with the musicService
Diffstat (limited to 'src/Components/Ble')
-rw-r--r--src/Components/Ble/MusicService.cpp20
-rw-r--r--src/Components/Ble/MusicService.h18
-rw-r--r--src/Components/Ble/NimbleController.cpp8
-rw-r--r--src/Components/Ble/NimbleController.h5
4 files changed, 37 insertions, 14 deletions
diff --git a/src/Components/Ble/MusicService.cpp b/src/Components/Ble/MusicService.cpp
index 080a814c..5ec76697 100644
--- a/src/Components/Ble/MusicService.cpp
+++ b/src/Components/Ble/MusicService.cpp
@@ -1,3 +1,4 @@
+#include <SystemTask/SystemTask.h>
#include "MusicService.h"
int MSCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
@@ -5,7 +6,7 @@ int MSCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_acces
return musicService->OnCommand(conn_handle, attr_handle, ctxt);
}
-Pinetime::Controllers::MusicService::MusicService()
+Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask &system) : m_system(system)
{
msUuid.value[11] = msId[0];
msUuid.value[12] = msId[1];
@@ -86,6 +87,8 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_
m_track = s;
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *)&msAlbumCharUuid) == 0) {
m_album = s;
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *)&msStatusCharUuid) == 0) {
+ m_status = s[0];
}
}
return 0;
@@ -106,18 +109,19 @@ std::string Pinetime::Controllers::MusicService::track()
return m_track;
}
+unsigned char Pinetime::Controllers::MusicService::status()
+{
+ return m_status;
+}
+
void Pinetime::Controllers::MusicService::event(char event)
{
- struct os_mbuf *om;
+ auto *om = ble_hs_mbuf_from_flat(&event, 1);
int ret;
- uint16_t connectionHandle = 0;
-
- om = ble_hs_mbuf_from_flat(&event, 1);
-
- ret = ble_gatts_find_svc((ble_uuid_t *) &msUuid, &connectionHandle);
+ uint16_t connectionHandle = m_system.nimble().connHandle();
- if (connectionHandle == 0) {
+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return;
}
diff --git a/src/Components/Ble/MusicService.h b/src/Components/Ble/MusicService.h
index ba872358..ab6db572 100644
--- a/src/Components/Ble/MusicService.h
+++ b/src/Components/Ble/MusicService.h
@@ -1,4 +1,5 @@
#pragma once
+
#include <cstdint>
#include <array>
#include <host/ble_gap.h>
@@ -9,10 +10,14 @@
#define MUSIC_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0xe5, 0xc7}
namespace Pinetime {
+ namespace System {
+ class SystemTask;
+ }
namespace Controllers {
+
class MusicService {
public:
- MusicService();
+ MusicService(Pinetime::System::SystemTask &system);
void Init();
int OnCommand(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt);
@@ -20,6 +25,8 @@ namespace Pinetime {
std::string artist();
std::string track();
std::string album();
+ unsigned char status();
+
void event(char event);
static const char EVENT_MUSIC_OPEN = 0xe0;
@@ -29,7 +36,8 @@ namespace Pinetime {
static const char EVENT_MUSIC_PREV = 0x04;
static const char EVENT_MUSIC_VOLUP = 0x05;
static const char EVENT_MUSIC_VOLDOWN = 0x06;
-
+ static const char STATUS_MUSIC_PAUSED = 0x00;
+ static const char STATUS_MUSIC_PLAYING = 0x01;
private:
static constexpr uint8_t msId[2] = {0x00, 0x01};
@@ -67,13 +75,17 @@ namespace Pinetime {
struct ble_gatt_chr_def characteristicDefinition[6];
struct ble_gatt_svc_def serviceDefinition[2];
-
+
uint16_t m_eventHandle;
std::string m_artist;
std::string m_album;
std::string m_track;
+ unsigned char m_status;
+
+ Pinetime::System::SystemTask& m_system;
+
};
}
}
diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp
index 53458676..d7bbd8be 100644
--- a/src/Components/Ble/NimbleController.cpp
+++ b/src/Components/Ble/NimbleController.cpp
@@ -6,6 +6,7 @@
#include <hal/nrf_rtc.h>
#include "NimbleController.h"
+#include "MusicService.h"
#include <services/gatt/ble_svc_gatt.h>
#include <services/gap/ble_svc_gap.h>
#include <host/util/util.h>
@@ -35,7 +36,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
currentTimeClient{dateTimeController},
anService{systemTask, notificationManager},
alertNotificationClient{systemTask, notificationManager},
- currentTimeService{dateTimeController} {
+ currentTimeService{dateTimeController},
+ musicService{systemTask} {
}
@@ -327,5 +329,7 @@ void NimbleController::StartDiscovery() {
}
-
+uint16_t NimbleController::connHandle() {
+ return connectionHandle;
+}
diff --git a/src/Components/Ble/NimbleController.h b/src/Components/Ble/NimbleController.h
index fab3df2b..dff93c87 100644
--- a/src/Components/Ble/NimbleController.h
+++ b/src/Components/Ble/NimbleController.h
@@ -16,6 +16,7 @@ namespace Pinetime {
}
namespace Controllers {
class DateTime;
+
class NimbleController {
public:
@@ -39,6 +40,8 @@ namespace Pinetime {
Pinetime::Controllers::MusicService& music() {return musicService;};
+ uint16_t connHandle();
+
private:
static constexpr char* deviceName = "Pinetime-JF";
Pinetime::System::SystemTask& systemTask;
@@ -56,7 +59,7 @@ namespace Pinetime {
MusicService musicService;
uint8_t addrType; // 1 = Random, 0 = PUBLIC
- uint16_t connectionHandle;
+ uint16_t connectionHandle = 0;
ble_uuid128_t dfuServiceUuid {
.u { .type = BLE_UUID_TYPE_128},