HeartRateService: Remove SystemTask dependency

This commit is contained in:
Riku Isokoski 2023-03-15 10:27:49 +02:00
parent 7c98f26f12
commit 829ab86f37
3 changed files with 8 additions and 11 deletions

View file

@ -1,6 +1,6 @@
#include "components/ble/HeartRateService.h" #include "components/ble/HeartRateService.h"
#include "components/heartrate/HeartRateController.h" #include "components/heartrate/HeartRateController.h"
#include "systemtask/SystemTask.h" #include "components/ble/NimbleController.h"
#include <nrf_log.h> #include <nrf_log.h>
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
@ -16,8 +16,8 @@ namespace {
} }
// TODO Refactoring - remove dependency to SystemTask // TODO Refactoring - remove dependency to SystemTask
HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Controllers::HeartRateController& heartRateController) HeartRateService::HeartRateService(NimbleController& nimble, Controllers::HeartRateController& heartRateController)
: system {system}, : nimble {nimble},
heartRateController {heartRateController}, heartRateController {heartRateController},
characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u, characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u,
.access_cb = HeartRateServiceCallback, .access_cb = HeartRateServiceCallback,
@ -63,7 +63,7 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {
uint8_t buffer[2] = {0, heartRateValue}; // [0] = flags, [1] = hr value uint8_t buffer[2] = {0, heartRateValue}; // [0] = flags, [1] = hr value
auto* om = ble_hs_mbuf_from_flat(buffer, 2); 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) { if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return; return;

View file

@ -7,16 +7,13 @@
#undef min #undef min
namespace Pinetime { namespace Pinetime {
namespace System {
class SystemTask;
}
namespace Controllers { namespace Controllers {
class HeartRateController; class HeartRateController;
class NimbleController;
class HeartRateService { class HeartRateService {
public: public:
HeartRateService(Pinetime::System::SystemTask& system, Controllers::HeartRateController& heartRateController); HeartRateService(NimbleController& nimble, Controllers::HeartRateController& heartRateController);
void Init(); void Init();
int OnHeartRateRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context); int OnHeartRateRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void OnNewHeartRateValue(uint8_t hearRateValue); void OnNewHeartRateValue(uint8_t hearRateValue);
@ -25,7 +22,7 @@ namespace Pinetime {
void UnsubscribeNotification(uint16_t attributeHandle); void UnsubscribeNotification(uint16_t attributeHandle);
private: private:
Pinetime::System::SystemTask& system; NimbleController& nimble;
Controllers::HeartRateController& heartRateController; Controllers::HeartRateController& heartRateController;
static constexpr uint16_t heartRateServiceId {0x180D}; static constexpr uint16_t heartRateServiceId {0x180D};
static constexpr uint16_t heartRateMeasurementId {0x2A37}; static constexpr uint16_t heartRateMeasurementId {0x2A37};

View file

@ -46,7 +46,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
weatherService {dateTimeController}, weatherService {dateTimeController},
batteryInformationService {batteryController}, batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager}, immediateAlertService {systemTask, notificationManager},
heartRateService {systemTask, heartRateController}, heartRateService {*this, heartRateController},
motionService {*this, motionController}, motionService {*this, motionController},
fsService {systemTask, fs}, fsService {systemTask, fs},
serviceDiscovery({&currentTimeClient, &alertNotificationClient}) { serviceDiscovery({&currentTimeClient, &alertNotificationClient}) {