From a5db54af2793a472f7e315d3580d1ee2c597a4f2 Mon Sep 17 00:00:00 2001 From: Patric Gruber Date: Thu, 11 May 2023 23:47:31 +0200 Subject: [PATCH] rebase on main --- src/heartratetask/HeartRateTask.cpp | 16 ++++++---------- src/heartratetask/HeartRateTask.h | 3 +-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/heartratetask/HeartRateTask.cpp b/src/heartratetask/HeartRateTask.cpp index f48045d8..a010cd44 100644 --- a/src/heartratetask/HeartRateTask.cpp +++ b/src/heartratetask/HeartRateTask.cpp @@ -24,7 +24,7 @@ void HeartRateTask::Process(void* instance) { } void HeartRateTask::Work() { - lastBpm = 0; + int lastBpm = 0; while (true) { auto delay = CurrentTaskDelay(); @@ -75,7 +75,7 @@ void HeartRateTask::Work() { if (state == States::BackgroundWaiting) { HandleBackgroundWaiting(); } else if (state == States::BackgroundMeasuring || state == States::Measuring) { - HandleSensorData(); + HandleSensorData(&lastBpm); } } } @@ -105,7 +105,7 @@ void HeartRateTask::HandleBackgroundWaiting() { } } -void HeartRateTask::HandleSensorData() { +void HeartRateTask::HandleSensorData(int* lastBpm) { int8_t ambient = ppg.Preprocess(heartRateSensor.ReadHrs(), heartRateSensor.ReadAls()); int bpm = ppg.HeartRate(); @@ -113,24 +113,20 @@ void HeartRateTask::HandleSensorData() { if (ambient > 0) { // Reset all DAQ buffers ppg.Reset(true); - // Force state to NotEnoughData (below) - lastBpm = 0; - bpm = 0; } else if (bpm < 0) { // Reset all DAQ buffers except HRS buffer ppg.Reset(false); // Set HR to zero and update bpm = 0; - controller.Update(Controllers::HeartRateController::States::Running, bpm); } - if (lastBpm == 0 && bpm == 0) { + if (*lastBpm == 0 && bpm == 0) { controller.Update(Controllers::HeartRateController::States::NotEnoughData, bpm); } if (bpm != 0) { - lastBpm = bpm; - controller.Update(Controllers::HeartRateController::States::Running, lastBpm); + *lastBpm = bpm; + controller.Update(Controllers::HeartRateController::States::Running, bpm); if (state == States::BackgroundMeasuring) { StopMeasurement(); state = States::BackgroundWaiting; diff --git a/src/heartratetask/HeartRateTask.h b/src/heartratetask/HeartRateTask.h index 61151af2..d27f68e7 100644 --- a/src/heartratetask/HeartRateTask.h +++ b/src/heartratetask/HeartRateTask.h @@ -32,7 +32,7 @@ namespace Pinetime { void StopMeasurement(); void HandleBackgroundWaiting(); - void HandleSensorData(); + void HandleSensorData(int* lastBpm); int CurrentTaskDelay(); TaskHandle_t taskHandle; @@ -41,7 +41,6 @@ namespace Pinetime { Drivers::Hrs3300& heartRateSensor; Controllers::HeartRateController& controller; Controllers::Ppg ppg; - int lastBpm = 0; TickType_t backgroundMeasurementWaitingStart = 0; };