Inverted the circular dependency of MotionService and MotionController

This commit is contained in:
Sándor Rátkai 2024-09-08 20:51:29 +02:00 committed by Hunman
parent d030982902
commit a083358b98
4 changed files with 11 additions and 8 deletions

View file

@ -62,9 +62,9 @@ void MotionService::Init() {
int MotionService::OnStepCountRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
if (attributeHandle == stepCountHandle) {
NRF_LOG_INFO("Motion-stepcount : handle = %d", stepCountHandle);
uint32_t buffer = motionController.NbSteps();
MotionController::step_t buffer = motionController.NbSteps();
int res = os_mbuf_append(context->om, &buffer, 4);
int res = os_mbuf_append(context->om, &buffer, sizeof(buffer));
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
} else if (attributeHandle == motionValuesHandle) {
int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()};
@ -75,12 +75,12 @@ int MotionService::OnStepCountRequested(uint16_t attributeHandle, ble_gatt_acces
return 0;
}
void MotionService::OnNewStepCountValue(uint32_t stepCount) {
void MotionService::OnNewStepCountValue(MotionController::step_t stepCount) {
if (!stepCountNoficationEnabled)
return;
uint32_t buffer = stepCount;
auto* om = ble_hs_mbuf_from_flat(&buffer, 4);
MotionController::step_t buffer = stepCount;
auto* om = ble_hs_mbuf_from_flat(&buffer, sizeof(buffer));
uint16_t connectionHandle = nimble.connHandle();

View file

@ -6,17 +6,18 @@
#undef max
#undef min
#include "components/motion/MotionController.h"
namespace Pinetime {
namespace Controllers {
class NimbleController;
class MotionController;
class MotionService {
public:
MotionService(NimbleController& nimble, Controllers::MotionController& motionController);
void Init();
int OnStepCountRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void OnNewStepCountValue(uint32_t stepCount);
void OnNewStepCountValue(MotionController::step_t stepCount);
void OnNewMotionValues(int16_t x, int16_t y, int16_t z);
void SubscribeNotification(uint16_t attributeHandle);

View file

@ -2,6 +2,7 @@
#include <task.h>
#include "components/ble/MotionService.h"
#include "utility/Math.h"
using namespace Pinetime::Controllers;

View file

@ -5,11 +5,12 @@
#include <FreeRTOS.h>
#include "drivers/Bma421.h"
#include "components/ble/MotionService.h"
#include "utility/CircularBuffer.h"
namespace Pinetime {
namespace Controllers {
class MotionService;
class MotionController {
public:
enum class DeviceTypes {