Skip to content

Commit c4fc866

Browse files
committed
Motion: Expose acceleration FIFO via BLE
The motion BLE service now broadcasts the entire FIFO buffer, in order to expose a higher frequency measurement. A high enough MTU has to be negotiated to fit all max. 192 bytes. The format is backwards-compatible.
1 parent b83f678 commit c4fc866

File tree

5 files changed

+19
-29
lines changed

5 files changed

+19
-29
lines changed

src/components/ble/MotionService.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,20 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
9595

9696
ble_gattc_notify_custom(connectionHandle, stepCountHandle, om);
9797
}
98-
void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
98+
void MotionService::OnNewMotionValues(int16_t* samples, uint16_t samples_length) {
9999
if(!motionValuesNoficationEnabled) return;
100100

101-
int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() };
102-
auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t));
101+
if(samples_length > 0 && samples != nullptr) {
102+
auto* om = ble_hs_mbuf_from_flat(samples, samples_length * 3 * sizeof(int16_t));
103103

104-
uint16_t connectionHandle = system.nimble().connHandle();
104+
uint16_t connectionHandle = system.nimble().connHandle();
105105

106-
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
107-
return;
108-
}
106+
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
107+
return;
108+
}
109109

110-
ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
110+
ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
111+
}
111112
}
112113

113114
void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {

src/components/ble/MotionService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Pinetime {
1818
void Init();
1919
int OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
2020
void OnNewStepCountValue(uint32_t stepCount);
21-
void OnNewMotionValues(int16_t x, int16_t y, int16_t z);
21+
void OnNewMotionValues(int16_t* samples, uint16_t samples_length);
2222

2323
void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
2424
void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);

src/components/motion/MotionController.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#include "os/os_cputime.h"
33
using namespace Pinetime::Controllers;
44

5-
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
5+
void MotionController::Update(uint32_t nbSteps, int16_t x, int16_t y, int16_t z,
6+
int16_t* samples, uint16_t samples_length) {
67
if (this->nbSteps != nbSteps && service != nullptr) {
78
service->OnNewStepCountValue(nbSteps);
89
}
910

1011
if (service != nullptr && (this->x != x || this->y != y || this->z != z)) {
11-
service->OnNewMotionValues(x, y, z);
12+
service->OnNewMotionValues(samples, samples_length);
1213
}
1314

1415
this->x = x;
@@ -69,18 +70,8 @@ int32_t MotionController::currentShakeSpeed() {
6970
void MotionController::IsSensorOk(bool isOk) {
7071
isSensorOk = isOk;
7172
}
72-
void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) {
73-
switch (types) {
74-
case Drivers::Bma421::DeviceTypes::BMA421:
75-
this->deviceType = DeviceTypes::BMA421;
76-
break;
77-
case Drivers::Bma421::DeviceTypes::BMA425:
78-
this->deviceType = DeviceTypes::BMA425;
79-
break;
80-
default:
81-
this->deviceType = DeviceTypes::Unknown;
82-
break;
83-
}
73+
void MotionController::Init(Pinetime::Drivers::AccelerationDeviceTypes types) {
74+
this->deviceType = types;
8475
}
8576
void MotionController::SetService(Pinetime::Controllers::MotionService* service) {
8677
this->service = service;

src/components/motion/MotionController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace Pinetime {
99
class MotionController {
1010
public:
1111

12-
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
12+
void Update(uint32_t nbSteps, int16_t x, int16_t y, int16_t z,
13+
int16_t* samples, uint16_t samples_length);
1314

1415
int16_t X() const {
1516
return x;

src/systemtask/SystemTask.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,6 @@ void SystemTask::UpdateMotion() {
481481
return;
482482
}
483483

484-
if (state == SystemTaskState::Sleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
485-
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
486-
return;
487-
}
488-
489484
if (stepCounterMustBeReset) {
490485
motionSensor.ResetStepCounter();
491486
stepCounterMustBeReset = false;
@@ -494,6 +489,8 @@ void SystemTask::UpdateMotion() {
494489
auto motionValues = motionSensor.Process();
495490

496491
motionController.IsSensorOk(motionSensor.IsInitialized());
492+
motionController.Update(motionValues.steps, motionValues.x, motionValues.y, motionValues.z,
493+
motionValues.samples, motionValues.samples_length);
497494

498495
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
499496
motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) {

0 commit comments

Comments
 (0)