summaryrefslogtreecommitdiff
path: root/src/components/ble
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ble')
-rw-r--r--src/components/ble/AlertNotificationClient.cpp2
-rw-r--r--src/components/ble/AlertNotificationService.cpp2
-rw-r--r--src/components/ble/BatteryInformationService.cpp8
-rw-r--r--src/components/ble/BatteryInformationService.h2
-rw-r--r--src/components/ble/DfuService.cpp18
-rw-r--r--src/components/ble/ImmediateAlertService.cpp2
-rw-r--r--src/components/ble/MusicService.cpp234
-rw-r--r--src/components/ble/MusicService.h74
-rw-r--r--src/components/ble/NimbleController.cpp8
-rw-r--r--src/components/ble/NimbleController.h3
10 files changed, 152 insertions, 201 deletions
diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp
index 6043a129..c3d1d69a 100644
--- a/src/components/ble/AlertNotificationClient.cpp
+++ b/src/components/ble/AlertNotificationClient.cpp
@@ -159,7 +159,7 @@ void AlertNotificationClient::OnNotification(ble_gap_event* event) {
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
notificationManager.Push(std::move(notif));
- systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
+ systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
}
}
diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp
index e9f5941e..d5fc7f65 100644
--- a/src/components/ble/AlertNotificationService.cpp
+++ b/src/components/ble/AlertNotificationService.cpp
@@ -79,7 +79,7 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
break;
}
- auto event = Pinetime::System::SystemTask::Messages::OnNewNotification;
+ auto event = Pinetime::System::Messages::OnNewNotification;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(event);
}
diff --git a/src/components/ble/BatteryInformationService.cpp b/src/components/ble/BatteryInformationService.cpp
index 10a78d67..7f176904 100644
--- a/src/components/ble/BatteryInformationService.cpp
+++ b/src/components/ble/BatteryInformationService.cpp
@@ -17,7 +17,7 @@ BatteryInformationService::BatteryInformationService(Controllers::Battery& batte
characteristicDefinition {{.uuid = (ble_uuid_t*) &batteryLevelUuid,
.access_cb = BatteryInformationServiceCallback,
.arg = this,
- .flags = BLE_GATT_CHR_F_READ,
+ .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
.val_handle = &batteryLevelHandle},
{0}},
serviceDefinition {
@@ -48,4 +48,8 @@ int BatteryInformationService::OnBatteryServiceRequested(uint16_t connectionHand
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
return 0;
-} \ No newline at end of file
+}
+void BatteryInformationService::NotifyBatteryLevel(uint16_t connectionHandle, uint8_t level) {
+ auto* om = ble_hs_mbuf_from_flat(&level, 1);
+ ble_gattc_notify_custom(connectionHandle, batteryLevelHandle, om);
+}
diff --git a/src/components/ble/BatteryInformationService.h b/src/components/ble/BatteryInformationService.h
index 7d060909..1303fd6c 100644
--- a/src/components/ble/BatteryInformationService.h
+++ b/src/components/ble/BatteryInformationService.h
@@ -17,7 +17,7 @@ namespace Pinetime {
void Init();
int OnBatteryServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
-
+ void NotifyBatteryLevel(uint16_t connectionHandle, uint8_t level);
private:
Controllers::Battery& batteryController;
static constexpr uint16_t batteryInformationServiceId {0x180F};
diff --git a/src/components/ble/DfuService.cpp b/src/components/ble/DfuService.cpp
index 2031668e..4179994d 100644
--- a/src/components/ble/DfuService.cpp
+++ b/src/components/ble/DfuService.cpp
@@ -121,6 +121,11 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) {
NRF_LOG_INFO(
"[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", softdeviceSize, bootloaderSize, applicationSize);
+ // wait until SystemTask has finished waking up all devices
+ while (systemTask.IsSleeping()) {
+ vTaskDelay(50); // 50ms
+ }
+
dfuImage.Erase();
uint8_t data[] {16, 1, 1};
@@ -205,7 +210,7 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf* om) {
bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Running);
bleController.FirmwareUpdateTotalBytes(0xffffffffu);
bleController.FirmwareUpdateCurrentBytes(0);
- systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateStarted);
+ systemTask.PushMessage(Pinetime::System::Messages::BleFirmwareUpdateStarted);
return 0;
} else {
NRF_LOG_INFO("[DFU] -> Start DFU, mode %d not supported!", imageType);
@@ -261,13 +266,14 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf* om) {
static_cast<uint8_t>(ErrorCodes::NoError)};
notificationManager.AsyncSend(connectionHandle, controlPointCharacteristicHandle, data, 3);
} else {
- bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Error);
NRF_LOG_INFO("Image Error : bad CRC");
uint8_t data[3] {static_cast<uint8_t>(Opcodes::Response),
static_cast<uint8_t>(Opcodes::ValidateFirmware),
static_cast<uint8_t>(ErrorCodes::CrcError)};
notificationManager.AsyncSend(connectionHandle, controlPointCharacteristicHandle, data, 3);
+ bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Error);
+ Reset();
}
return 0;
@@ -278,10 +284,8 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf* om) {
return 0;
}
NRF_LOG_INFO("[DFU] -> Activate image and reset!");
- bleController.StopFirmwareUpdate();
- systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateFinished);
- Reset();
bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated);
+ Reset();
return 0;
default:
return 0;
@@ -289,6 +293,7 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf* om) {
}
void DfuService::OnTimeout() {
+ bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Error);
Reset();
}
@@ -302,9 +307,8 @@ void DfuService::Reset() {
applicationSize = 0;
expectedCrc = 0;
notificationManager.Reset();
- bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Error);
bleController.StopFirmwareUpdate();
- systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateFinished);
+ systemTask.PushMessage(Pinetime::System::Messages::BleFirmwareUpdateFinished);
}
DfuService::NotificationManager::NotificationManager() {
diff --git a/src/components/ble/ImmediateAlertService.cpp b/src/components/ble/ImmediateAlertService.cpp
index fd6430af..820d3b6e 100644
--- a/src/components/ble/ImmediateAlertService.cpp
+++ b/src/components/ble/ImmediateAlertService.cpp
@@ -67,7 +67,7 @@ int ImmediateAlertService::OnAlertLevelChanged(uint16_t connectionHandle, uint16
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
notificationManager.Push(std::move(notif));
- systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
+ systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
}
}
diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp
index 36bf2709..74fe9522 100644
--- a/src/components/ble/MusicService.cpp
+++ b/src/components/ble/MusicService.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2020 JF, Adam Pigg, Avamander
+/* Copyright (C) 2020-2021 JF, Adam Pigg, Avamander
This file is part of InfiniTime.
@@ -18,132 +18,103 @@
#include "MusicService.h"
#include "systemtask/SystemTask.h"
-int MSCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
- auto musicService = static_cast<Pinetime::Controllers::MusicService*>(arg);
- return musicService->OnCommand(conn_handle, attr_handle, ctxt);
+namespace {
+ // 0000yyxx-78fc-48fe-8e23-433b3a1942d0
+ constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
+ return ble_uuid128_t{
+ .u = {.type = BLE_UUID_TYPE_128},
+ .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x00, 0x00 }
+ };
+ }
+
+ // 00000000-78fc-48fe-8e23-433b3a1942d0
+ constexpr ble_uuid128_t BaseUuid() {
+ return CharUuid(0x00, 0x00);
+ }
+
+ constexpr ble_uuid128_t msUuid {BaseUuid()};
+
+ constexpr ble_uuid128_t msEventCharUuid {CharUuid(0x01, 0x00)};
+ constexpr ble_uuid128_t msStatusCharUuid {CharUuid(0x02, 0x00)};
+ constexpr ble_uuid128_t msArtistCharUuid {CharUuid(0x03, 0x00)};
+ constexpr ble_uuid128_t msTrackCharUuid {CharUuid(0x04, 0x00)};
+ constexpr ble_uuid128_t msAlbumCharUuid {CharUuid(0x05, 0x00)};
+ constexpr ble_uuid128_t msPositionCharUuid {CharUuid(0x06, 0x00)};
+ constexpr ble_uuid128_t msTotalLengthCharUuid {CharUuid(0x07, 0x00)};
+ constexpr ble_uuid128_t msTrackNumberCharUuid {CharUuid(0x08, 0x00)};
+ constexpr ble_uuid128_t msTrackTotalCharUuid {CharUuid(0x09, 0x00)};
+ constexpr ble_uuid128_t msPlaybackSpeedCharUuid {CharUuid(0x0a, 0x00)};
+ constexpr ble_uuid128_t msRepeatCharUuid {CharUuid(0x0b, 0x00)};
+ constexpr ble_uuid128_t msShuffleCharUuid {CharUuid(0x0c, 0x00)};
+
+ int MusicCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
+ return static_cast<Pinetime::Controllers::MusicService*>(arg)->OnCommand(conn_handle, attr_handle, ctxt);
+ }
}
Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask& system) : m_system(system) {
- msUuid.value[14] = msId[0];
- msUuid.value[15] = msId[1];
-
- msEventCharUuid.value[12] = msEventCharId[0];
- msEventCharUuid.value[13] = msEventCharId[1];
- msEventCharUuid.value[14] = msId[0];
- msEventCharUuid.value[15] = msId[1];
-
- msStatusCharUuid.value[12] = msStatusCharId[0];
- msStatusCharUuid.value[13] = msStatusCharId[1];
- msStatusCharUuid.value[14] = msId[0];
- msStatusCharUuid.value[15] = msId[1];
-
- msTrackCharUuid.value[12] = msTrackCharId[0];
- msTrackCharUuid.value[13] = msTrackCharId[1];
- msTrackCharUuid.value[14] = msId[0];
- msTrackCharUuid.value[15] = msId[1];
-
- msArtistCharUuid.value[12] = msArtistCharId[0];
- msArtistCharUuid.value[13] = msArtistCharId[1];
- msArtistCharUuid.value[14] = msId[0];
- msArtistCharUuid.value[15] = msId[1];
-
- msAlbumCharUuid.value[12] = msAlbumCharId[0];
- msAlbumCharUuid.value[13] = msAlbumCharId[1];
- msAlbumCharUuid.value[14] = msId[0];
- msAlbumCharUuid.value[15] = msId[1];
-
- msPositionCharUuid.value[12] = msPositionCharId[0];
- msPositionCharUuid.value[13] = msPositionCharId[1];
- msPositionCharUuid.value[14] = msId[0];
- msPositionCharUuid.value[15] = msId[1];
-
- msTotalLengthCharUuid.value[12] = msTotalLengthCharId[0];
- msTotalLengthCharUuid.value[13] = msTotalLengthCharId[1];
- msTotalLengthCharUuid.value[14] = msId[0];
- msTotalLengthCharUuid.value[15] = msId[1];
-
- msTrackNumberCharUuid.value[12] = msTrackNumberCharId[0];
- msTrackNumberCharUuid.value[13] = msTrackNumberCharId[1];
- msTrackNumberCharUuid.value[14] = msId[0];
- msTrackNumberCharUuid.value[15] = msId[1];
-
- msTrackTotalCharUuid.value[12] = msTrackTotalCharId[0];
- msTrackTotalCharUuid.value[13] = msTrackTotalCharId[1];
- msTrackTotalCharUuid.value[14] = msId[0];
- msTrackTotalCharUuid.value[15] = msId[1];
-
- msPlaybackSpeedCharUuid.value[12] = msPlaybackSpeedCharId[0];
- msPlaybackSpeedCharUuid.value[13] = msPlaybackSpeedCharId[1];
- msPlaybackSpeedCharUuid.value[14] = msId[0];
- msPlaybackSpeedCharUuid.value[15] = msId[1];
-
- msRepeatCharUuid.value[12] = msRepeatCharId[0];
- msRepeatCharUuid.value[13] = msRepeatCharId[1];
- msRepeatCharUuid.value[14] = msId[0];
- msRepeatCharUuid.value[15] = msId[1];
-
- msShuffleCharUuid.value[12] = msShuffleCharId[0];
- msShuffleCharUuid.value[13] = msShuffleCharId[1];
- msShuffleCharUuid.value[14] = msId[0];
- msShuffleCharUuid.value[15] = msId[1];
-
- characteristicDefinition[0] = {.uuid = (ble_uuid_t*) (&msEventCharUuid),
- .access_cb = MSCallback,
+ characteristicDefinition[0] = {.uuid = &msEventCharUuid.u,
+ .access_cb = MusicCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_NOTIFY,
.val_handle = &eventHandle};
- characteristicDefinition[1] = {
- .uuid = (ble_uuid_t*) (&msStatusCharUuid), .access_cb = MSCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[2] = {
- .uuid = (ble_uuid_t*) (&msTrackCharUuid), .access_cb = MSCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[3] = {
- .uuid = (ble_uuid_t*) (&msArtistCharUuid), .access_cb = MSCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[4] = {
- .uuid = (ble_uuid_t*) (&msAlbumCharUuid), .access_cb = MSCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[5] = {
- .uuid = (ble_uuid_t*) (&msPositionCharUuid), .access_cb = MSCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[6] = {.uuid = (ble_uuid_t*) (&msTotalLengthCharUuid),
- .access_cb = MSCallback,
+ characteristicDefinition[1] = {.uuid = &msStatusCharUuid.u,
+ .access_cb = MusicCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[2] = {.uuid = &msTrackCharUuid.u,
+ .access_cb = MusicCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[3] = {.uuid = &msArtistCharUuid.u,
+ .access_cb = MusicCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[7] = {.uuid = (ble_uuid_t*) (&msTotalLengthCharUuid),
- .access_cb = MSCallback,
+ characteristicDefinition[4] = {.uuid = &msAlbumCharUuid.u,
+ .access_cb = MusicCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[8] = {.uuid = (ble_uuid_t*) (&msTrackNumberCharUuid),
- .access_cb = MSCallback,
+ characteristicDefinition[5] = {.uuid = &msPositionCharUuid.u,
+ .access_cb = MusicCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[9] = {.uuid = (ble_uuid_t*) (&msTrackTotalCharUuid),
- .access_cb = MSCallback,
+ characteristicDefinition[6] = {.uuid = &msTotalLengthCharUuid.u,
+ .access_cb = MusicCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[10] = {.uuid = (ble_uuid_t*) (&msPlaybackSpeedCharUuid),
- .access_cb = MSCallback,
+ characteristicDefinition[7] = {.uuid = &msTotalLengthCharUuid.u,
+ .access_cb = MusicCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[8] = {.uuid = &msTrackNumberCharUuid.u,
+ .access_cb = MusicCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[9] = {.uuid = &msTrackTotalCharUuid.u,
+ .access_cb = MusicCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[10] = {.uuid = &msPlaybackSpeedCharUuid.u,
+ .access_cb = MusicCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[11] = {.uuid = &msRepeatCharUuid.u,
+ .access_cb = MusicCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[12] = {.uuid = &msShuffleCharUuid.u,
+ .access_cb = MusicCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[11] = {
- .uuid = (ble_uuid_t*) (&msRepeatCharUuid), .access_cb = MSCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[12] = {
- .uuid = (ble_uuid_t*) (&msShuffleCharUuid), .access_cb = MSCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
characteristicDefinition[13] = {0};
- serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = (ble_uuid_t*) &msUuid, .characteristics = characteristicDefinition};
+ serviceDefinition[0] = {
+ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition};
serviceDefinition[1] = {0};
-
- artistName = "Waiting for";
- albumName = "";
- trackName = "track information..";
- playing = false;
- repeat = false;
- shuffle = false;
- playbackSpeed = 1.0f;
- trackProgress = 0;
- trackLength = 0;
}
void Pinetime::Controllers::MusicService::Init() {
- int res = 0;
+ uint8_t res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
@@ -152,60 +123,67 @@ void Pinetime::Controllers::MusicService::Init() {
}
int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {
-
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
- uint8_t data[notifSize + 1];
+ char data[notifSize + 1];
data[notifSize] = '\0';
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
- char* s = (char*) &data[0];
- if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msArtistCharUuid) == 0) {
+ char* s = &data[0];
+ if (ble_uuid_cmp(ctxt->chr->uuid, &msArtistCharUuid.u) == 0) {
artistName = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msTrackCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msTrackCharUuid.u) == 0) {
trackName = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msAlbumCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msAlbumCharUuid.u) == 0) {
albumName = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msStatusCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msStatusCharUuid.u) == 0) {
playing = s[0];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msRepeatCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msRepeatCharUuid.u) == 0) {
repeat = s[0];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msShuffleCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msShuffleCharUuid.u) == 0) {
shuffle = s[0];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msPositionCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msPositionCharUuid.u) == 0) {
trackProgress = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msTotalLengthCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msTotalLengthCharUuid.u) == 0) {
trackLength = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msTrackNumberCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msTrackNumberCharUuid.u) == 0) {
trackNumber = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msTrackTotalCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msTrackTotalCharUuid.u) == 0) {
tracksTotal = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &msPlaybackSpeedCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &msPlaybackSpeedCharUuid.u) == 0) {
playbackSpeed = static_cast<float>(((s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3])) / 100.0f;
}
}
return 0;
}
-std::string Pinetime::Controllers::MusicService::getAlbum() {
+std::string Pinetime::Controllers::MusicService::getAlbum() const {
return albumName;
}
-std::string Pinetime::Controllers::MusicService::getArtist() {
+std::string Pinetime::Controllers::MusicService::getArtist() const {
return artistName;
}
-std::string Pinetime::Controllers::MusicService::getTrack() {
+std::string Pinetime::Controllers::MusicService::getTrack() const {
return trackName;
}
-bool Pinetime::Controllers::MusicService::isPlaying() {
+bool Pinetime::Controllers::MusicService::isPlaying() const {
return playing;
}
-float Pinetime::Controllers::MusicService::getPlaybackSpeed() {
+float Pinetime::Controllers::MusicService::getPlaybackSpeed() const {
return playbackSpeed;
}
+int Pinetime::Controllers::MusicService::getProgress() const {
+ return trackProgress;
+}
+
+int Pinetime::Controllers::MusicService::getTrackLength() const {
+ return trackLength;
+}
+
void Pinetime::Controllers::MusicService::event(char event) {
auto* om = ble_hs_mbuf_from_flat(&event, 1);
@@ -217,11 +195,3 @@ void Pinetime::Controllers::MusicService::event(char event) {
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
}
-
-int Pinetime::Controllers::MusicService::getProgress() {
- return trackProgress;
-}
-
-int Pinetime::Controllers::MusicService::getTrackLength() {
- return trackLength;
-}
diff --git a/src/components/ble/MusicService.h b/src/components/ble/MusicService.h
index 5f5343e4..1ad9a420 100644
--- a/src/components/ble/MusicService.h
+++ b/src/components/ble/MusicService.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2020 JF, Adam Pigg, Avamander
+/* Copyright (C) 2020-2021 JF, Adam Pigg, Avamander
This file is part of InfiniTime.
@@ -26,16 +26,11 @@
#undef max
#undef min
-// 00000000-78fc-48fe-8e23-433b3a1942d0
-#define MUSIC_SERVICE_UUID_BASE \
- { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x00, 0x00 }
-
namespace Pinetime {
namespace System {
class SystemTask;
}
namespace Controllers {
-
class MusicService {
public:
explicit MusicService(Pinetime::System::SystemTask& system);
@@ -46,19 +41,19 @@ namespace Pinetime {
void event(char event);
- std::string getArtist();
+ std::string getArtist() const;
- std::string getTrack();
+ std::string getTrack() const;
- std::string getAlbum();
+ std::string getAlbum() const;
- int getProgress();
+ int getProgress() const;
- int getTrackLength();
+ int getTrackLength() const;
- float getPlaybackSpeed();
+ float getPlaybackSpeed() const;
- bool isPlaying();
+ bool isPlaying() const;
static const char EVENT_MUSIC_OPEN = 0xe0;
static const char EVENT_MUSIC_PLAY = 0x00;
@@ -71,55 +66,26 @@ namespace Pinetime {
enum MusicStatus { NotPlaying = 0x00, Playing = 0x01 };
private:
- static constexpr uint8_t msId[2] = {0x00, 0x00};
- static constexpr uint8_t msEventCharId[2] = {0x01, 0x00};
- static constexpr uint8_t msStatusCharId[2] = {0x02, 0x00};
- static constexpr uint8_t msArtistCharId[2] = {0x03, 0x00};
- static constexpr uint8_t msTrackCharId[2] = {0x04, 0x00};
- static constexpr uint8_t msAlbumCharId[2] = {0x05, 0x00};
- static constexpr uint8_t msPositionCharId[2] = {0x06, 0x00};
- static constexpr uint8_t msTotalLengthCharId[2] = {0x07, 0x00};
- static constexpr uint8_t msTrackNumberCharId[2] = {0x08, 0x00};
- static constexpr uint8_t msTrackTotalCharId[2] = {0x09, 0x00};
- static constexpr uint8_t msPlaybackSpeedCharId[2] = {0x0a, 0x00};
- static constexpr uint8_t msRepeatCharId[2] = {0x0b, 0x00};
- static constexpr uint8_t msShuffleCharId[2] = {0x0c, 0x00};
-
- ble_uuid128_t msUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
-
- ble_uuid128_t msEventCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msStatusCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msArtistCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msTrackCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msAlbumCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msPositionCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msTotalLengthCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msTrackNumberCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msTrackTotalCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msPlaybackSpeedCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msRepeatCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
- ble_uuid128_t msShuffleCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = MUSIC_SERVICE_UUID_BASE};
-
struct ble_gatt_chr_def characteristicDefinition[14];
struct ble_gatt_svc_def serviceDefinition[2];
- uint16_t eventHandle;
+ uint16_t eventHandle {};
- std::string artistName;
- std::string albumName;
- std::string trackName;
+ std::string artistName {"Waiting for"};
+ std::string albumName {};
+ std::string trackName {"track information.."};
- bool playing;
+ bool playing {false};
- int trackProgress;
- int trackLength;
- int trackNumber;
- int tracksTotal;
+ int trackProgress {0};
+ int trackLength {0};
+ int trackNumber {};
+ int tracksTotal {};
- float playbackSpeed;
+ float playbackSpeed {1.0f};
- bool repeat;
- bool shuffle;
+ bool repeat {false};
+ bool shuffle {false};
Pinetime::System::SystemTask& m_system;
};
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp
index 67a6d691..5eb227bf 100644
--- a/src/components/ble/NimbleController.cpp
+++ b/src/components/ble/NimbleController.cpp
@@ -149,7 +149,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
bleController.Disconnect();
} else {
bleController.Connect();
- systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleConnected);
+ systemTask.PushMessage(Pinetime::System::Messages::BleConnected);
connectionHandle = event->connect.conn_handle;
// Service discovery is deffered via systemtask
}
@@ -235,3 +235,9 @@ void NimbleController::StartDiscovery() {
uint16_t NimbleController::connHandle() {
return connectionHandle;
}
+
+void NimbleController::NotifyBatteryLevel(uint8_t level) {
+ if(connectionHandle != BLE_HS_CONN_HANDLE_NONE) {
+ batteryInformationService.NotifyBatteryLevel(connectionHandle, level);
+ }
+}
diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h
index 5dd01e42..0cfe983c 100644
--- a/src/components/ble/NimbleController.h
+++ b/src/components/ble/NimbleController.h
@@ -70,6 +70,7 @@ namespace Pinetime {
};
uint16_t connHandle();
+ void NotifyBatteryLevel(uint8_t level);
private:
static constexpr const char* deviceName = "InfiniTime";
@@ -92,7 +93,7 @@ namespace Pinetime {
HeartRateService heartRateService;
uint8_t addrType; // 1 = Random, 0 = PUBLIC
- uint16_t connectionHandle = 0;
+ uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE;
ble_uuid128_t dfuServiceUuid {
.u {.type = BLE_UUID_TYPE_128},