use different style for the heartrate settings and fix issues with settings file

This commit is contained in:
Patric Gruber 2023-08-25 13:06:18 +02:00
parent 27ee1eb2c8
commit be1a519098
5 changed files with 73 additions and 76 deletions

View file

@ -8,7 +8,6 @@ Settings::Settings(Pinetime::Controllers::FS& fs) : fs {fs} {
} }
void Settings::Init() { void Settings::Init() {
// Load default settings from Flash // Load default settings from Flash
LoadSettingsFromFile(); LoadSettingsFromFile();
} }

View file

@ -320,6 +320,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)
uint32_t heartRateBackgroundMeasurementInterval = 0; uint32_t heartRateBackgroundMeasurementInterval = 0;
}; };

View file

@ -9,77 +9,68 @@
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
constexpr const char* SettingHeartRate::title;
constexpr const char* SettingHeartRate::symbol;
namespace { namespace {
constexpr std::array<uint32_t, 6> intervalOptions = {{ void event_handler(lv_obj_t* obj, lv_event_t event) {
0, auto* screen = static_cast<SettingHeartRate*>(obj->user_data);
30 * 1000, screen->UpdateSelected(obj, event);
60 * 1000, }
5 * 60 * 1000, }
10 * 60 * 1000,
30 * 60 * 1000,
}};
constexpr std::array<CheckboxList::Item, 8> options = {{ constexpr std::array<Option, 8> SettingHeartRate::options;
{"Off", true},
{"30s", true},
{"1 min", true},
{"5 min", true},
{"10 min", true},
{"30 min", true},
{"", false},
{"", false},
}};
uint32_t GetDefaultOption(uint32_t currentInterval) { SettingHeartRate::SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
for (size_t i = 0; i < intervalOptions.size(); i++) { : app {app}, settingsController {settingsController} {
if (intervalOptions[i] == currentInterval) {
return i; 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_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_pos(container1, 10, 60);
lv_obj_set_width(container1, LV_HOR_RES - 20);
lv_obj_set_height(container1, LV_VER_RES - 50);
lv_cont_set_layout(container1, LV_LAYOUT_PRETTY_TOP);
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(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);
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
lv_label_set_text_static(icon, Symbols::heartBeat);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
for (unsigned int i = 0; i < options.size(); i++) {
cbOption[i] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text(cbOption[i], options[i].name);
cbOption[i]->user_data = this;
lv_obj_set_event_cb(cbOption[i], event_handler);
SetRadioButtonStyle(cbOption[i]);
if (settingsController.GetHeartRateBackgroundMeasurementInterval() == options[i].interval) {
lv_checkbox_set_checked(cbOption[i], true);
} }
return 0;
} }
} }
auto SettingHeartRate::CreateScreenList() const {
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
for (size_t i = 0; i < screens.size(); i++) {
screens[i] = [this, i]() -> std::unique_ptr<Screen> {
return CreateScreen(i);
};
}
return screens;
}
SettingHeartRate::SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settings)
: app {app}, settings {settings}, screens {app, 0, CreateScreenList(), Screens::ScreenListModes::UpDown} {
}
SettingHeartRate::~SettingHeartRate() { SettingHeartRate::~SettingHeartRate() {
lv_obj_clean(lv_scr_act()); lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
} }
bool SettingHeartRate::OnTouchEvent(Pinetime::Applications::TouchEvents event) { void SettingHeartRate::UpdateSelected(lv_obj_t* object, lv_event_t event) {
return screens.OnTouchEvent(event); if (event == LV_EVENT_CLICKED) {
} for (unsigned int i = 0; i < options.size(); i++) {
if (object == cbOption[i]) {
std::unique_ptr<Screen> SettingHeartRate::CreateScreen(unsigned int screenNum) const { lv_checkbox_set_checked(cbOption[i], true);
std::array<Screens::CheckboxList::Item, optionsPerScreen> optionsOnThisScreen; settingsController.SetHeartRateBackgroundMeasurementInterval(options[i].interval);
for (int i = 0; i < optionsPerScreen; i++) { } else {
optionsOnThisScreen[i] = options[screenNum * optionsPerScreen + i]; lv_checkbox_set_checked(cbOption[i], false);
}
}
} }
}
return std::make_unique<Screens::CheckboxList>(
screenNum,
nScreens,
title,
symbol,
GetDefaultOption(settings.GetHeartRateBackgroundMeasurementInterval()),
[&settings = settings](uint32_t index) {
settings.SetHeartRateBackgroundMeasurementInterval(intervalOptions[index]);
settings.SaveSettings();
},
optionsOnThisScreen);
}

View file

@ -14,28 +14,34 @@ namespace Pinetime {
namespace Applications { namespace Applications {
namespace Screens { namespace Screens {
struct Option {
const uint32_t interval;
const char* name;
};
class SettingHeartRate : public Screen { class SettingHeartRate : public Screen {
public: public:
SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settings); SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settings);
~SettingHeartRate() override; ~SettingHeartRate() override;
bool OnTouchEvent(TouchEvents event) override; void UpdateSelected(lv_obj_t* object, lv_event_t event);
private: private:
DisplayApp* app; DisplayApp* app;
Pinetime::Controllers::Settings& settingsController;
auto CreateScreenList() const; static constexpr std::array<Option, 8> options = {{
std::unique_ptr<Screen> CreateScreen(unsigned int screenNum) const; {0, "Off"},
{10, "10s"},
{30, "30s"},
{60, " 1m"},
{5 * 60, " 5m"},
{10 * 60, "10m"},
{30 * 60, "30m"},
{60 * 60, " 1h"},
}};
Pinetime::Controllers::Settings& settings; lv_obj_t* cbOption[options.size()];
static constexpr const char* title = "Backg. Interval";
static constexpr const char* symbol = Symbols::heartBeat;
static constexpr int optionsPerScreen = 4;
static constexpr int nScreens = 2;
ScreenList<nScreens> screens;
}; };
} }
} }

View file

@ -112,7 +112,7 @@ void HeartRateTask::HandleBackgroundWaiting() {
return; return;
} }
if (xTaskGetTickCount() - backgroundWaitingStart >= settings.GetHeartRateBackgroundMeasurementInterval()) { if (xTaskGetTickCount() - backgroundWaitingStart >= settings.GetHeartRateBackgroundMeasurementInterval() * 1000) {
state = States::BackgroundMeasuring; state = States::BackgroundMeasuring;
StartMeasurement(); StartMeasurement();
} }