From 6e7897f7b5b42734afed75d62717a51badaa8275 Mon Sep 17 00:00:00 2001 From: Andersama Date: Sat, 22 Nov 2025 11:41:24 -0800 Subject: [PATCH] Keep heart rate tracking setting after reboot --- src/components/settings/Settings.h | 12 +++++++++++- src/displayapp/screens/HeartRate.cpp | 1 + src/heartratetask/HeartRateTask.cpp | 9 +++++++++ src/heartratetask/HeartRateTask.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 9133d3fea1..7efa8e80e8 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -336,6 +336,15 @@ namespace Pinetime { return (settings.dfuAndFsEnabledOnBoot ? DfuAndFsMode::Enabled : DfuAndFsMode::Disabled); }; + void SetHeartRateRebootMode(bool enabled) { + settingsChanged = settingsChanged || (enabled != settings.heartRateEnabledOnBoot); + settings.heartRateEnabledOnBoot = enabled; + } + + bool GetHeartRateRebootMode() { + return settings.heartRateEnabledOnBoot; + } + std::optional GetHeartRateBackgroundMeasurementInterval() const { if (settings.heartRateBackgroundPeriod == std::numeric_limits::max()) { return std::nullopt; @@ -354,7 +363,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x000a; + static constexpr uint32_t settingsVersion = 0x000b; struct SettingsData { uint32_t version = settingsVersion; @@ -383,6 +392,7 @@ namespace Pinetime { bool dfuAndFsEnabledOnBoot = false; uint16_t heartRateBackgroundPeriod = std::numeric_limits::max(); // Disabled by default + bool heartRateEnabledOnBoot = false; }; SettingsData settings; diff --git a/src/displayapp/screens/HeartRate.cpp b/src/displayapp/screens/HeartRate.cpp index 14c873e201..b0daa6d33d 100644 --- a/src/displayapp/screens/HeartRate.cpp +++ b/src/displayapp/screens/HeartRate.cpp @@ -72,6 +72,7 @@ HeartRate::HeartRate(Controllers::HeartRateController& heartRateController, Syst HeartRate::~HeartRate() { lv_task_del(taskRefresh); lv_obj_clean(lv_scr_act()); + heartRateController.SaveSettings(); } void HeartRate::Refresh() { diff --git a/src/heartratetask/HeartRateTask.cpp b/src/heartratetask/HeartRateTask.cpp index e9bc11a30a..2ba6d1975b 100644 --- a/src/heartratetask/HeartRateTask.cpp +++ b/src/heartratetask/HeartRateTask.cpp @@ -100,6 +100,9 @@ void HeartRateTask::Start() { if (pdPASS != xTaskCreate(HeartRateTask::Process, "Heartrate", 500, this, 1, &taskHandle)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); + } else { + if (settings.GetHeartRateRebootMode()) + controller.Enable(); } } @@ -147,9 +150,11 @@ void HeartRateTask::Work() { // will self-resolve at the next screen on event newState = States::ForegroundMeasuring; valueCurrentlyShown = false; + settings.SetHeartRateRebootMode(true); break; case Messages::Disable: newState = States::Disabled; + settings.SetHeartRateRebootMode(false); break; } } @@ -176,6 +181,10 @@ void HeartRateTask::Work() { } } +void HeartRateTask::SaveSettings() { + settings.SaveSettings(); +} + void HeartRateTask::PushMessage(HeartRateTask::Messages msg) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; xQueueSendFromISR(messageQueue, &msg, &xHigherPriorityTaskWoken); diff --git a/src/heartratetask/HeartRateTask.h b/src/heartratetask/HeartRateTask.h index e00bc4d638..a4dca8da2e 100644 --- a/src/heartratetask/HeartRateTask.h +++ b/src/heartratetask/HeartRateTask.h @@ -27,6 +27,7 @@ namespace Pinetime { void Start(); void Work(); void PushMessage(Messages msg); + void SaveSettings(); private: enum class States : uint8_t { Disabled, Waiting, BackgroundMeasuring, ForegroundMeasuring };