use enum instead of uint32_t for heartrater interval setting
This commit is contained in:
parent
be1a519098
commit
d376a856b7
|
@ -50,6 +50,17 @@ namespace Pinetime {
|
|||
int colorIndex = 0;
|
||||
};
|
||||
|
||||
enum class HeartRateBackgroundMeasurementInterval : uint8_t {
|
||||
Off,
|
||||
Continuous,
|
||||
TenSeconds,
|
||||
ThirtySeconds,
|
||||
OneMinute,
|
||||
FiveMinutes,
|
||||
TenMinutes,
|
||||
ThirtyMinutes,
|
||||
};
|
||||
|
||||
Settings(Pinetime::Controllers::FS& fs);
|
||||
|
||||
Settings(const Settings&) = delete;
|
||||
|
@ -283,11 +294,11 @@ namespace Pinetime {
|
|||
return bleRadioEnabled;
|
||||
};
|
||||
|
||||
uint32_t GetHeartRateBackgroundMeasurementInterval() const {
|
||||
HeartRateBackgroundMeasurementInterval GetHeartRateBackgroundMeasurementInterval() const {
|
||||
return settings.heartRateBackgroundMeasurementInterval;
|
||||
}
|
||||
|
||||
void SetHeartRateBackgroundMeasurementInterval(uint32_t newHeartRateBackgroundMeasurementInterval) {
|
||||
void SetHeartRateBackgroundMeasurementInterval(HeartRateBackgroundMeasurementInterval newHeartRateBackgroundMeasurementInterval) {
|
||||
if (newHeartRateBackgroundMeasurementInterval != settings.heartRateBackgroundMeasurementInterval) {
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
@ -320,8 +331,7 @@ namespace Pinetime {
|
|||
|
||||
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
|
||||
|
||||
// The interval for measuring the heart rate when the screen is off (in seconds)
|
||||
uint32_t heartRateBackgroundMeasurementInterval = 0;
|
||||
HeartRateBackgroundMeasurementInterval heartRateBackgroundMeasurementInterval = HeartRateBackgroundMeasurementInterval::Off;
|
||||
};
|
||||
|
||||
SettingsData settings;
|
||||
|
|
|
@ -24,7 +24,7 @@ SettingHeartRate::SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pine
|
|||
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_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_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_label_set_text_static(title, "Backg. Interval");
|
||||
lv_label_set_text(title, "Backg. Interval");
|
||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Pinetime {
|
|||
namespace Screens {
|
||||
|
||||
struct Option {
|
||||
const uint32_t interval;
|
||||
const Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval interval;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
|
@ -31,14 +31,14 @@ namespace Pinetime {
|
|||
Pinetime::Controllers::Settings& settingsController;
|
||||
|
||||
static constexpr std::array<Option, 8> options = {{
|
||||
{0, "Off"},
|
||||
{10, "10s"},
|
||||
{30, "30s"},
|
||||
{60, " 1m"},
|
||||
{5 * 60, " 5m"},
|
||||
{10 * 60, "10m"},
|
||||
{30 * 60, "30m"},
|
||||
{60 * 60, " 1h"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Off, " Off"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Continuous, "Cont"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenSeconds, " 10s"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtySeconds, " 30s"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::OneMinute, " 1m"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::FiveMinutes, " 5m"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenMinutes, " 10m"},
|
||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtyMinutes, " 30m"},
|
||||
}};
|
||||
|
||||
lv_obj_t* cbOption[options.size()];
|
||||
|
|
|
@ -107,12 +107,12 @@ void HeartRateTask::StartWaiting() {
|
|||
}
|
||||
|
||||
void HeartRateTask::HandleBackgroundWaiting() {
|
||||
if (settings.GetHeartRateBackgroundMeasurementInterval() == 0) {
|
||||
// stay waiting
|
||||
if (!IsBackgroundMeasurementActivated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xTaskGetTickCount() - backgroundWaitingStart >= settings.GetHeartRateBackgroundMeasurementInterval() * 1000) {
|
||||
TickType_t ticksSinceWaitingStart = xTaskGetTickCount() - backgroundWaitingStart;
|
||||
if (ticksSinceWaitingStart >= GetHeartRateBackgroundMeasurementIntervalInTicks()) {
|
||||
state = States::BackgroundMeasuring;
|
||||
StartMeasurement();
|
||||
}
|
||||
|
@ -140,13 +140,17 @@ void HeartRateTask::HandleSensorData(int* lastBpm) {
|
|||
if (bpm != 0) {
|
||||
*lastBpm = bpm;
|
||||
controller.Update(Controllers::HeartRateController::States::Running, bpm);
|
||||
if (state == States::Measuring || IsContinuosModeActivated()) {
|
||||
return;
|
||||
}
|
||||
if (state == States::BackgroundMeasuring) {
|
||||
state = States::BackgroundWaiting;
|
||||
StartWaiting();
|
||||
}
|
||||
}
|
||||
if (bpm == 0 && state == States::BackgroundMeasuring &&
|
||||
xTaskGetTickCount() - measurementStart >= DURATION_UNTIL_BACKGROUND_MEASURMENT_IS_STOPPED) {
|
||||
TickType_t ticksSinceMeasurementStart = xTaskGetTickCount() - measurementStart;
|
||||
if (bpm == 0 && state == States::BackgroundMeasuring && !IsContinuosModeActivated() &&
|
||||
ticksSinceMeasurementStart >= DURATION_UNTIL_BACKGROUND_MEASURMENT_IS_STOPPED) {
|
||||
state = States::BackgroundWaiting;
|
||||
StartWaiting();
|
||||
}
|
||||
|
@ -165,3 +169,32 @@ int HeartRateTask::CurrentTaskDelay() {
|
|||
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;
|
||||
}
|
|
@ -39,6 +39,10 @@ namespace Pinetime {
|
|||
void HandleSensorData(int* lastBpm);
|
||||
int CurrentTaskDelay();
|
||||
|
||||
uint32_t GetHeartRateBackgroundMeasurementIntervalInTicks();
|
||||
bool IsContinuosModeActivated();
|
||||
bool IsBackgroundMeasurementActivated();
|
||||
|
||||
TaskHandle_t taskHandle;
|
||||
QueueHandle_t messageQueue;
|
||||
States state = States::Running;
|
||||
|
|
Loading…
Reference in a new issue