From eeaf5374d4d1cfe427c4aa7e883c8d830bb29967 Mon Sep 17 00:00:00 2001 From: Patric Gruber Date: Thu, 25 May 2023 23:41:26 +0200 Subject: [PATCH] stop background after 30s of no data from the heart rate sensor --- src/heartratetask/HeartRateTask.cpp | 4 ++++ src/heartratetask/HeartRateTask.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/heartratetask/HeartRateTask.cpp b/src/heartratetask/HeartRateTask.cpp index 56439e93..3ee04be9 100644 --- a/src/heartratetask/HeartRateTask.cpp +++ b/src/heartratetask/HeartRateTask.cpp @@ -154,6 +154,10 @@ void HeartRateTask::HandleSensorData(int* lastBpm) { state = States::BackgroundWaiting; StartWaiting(); } + if (bpm == 0 && state == States::BackgroundMeasuring && xTaskGetTickCount() - measurementStart >= DURATION_UNTIL_BACKGROUND_MEASURMENT_IS_STOPPED) { + state = States::BackgroundWaiting; + StartWaiting(); + } } int HeartRateTask::CurrentTaskDelay() { diff --git a/src/heartratetask/HeartRateTask.h b/src/heartratetask/HeartRateTask.h index e08d29d0..85ccb601 100644 --- a/src/heartratetask/HeartRateTask.h +++ b/src/heartratetask/HeartRateTask.h @@ -7,7 +7,8 @@ #define DURATION_UNTIL_BACKGROUND_MEASURMENT_IS_STOPPED 30 * 1000 // 30 seconds assuming 1 Hz -#define DURATION_BETWEEN_BACKGROUND_MEASUREMENTS 5 * 60 * 1000 // 5 Minutes assuming 1 Hz +#define DURATION_BETWEEN_BACKGROUND_MEASUREMENTS 5 * 60 * 1000 // 5 minutes assuming 1 Hz +#define DURATION_UNTIL_BACKGROUND_MEASURMENT_IS_STOPPED 30 * 1000 // 30 seconds assuming 1 Hz namespace Pinetime { namespace Drivers {