MotionService: Remove SystemTask dependency

This commit is contained in:
Riku Isokoski 2023-03-15 10:26:12 +02:00
parent ca5e7d1adf
commit 7c98f26f12
3 changed files with 9 additions and 12 deletions

View file

@ -1,6 +1,6 @@
#include "components/ble/MotionService.h" #include "components/ble/MotionService.h"
#include "components/motion/MotionController.h" #include "components/motion/MotionController.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;
@ -28,8 +28,8 @@ namespace {
} }
// TODO Refactoring - remove dependency to SystemTask // TODO Refactoring - remove dependency to SystemTask
MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController) MotionService::MotionService(NimbleController& nimble, Controllers::MotionController& motionController)
: system {system}, : nimble {nimble},
motionController {motionController}, motionController {motionController},
characteristicDefinition {{.uuid = &stepCountCharUuid.u, characteristicDefinition {{.uuid = &stepCountCharUuid.u,
.access_cb = MotionServiceCallback, .access_cb = MotionServiceCallback,
@ -82,7 +82,7 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
uint32_t buffer = stepCount; uint32_t buffer = stepCount;
auto* om = ble_hs_mbuf_from_flat(&buffer, 4); auto* om = ble_hs_mbuf_from_flat(&buffer, 4);
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;
@ -98,7 +98,7 @@ void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
int16_t buffer[3] = {x, y, z}; int16_t buffer[3] = {x, y, z};
auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t)); auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t));
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 NimbleController;
class MotionController; class MotionController;
class MotionService { class MotionService {
public: public:
MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController); MotionService(NimbleController& nimble, Controllers::MotionController& motionController);
void Init(); void Init();
int OnStepCountRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context); int OnStepCountRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void OnNewStepCountValue(uint32_t stepCount); void OnNewStepCountValue(uint32_t stepCount);
@ -26,7 +23,7 @@ namespace Pinetime {
void UnsubscribeNotification(uint16_t attributeHandle); void UnsubscribeNotification(uint16_t attributeHandle);
private: private:
Pinetime::System::SystemTask& system; NimbleController& nimble;
Controllers::MotionController& motionController; Controllers::MotionController& motionController;
struct ble_gatt_chr_def characteristicDefinition[3]; struct ble_gatt_chr_def characteristicDefinition[3];

View file

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