diff --git a/src/components/settings/Settings.cpp b/src/components/settings/Settings.cpp index 1ae00a2d..05ab23d4 100644 --- a/src/components/settings/Settings.cpp +++ b/src/components/settings/Settings.cpp @@ -8,7 +8,6 @@ Settings::Settings(Pinetime::Controllers::FS& fs) : fs {fs} { } void Settings::Init() { - // Load default settings from Flash LoadSettingsFromFile(); } diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 77c1ca1a..53ab75a2 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -320,6 +320,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; }; diff --git a/src/displayapp/screens/settings/SettingHeartRate.cpp b/src/displayapp/screens/settings/SettingHeartRate.cpp index 8460e260..99f4a463 100644 --- a/src/displayapp/screens/settings/SettingHeartRate.cpp +++ b/src/displayapp/screens/settings/SettingHeartRate.cpp @@ -9,77 +9,68 @@ using namespace Pinetime::Applications::Screens; -constexpr const char* SettingHeartRate::title; -constexpr const char* SettingHeartRate::symbol; - namespace { - constexpr std::array intervalOptions = {{ - 0, - 30 * 1000, - 60 * 1000, - 5 * 60 * 1000, - 10 * 60 * 1000, - 30 * 60 * 1000, - }}; + void event_handler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); + screen->UpdateSelected(obj, event); + } +} - constexpr std::array options = {{ - {"Off", true}, - {"30s", true}, - {"1 min", true}, - {"5 min", true}, - {"10 min", true}, - {"30 min", true}, - {"", false}, - {"", false}, - }}; +constexpr std::array SettingHeartRate::options; - uint32_t GetDefaultOption(uint32_t currentInterval) { - for (size_t i = 0; i < intervalOptions.size(); i++) { - if (intervalOptions[i] == currentInterval) { - return i; - } +SettingHeartRate::SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) + : app {app}, settingsController {settingsController} { + + 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()>, nScreens> screens; - for (size_t i = 0; i < screens.size(); i++) { - screens[i] = [this, i]() -> std::unique_ptr { - 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() { lv_obj_clean(lv_scr_act()); + settingsController.SaveSettings(); } -bool SettingHeartRate::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - return screens.OnTouchEvent(event); -} - -std::unique_ptr SettingHeartRate::CreateScreen(unsigned int screenNum) const { - std::array optionsOnThisScreen; - for (int i = 0; i < optionsPerScreen; i++) { - optionsOnThisScreen[i] = options[screenNum * optionsPerScreen + i]; +void SettingHeartRate::UpdateSelected(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_CLICKED) { + for (unsigned int i = 0; i < options.size(); i++) { + if (object == cbOption[i]) { + lv_checkbox_set_checked(cbOption[i], true); + settingsController.SetHeartRateBackgroundMeasurementInterval(options[i].interval); + } else { + lv_checkbox_set_checked(cbOption[i], false); + } + } } - - return std::make_unique( - screenNum, - nScreens, - title, - symbol, - GetDefaultOption(settings.GetHeartRateBackgroundMeasurementInterval()), - [&settings = settings](uint32_t index) { - settings.SetHeartRateBackgroundMeasurementInterval(intervalOptions[index]); - settings.SaveSettings(); - }, - optionsOnThisScreen); -} \ No newline at end of file +} diff --git a/src/displayapp/screens/settings/SettingHeartRate.h b/src/displayapp/screens/settings/SettingHeartRate.h index 6b4ba581..28605bac 100644 --- a/src/displayapp/screens/settings/SettingHeartRate.h +++ b/src/displayapp/screens/settings/SettingHeartRate.h @@ -14,28 +14,34 @@ namespace Pinetime { namespace Applications { namespace Screens { + struct Option { + const uint32_t interval; + const char* name; + }; + class SettingHeartRate : public Screen { public: SettingHeartRate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settings); ~SettingHeartRate() override; - bool OnTouchEvent(TouchEvents event) override; + void UpdateSelected(lv_obj_t* object, lv_event_t event); private: DisplayApp* app; + Pinetime::Controllers::Settings& settingsController; - auto CreateScreenList() const; - std::unique_ptr CreateScreen(unsigned int screenNum) const; + static constexpr std::array options = {{ + {0, "Off"}, + {10, "10s"}, + {30, "30s"}, + {60, " 1m"}, + {5 * 60, " 5m"}, + {10 * 60, "10m"}, + {30 * 60, "30m"}, + {60 * 60, " 1h"}, + }}; - Pinetime::Controllers::Settings& settings; - - 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 screens; + lv_obj_t* cbOption[options.size()]; }; } } diff --git a/src/heartratetask/HeartRateTask.cpp b/src/heartratetask/HeartRateTask.cpp index e833dfe0..531cdf5e 100644 --- a/src/heartratetask/HeartRateTask.cpp +++ b/src/heartratetask/HeartRateTask.cpp @@ -112,7 +112,7 @@ void HeartRateTask::HandleBackgroundWaiting() { return; } - if (xTaskGetTickCount() - backgroundWaitingStart >= settings.GetHeartRateBackgroundMeasurementInterval()) { + if (xTaskGetTickCount() - backgroundWaitingStart >= settings.GetHeartRateBackgroundMeasurementInterval() * 1000) { state = States::BackgroundMeasuring; StartMeasurement(); }