use enum instead of uint32_t for heartrater interval setting

This commit is contained in:
Patric Gruber 2023-08-26 20:35:39 +02:00
parent be1a519098
commit d376a856b7
5 changed files with 67 additions and 19 deletions

View file

@ -50,6 +50,17 @@ namespace Pinetime {
int colorIndex = 0; int colorIndex = 0;
}; };
enum class HeartRateBackgroundMeasurementInterval : uint8_t {
Off,
Continuous,
TenSeconds,
ThirtySeconds,
OneMinute,
FiveMinutes,
TenMinutes,
ThirtyMinutes,
};
Settings(Pinetime::Controllers::FS& fs); Settings(Pinetime::Controllers::FS& fs);
Settings(const Settings&) = delete; Settings(const Settings&) = delete;
@ -283,11 +294,11 @@ namespace Pinetime {
return bleRadioEnabled; return bleRadioEnabled;
}; };
uint32_t GetHeartRateBackgroundMeasurementInterval() const { HeartRateBackgroundMeasurementInterval GetHeartRateBackgroundMeasurementInterval() const {
return settings.heartRateBackgroundMeasurementInterval; return settings.heartRateBackgroundMeasurementInterval;
} }
void SetHeartRateBackgroundMeasurementInterval(uint32_t newHeartRateBackgroundMeasurementInterval) { void SetHeartRateBackgroundMeasurementInterval(HeartRateBackgroundMeasurementInterval newHeartRateBackgroundMeasurementInterval) {
if (newHeartRateBackgroundMeasurementInterval != settings.heartRateBackgroundMeasurementInterval) { if (newHeartRateBackgroundMeasurementInterval != settings.heartRateBackgroundMeasurementInterval) {
settingsChanged = true; settingsChanged = true;
} }
@ -320,8 +331,7 @@ namespace Pinetime {
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
// The interval for measuring the heart rate when the screen is off (in seconds) HeartRateBackgroundMeasurementInterval heartRateBackgroundMeasurementInterval = HeartRateBackgroundMeasurementInterval::Off;
uint32_t heartRateBackgroundMeasurementInterval = 0;
}; };
SettingsData settings; SettingsData settings;

View file

@ -24,7 +24,7 @@ SettingHeartRate::SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pine
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
@ -35,6 +35,7 @@ SettingHeartRate::SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pine
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Backg. Interval"); lv_label_set_text_static(title, "Backg. Interval");
lv_label_set_text(title, "Backg. Interval");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15);

View file

@ -15,7 +15,7 @@ namespace Pinetime {
namespace Screens { namespace Screens {
struct Option { struct Option {
const uint32_t interval; const Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval interval;
const char* name; const char* name;
}; };
@ -31,14 +31,14 @@ namespace Pinetime {
Pinetime::Controllers::Settings& settingsController; Pinetime::Controllers::Settings& settingsController;
static constexpr std::array<Option, 8> options = {{ static constexpr std::array<Option, 8> options = {{
{0, "Off"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Off, " Off"},
{10, "10s"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Continuous, "Cont"},
{30, "30s"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenSeconds, " 10s"},
{60, " 1m"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtySeconds, " 30s"},
{5 * 60, " 5m"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::OneMinute, " 1m"},
{10 * 60, "10m"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::FiveMinutes, " 5m"},
{30 * 60, "30m"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenMinutes, " 10m"},
{60 * 60, " 1h"}, {Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtyMinutes, " 30m"},
}}; }};
lv_obj_t* cbOption[options.size()]; lv_obj_t* cbOption[options.size()];

View file

@ -107,12 +107,12 @@ void HeartRateTask::StartWaiting() {
} }
void HeartRateTask::HandleBackgroundWaiting() { void HeartRateTask::HandleBackgroundWaiting() {
if (settings.GetHeartRateBackgroundMeasurementInterval() == 0) { if (!IsBackgroundMeasurementActivated()) {
// stay waiting
return; return;
} }
if (xTaskGetTickCount() - backgroundWaitingStart >= settings.GetHeartRateBackgroundMeasurementInterval() * 1000) { TickType_t ticksSinceWaitingStart = xTaskGetTickCount() - backgroundWaitingStart;
if (ticksSinceWaitingStart >= GetHeartRateBackgroundMeasurementIntervalInTicks()) {
state = States::BackgroundMeasuring; state = States::BackgroundMeasuring;
StartMeasurement(); StartMeasurement();
} }
@ -140,13 +140,17 @@ void HeartRateTask::HandleSensorData(int* lastBpm) {
if (bpm != 0) { if (bpm != 0) {
*lastBpm = bpm; *lastBpm = bpm;
controller.Update(Controllers::HeartRateController::States::Running, bpm); controller.Update(Controllers::HeartRateController::States::Running, bpm);
if (state == States::Measuring || IsContinuosModeActivated()) {
return;
}
if (state == States::BackgroundMeasuring) { if (state == States::BackgroundMeasuring) {
state = States::BackgroundWaiting; state = States::BackgroundWaiting;
StartWaiting(); StartWaiting();
} }
} }
if (bpm == 0 && state == States::BackgroundMeasuring && TickType_t ticksSinceMeasurementStart = xTaskGetTickCount() - measurementStart;
xTaskGetTickCount() - measurementStart >= DURATION_UNTIL_BACKGROUND_MEASURMENT_IS_STOPPED) { if (bpm == 0 && state == States::BackgroundMeasuring && !IsContinuosModeActivated() &&
ticksSinceMeasurementStart >= DURATION_UNTIL_BACKGROUND_MEASURMENT_IS_STOPPED) {
state = States::BackgroundWaiting; state = States::BackgroundWaiting;
StartWaiting(); StartWaiting();
} }
@ -164,4 +168,33 @@ int HeartRateTask::CurrentTaskDelay() {
default: default:
return portMAX_DELAY; return portMAX_DELAY;
} }
}
uint32_t HeartRateTask::GetHeartRateBackgroundMeasurementIntervalInTicks() {
switch (settings.GetHeartRateBackgroundMeasurementInterval()) {
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenSeconds:
return 10 * 1000;
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtySeconds:
return 30 * 1000;
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::OneMinute:
return 60 * 1000;
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::FiveMinutes:
return 5 * 60 * 1000;
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenMinutes:
return 10 * 60 * 1000;
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtyMinutes:
return 30 * 60 * 1000;
default:
return 0;
}
}
bool HeartRateTask::IsContinuosModeActivated() {
return settings.GetHeartRateBackgroundMeasurementInterval() ==
Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Continuous;
}
bool HeartRateTask::IsBackgroundMeasurementActivated() {
return settings.GetHeartRateBackgroundMeasurementInterval() !=
Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Off;
} }

View file

@ -39,6 +39,10 @@ namespace Pinetime {
void HandleSensorData(int* lastBpm); void HandleSensorData(int* lastBpm);
int CurrentTaskDelay(); int CurrentTaskDelay();
uint32_t GetHeartRateBackgroundMeasurementIntervalInTicks();
bool IsContinuosModeActivated();
bool IsBackgroundMeasurementActivated();
TaskHandle_t taskHandle; TaskHandle_t taskHandle;
QueueHandle_t messageQueue; QueueHandle_t messageQueue;
States state = States::Running; States state = States::Running;