Skip to content

Commit eb5ac72

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 3e3a5a6 commit eb5ac72

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

src/components/ble/MotionService.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,22 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
9090

9191
ble_gattc_notify_custom(connectionHandle, stepCountHandle, om);
9292
}
93-
void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
93+
94+
void MotionService::OnNewMotionValues(int16_t* samples, uint16_t samples_length) {
9495
if (!motionValuesNoficationEnabled)
9596
return;
9697

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

100-
uint16_t connectionHandle = system.nimble().connHandle();
101+
uint16_t connectionHandle = system.nimble().connHandle();
101102

102-
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
103-
return;
104-
}
103+
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
104+
return;
105+
}
105106

106-
ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
107+
ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
108+
}
107109
}
108110

109111
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
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, int16_t* samples, uint16_t samples_length) {
66
if (this->nbSteps != nbSteps && service != nullptr) {
77
service->OnNewStepCountValue(nbSteps);
88
}
99

1010
if (service != nullptr && (this->x != x || this->y != y || this->z != z)) {
11-
service->OnNewMotionValues(x, y, z);
11+
service->OnNewMotionValues(samples, samples_length);
1212
}
1313

1414
this->x = x;

src/components/motion/MotionController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Pinetime {
88
namespace Controllers {
99
class MotionController {
1010
public:
11-
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
11+
void Update(uint32_t nbSteps, int16_t x, int16_t y, int16_t z, int16_t* samples, uint16_t samples_length);
1212

1313
int16_t X() const {
1414
return x;

src/systemtask/SystemTask.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,6 @@ void SystemTask::UpdateMotion() {
468468
return;
469469
}
470470

471-
if (state == SystemTaskState::Sleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
472-
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
473-
return;
474-
}
475-
476471
if (stepCounterMustBeReset) {
477472
motionSensor.ResetStepCounter();
478473
stepCounterMustBeReset = false;
@@ -481,7 +476,8 @@ void SystemTask::UpdateMotion() {
481476
auto motionValues = motionSensor.Process();
482477

483478
motionController.IsSensorOk(motionSensor.IsInitialized());
484-
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
479+
motionController
480+
.Update(motionValues.steps, motionValues.x, motionValues.y, motionValues.z, motionValues.samples, motionValues.samples_length);
485481

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

0 commit comments

Comments
 (0)