Skip to content

Commit

Permalink
Merge branch 'p8-acc-hfble' into p8b
Browse files Browse the repository at this point in the history
  • Loading branch information
StarGate01 committed Jun 27, 2022
2 parents 949a325 + 5d88128 commit 63700ad
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
18 changes: 10 additions & 8 deletions src/components/ble/MotionService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,22 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {

ble_gattc_notify_custom(connectionHandle, stepCountHandle, om);
}
void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {

void MotionService::OnNewMotionValues(int16_t* samples, uint16_t samples_length) {
if (!motionValuesNoficationEnabled)
return;

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

uint16_t connectionHandle = system.nimble().connHandle();
uint16_t connectionHandle = system.nimble().connHandle();

if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return;
}
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return;
}

ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
}
}

void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ble/MotionService.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Pinetime {
void Init();
int OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void OnNewStepCountValue(uint32_t stepCount);
void OnNewMotionValues(int16_t x, int16_t y, int16_t z);
void OnNewMotionValues(int16_t* samples, uint16_t samples_length);

void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
Expand Down
4 changes: 2 additions & 2 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#include "os/os_cputime.h"
using namespace Pinetime::Controllers;

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

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

this->x = x;
Expand Down
2 changes: 1 addition & 1 deletion src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Pinetime {
namespace Controllers {
class MotionController {
public:
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
void Update(uint32_t nbSteps, int16_t x, int16_t y, int16_t z, int16_t* samples, uint16_t samples_length);

int16_t X() const {
return x;
Expand Down
8 changes: 2 additions & 6 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,6 @@ void SystemTask::UpdateMotion() {
return;
}

if (state == SystemTaskState::Sleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
return;
}

if (stepCounterMustBeReset) {
motionSensor.ResetStepCounter();
stepCounterMustBeReset = false;
Expand All @@ -487,7 +482,8 @@ void SystemTask::UpdateMotion() {
auto motionValues = motionSensor.Process();

motionController.IsSensorOk(motionSensor.IsInitialized());
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
motionController
.Update(motionValues.steps, motionValues.x, motionValues.y, motionValues.z, motionValues.samples, motionValues.samples_length);

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

0 comments on commit 63700ad

Please sign in to comment.