summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ble/MusicService.cpp197
-rw-r--r--src/components/ble/MusicService.h93
-rw-r--r--src/components/ble/NavigationService.cpp111
-rw-r--r--src/components/ble/NavigationService.h63
-rw-r--r--src/components/ble/NimbleController.cpp6
-rw-r--r--src/components/ble/NimbleController.h11
6 files changed, 0 insertions, 481 deletions
diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp
deleted file mode 100644
index 3457ce4..0000000
--- a/src/components/ble/MusicService.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/* Copyright (C) 2020-2021 JF, Adam Pigg, Avamander
-
- 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/>.
-*/
-#include "components/ble/MusicService.h"
-#include "systemtask/SystemTask.h"
-
-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) {
- characteristicDefinition[0] = {.uuid = &msEventCharUuid.u,
- .access_cb = MusicCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_NOTIFY,
- .val_handle = &eventHandle};
- 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[4] = {.uuid = &msAlbumCharUuid.u,
- .access_cb = MusicCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[5] = {.uuid = &msPositionCharUuid.u,
- .access_cb = MusicCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[6] = {.uuid = &msTotalLengthCharUuid.u,
- .access_cb = MusicCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- 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[13] = {0};
-
- serviceDefinition[0] = {
- .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition};
- serviceDefinition[1] = {0};
-}
-
-void Pinetime::Controllers::MusicService::Init() {
- uint8_t res = 0;
- res = ble_gatts_count_cfg(serviceDefinition);
- ASSERT(res == 0);
-
- res = ble_gatts_add_svcs(serviceDefinition);
- ASSERT(res == 0);
-}
-
-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);
- char data[notifSize + 1];
- data[notifSize] = '\0';
- os_mbuf_copydata(ctxt->om, 0, notifSize, data);
- char* s = &data[0];
- if (ble_uuid_cmp(ctxt->chr->uuid, &msArtistCharUuid.u) == 0) {
- artistName = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &msTrackCharUuid.u) == 0) {
- trackName = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &msAlbumCharUuid.u) == 0) {
- albumName = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &msStatusCharUuid.u) == 0) {
- playing = s[0];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &msRepeatCharUuid.u) == 0) {
- repeat = s[0];
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &msShuffleCharUuid.u) == 0) {
- shuffle = s[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, &msTotalLengthCharUuid.u) == 0) {
- trackLength = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
- } 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, &msTrackTotalCharUuid.u) == 0) {
- tracksTotal = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
- } 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() const {
- return albumName;
-}
-
-std::string Pinetime::Controllers::MusicService::getArtist() const {
- return artistName;
-}
-
-std::string Pinetime::Controllers::MusicService::getTrack() const {
- return trackName;
-}
-
-bool Pinetime::Controllers::MusicService::isPlaying() const {
- return playing;
-}
-
-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);
-
- uint16_t connectionHandle = m_system.nimble().connHandle();
-
- if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
- return;
- }
-
- ble_gattc_notify_custom(connectionHandle, eventHandle, om);
-}
diff --git a/src/components/ble/MusicService.h b/src/components/ble/MusicService.h
deleted file mode 100644
index 1ad9a42..0000000
--- a/src/components/ble/MusicService.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* Copyright (C) 2020-2021 JF, Adam Pigg, Avamander
-
- 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/>.
-*/
-#pragma once
-
-#include <cstdint>
-#include <string>
-#define min // workaround: nimble's min/max macros conflict with libstdc++
-#define max
-#include <host/ble_gap.h>
-#include <host/ble_uuid.h>
-#undef max
-#undef min
-
-namespace Pinetime {
- namespace System {
- class SystemTask;
- }
- namespace Controllers {
- class MusicService {
- public:
- explicit MusicService(Pinetime::System::SystemTask& system);
-
- void Init();
-
- int OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt);
-
- void event(char event);
-
- std::string getArtist() const;
-
- std::string getTrack() const;
-
- std::string getAlbum() const;
-
- int getProgress() const;
-
- int getTrackLength() const;
-
- float getPlaybackSpeed() const;
-
- bool isPlaying() const;
-
- 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;
-
- enum MusicStatus { NotPlaying = 0x00, Playing = 0x01 };
-
- private:
- struct ble_gatt_chr_def characteristicDefinition[14];
- struct ble_gatt_svc_def serviceDefinition[2];
-
- uint16_t eventHandle {};
-
- std::string artistName {"Waiting for"};
- std::string albumName {};
- std::string trackName {"track information.."};
-
- bool playing {false};
-
- int trackProgress {0};
- int trackLength {0};
- int trackNumber {};
- int tracksTotal {};
-
- float playbackSpeed {1.0f};
-
- bool repeat {false};
- bool shuffle {false};
-
- Pinetime::System::SystemTask& m_system;
- };
- }
-}
diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp
deleted file mode 100644
index 5418b9e..0000000
--- a/src/components/ble/NavigationService.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Copyright (C) 2021 Adam Pigg
-
- 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/>.
-*/
-
-#include "components/ble/NavigationService.h"
-
-#include "systemtask/SystemTask.h"
-
-namespace {
- // 0001yyxx-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, 0x01, 0x00}};
- }
-
- // 00010000-78fc-48fe-8e23-433b3a1942d0
- constexpr ble_uuid128_t BaseUuid() {
- return CharUuid(0x00, 0x00);
- }
-
- constexpr ble_uuid128_t navUuid {BaseUuid()};
-
- constexpr ble_uuid128_t navFlagCharUuid {CharUuid(0x01, 0x00)};
- constexpr ble_uuid128_t navNarrativeCharUuid {CharUuid(0x02, 0x00)};
- constexpr ble_uuid128_t navManDistCharUuid {CharUuid(0x03, 0x00)};
- constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)};
-
- int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
- auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg);
- return navService->OnCommand(conn_handle, attr_handle, ctxt);
- }
-} // namespace
-
-Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) {
- characteristicDefinition[0] = {
- .uuid = &navFlagCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
-
- characteristicDefinition[1] = {
- .uuid = &navNarrativeCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[2] = {
- .uuid = &navManDistCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[3] = {
- .uuid = &navProgressCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
-
- characteristicDefinition[4] = {0};
-
- serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &navUuid.u, .characteristics = characteristicDefinition};
- serviceDefinition[1] = {0};
-
- m_progress = 0;
-}
-
-void Pinetime::Controllers::NavigationService::Init() {
- int res = 0;
- res = ble_gatts_count_cfg(serviceDefinition);
- ASSERT(res == 0);
-
- res = ble_gatts_add_svcs(serviceDefinition);
- ASSERT(res == 0);
-}
-
-int Pinetime::Controllers::NavigationService::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];
- data[notifSize] = '\0';
- os_mbuf_copydata(ctxt->om, 0, notifSize, data);
- char* s = (char*) &data[0];
- if (ble_uuid_cmp(ctxt->chr->uuid, &navFlagCharUuid.u) == 0) {
- m_flag = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &navNarrativeCharUuid.u) == 0) {
- m_narrative = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &navManDistCharUuid.u) == 0) {
- m_manDist = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, &navProgressCharUuid.u) == 0) {
- m_progress = data[0];
- }
- }
- return 0;
-}
-
-std::string Pinetime::Controllers::NavigationService::getFlag() {
- return m_flag;
-}
-
-std::string Pinetime::Controllers::NavigationService::getNarrative() {
- return m_narrative;
-}
-
-std::string Pinetime::Controllers::NavigationService::getManDist() {
- return m_manDist;
-}
-
-int Pinetime::Controllers::NavigationService::getProgress() {
- return m_progress;
-}
diff --git a/src/components/ble/NavigationService.h b/src/components/ble/NavigationService.h
deleted file mode 100644
index c0c77f3..0000000
--- a/src/components/ble/NavigationService.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Copyright (C) 2021 Adam Pigg
-
- 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/>.
-*/
-#pragma once
-
-#include <cstdint>
-#include <string>
-#define min // workaround: nimble's min/max macros conflict with libstdc++
-#define max
-#include <host/ble_gap.h>
-#include <host/ble_uuid.h>
-#undef max
-#undef min
-
-namespace Pinetime {
- namespace System {
- class SystemTask;
- }
- namespace Controllers {
-
- class NavigationService {
- public:
- explicit NavigationService(Pinetime::System::SystemTask& system);
-
- void Init();
-
- int OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt);
-
- std::string getFlag();
-
- std::string getNarrative();
-
- std::string getManDist();
-
- int getProgress();
-
- private:
- struct ble_gatt_chr_def characteristicDefinition[5];
- struct ble_gatt_svc_def serviceDefinition[2];
-
- std::string m_flag;
- std::string m_narrative;
- std::string m_manDist;
- int m_progress;
-
- Pinetime::System::SystemTask& m_system;
- };
- }
-}
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp
index 0be7c0f..f490144 100644
--- a/src/components/ble/NimbleController.cpp
+++ b/src/components/ble/NimbleController.cpp
@@ -44,9 +44,6 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
anService {systemTask, notificationManager},
alertNotificationClient {systemTask, notificationManager},
currentTimeService {dateTimeController},
- musicService {systemTask},
- weatherService {systemTask, dateTimeController},
- navService {systemTask},
batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager},
heartRateService {systemTask, heartRateController},
@@ -90,9 +87,6 @@ void NimbleController::Init() {
deviceInformationService.Init();
currentTimeClient.Init();
currentTimeService.Init();
- musicService.Init();
- weatherService.Init();
- navService.Init();
anService.Init();
dfuService.Init();
batteryInformationService.Init();
diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h
index ad19421..87d44aa 100644
--- a/src/components/ble/NimbleController.h
+++ b/src/components/ble/NimbleController.h
@@ -17,8 +17,6 @@
#include "components/ble/FSService.h"
#include "components/ble/HeartRateService.h"
#include "components/ble/ImmediateAlertService.h"
-#include "components/ble/MusicService.h"
-#include "components/ble/NavigationService.h"
#include "components/ble/ServiceDiscovery.h"
#include "components/ble/MotionService.h"
#include "components/ble/weather/WeatherService.h"
@@ -55,12 +53,6 @@ namespace Pinetime {
int OnGAPEvent(ble_gap_event* event);
void StartDiscovery();
- Pinetime::Controllers::MusicService& music() {
- return musicService;
- };
- Pinetime::Controllers::NavigationService& navigation() {
- return navService;
- };
Pinetime::Controllers::AlertNotificationService& alertService() {
return anService;
};
@@ -96,9 +88,6 @@ namespace Pinetime {
AlertNotificationService anService;
AlertNotificationClient alertNotificationClient;
CurrentTimeService currentTimeService;
- MusicService musicService;
- WeatherService weatherService;
- NavigationService navService;
BatteryInformationService batteryInformationService;
ImmediateAlertService immediateAlertService;
HeartRateService heartRateService;