From 829ab86f37fffbed8575aad2be6707198a58ab19 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 15 Mar 2023 10:27:49 +0200 Subject: [PATCH] HeartRateService: Remove SystemTask dependency --- src/components/ble/HeartRateService.cpp | 8 ++++---- src/components/ble/HeartRateService.h | 9 +++------ src/components/ble/NimbleController.cpp | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp index c522e67e..d34dbf83 100644 --- a/src/components/ble/HeartRateService.cpp +++ b/src/components/ble/HeartRateService.cpp @@ -1,6 +1,6 @@ #include "components/ble/HeartRateService.h" #include "components/heartrate/HeartRateController.h" -#include "systemtask/SystemTask.h" +#include "components/ble/NimbleController.h" #include using namespace Pinetime::Controllers; @@ -16,8 +16,8 @@ namespace { } // TODO Refactoring - remove dependency to SystemTask -HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Controllers::HeartRateController& heartRateController) - : system {system}, +HeartRateService::HeartRateService(NimbleController& nimble, Controllers::HeartRateController& heartRateController) + : nimble {nimble}, heartRateController {heartRateController}, characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u, .access_cb = HeartRateServiceCallback, @@ -63,7 +63,7 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { uint8_t buffer[2] = {0, heartRateValue}; // [0] = flags, [1] = hr value auto* om = ble_hs_mbuf_from_flat(buffer, 2); - uint16_t connectionHandle = system.nimble().connHandle(); + uint16_t connectionHandle = nimble.connHandle(); if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { return; diff --git a/src/components/ble/HeartRateService.h b/src/components/ble/HeartRateService.h index 003bdbd1..72632c96 100644 --- a/src/components/ble/HeartRateService.h +++ b/src/components/ble/HeartRateService.h @@ -7,16 +7,13 @@ #undef min namespace Pinetime { - namespace System { - class SystemTask; - } - namespace Controllers { class HeartRateController; + class NimbleController; class HeartRateService { public: - HeartRateService(Pinetime::System::SystemTask& system, Controllers::HeartRateController& heartRateController); + HeartRateService(NimbleController& nimble, Controllers::HeartRateController& heartRateController); void Init(); int OnHeartRateRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context); void OnNewHeartRateValue(uint8_t hearRateValue); @@ -25,7 +22,7 @@ namespace Pinetime { void UnsubscribeNotification(uint16_t attributeHandle); private: - Pinetime::System::SystemTask& system; + NimbleController& nimble; Controllers::HeartRateController& heartRateController; static constexpr uint16_t heartRateServiceId {0x180D}; static constexpr uint16_t heartRateMeasurementId {0x2A37}; diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index c541cbaa..2e7f8003 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -46,7 +46,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, weatherService {dateTimeController}, batteryInformationService {batteryController}, immediateAlertService {systemTask, notificationManager}, - heartRateService {systemTask, heartRateController}, + heartRateService {*this, heartRateController}, motionService {*this, motionController}, fsService {systemTask, fs}, serviceDiscovery({¤tTimeClient, &alertNotificationClient}) {