From c2ecd4c73179fac7cea866ddbfaaa3727e03dd51 Mon Sep 17 00:00:00 2001 From: Diego Miguel Date: Wed, 2 Mar 2022 00:05:31 +0100 Subject: Add Infineat settings to settings controller --- src/components/settings/Settings.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/components/settings') diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 3b113ead..686024b2 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -41,6 +41,10 @@ namespace Pinetime { Colors ColorBar = Colors::Teal; Colors ColorBG = Colors::Black; }; + struct WatchFaceInfineat { + bool showSideCover = true; + int colorIndex = 0; + }; Settings(Pinetime::Controllers::FS& fs); @@ -94,6 +98,24 @@ namespace Pinetime { return settings.PTS.ColorBG; }; + void SetInfineatShowSideCover(bool show) { + if (show != settings.watchFaceInfineat.showSideCover) + settingsChanged = true; + settings.watchFaceInfineat.showSideCover = show; + }; + bool GetInfineatShowSideCover() const { + return settings.watchFaceInfineat.showSideCover; + }; + + void SetInfineatColorIndex(int index) { + if (index != settings.watchFaceInfineat.colorIndex) + settingsChanged = true; + settings.watchFaceInfineat.colorIndex = index; + }; + int GetInfineatColorIndex() const { + return settings.watchFaceInfineat.colorIndex; + }; + void SetAppMenu(uint8_t menu) { appMenu = menu; }; @@ -226,6 +248,8 @@ namespace Pinetime { PineTimeStyle PTS; + WatchFaceInfineat watchFaceInfineat; + std::bitset<4> wakeUpMode {0}; uint16_t shakeWakeThreshold = 150; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; -- cgit v1.2.3-70-g09d2 From a890f8568a0d0adfdd7118a21393d16c2423f941 Mon Sep 17 00:00:00 2001 From: Diego Miguel Date: Thu, 3 Mar 2022 01:57:42 +0100 Subject: Fixes in side cover toggling --- src/components/settings/Settings.h | 10 +++-- src/displayapp/screens/WatchFaceInfineat.cpp | 67 ++++++++++++++-------------- src/displayapp/screens/WatchFaceInfineat.h | 2 - 3 files changed, 39 insertions(+), 40 deletions(-) (limited to 'src/components/settings') diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 686024b2..56248d02 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -99,18 +99,20 @@ namespace Pinetime { }; void SetInfineatShowSideCover(bool show) { - if (show != settings.watchFaceInfineat.showSideCover) + if (show != settings.watchFaceInfineat.showSideCover) { + settings.watchFaceInfineat.showSideCover = show; settingsChanged = true; - settings.watchFaceInfineat.showSideCover = show; + } }; bool GetInfineatShowSideCover() const { return settings.watchFaceInfineat.showSideCover; }; void SetInfineatColorIndex(int index) { - if (index != settings.watchFaceInfineat.colorIndex) + if (index != settings.watchFaceInfineat.colorIndex) { + settings.watchFaceInfineat.colorIndex = index; settingsChanged = true; - settings.watchFaceInfineat.colorIndex = index; + } }; int GetInfineatColorIndex() const { return settings.watchFaceInfineat.colorIndex; diff --git a/src/displayapp/screens/WatchFaceInfineat.cpp b/src/displayapp/screens/WatchFaceInfineat.cpp index 5ca7d70d..c21b8555 100644 --- a/src/displayapp/screens/WatchFaceInfineat.cpp +++ b/src/displayapp/screens/WatchFaceInfineat.cpp @@ -61,6 +61,7 @@ WatchFaceInfineat::WatchFaceInfineat(DisplayApp* app, line0Points[1] = {68, -8}; lv_line_set_points(line0, line0Points, 2); + lv_style_init(&line1Style); lv_style_set_line_width(&line1Style, LV_STATE_DEFAULT, 15); lv_style_set_line_color(&line1Style, LV_STATE_DEFAULT, lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 1])); @@ -294,51 +295,65 @@ bool WatchFaceInfineat::OnButtonPushed() { void WatchFaceInfineat::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event == LV_EVENT_CLICKED) { + bool showSideCover = settingsController.GetInfineatShowSideCover(); + int colorIndex = settingsController.GetInfineatColorIndex(); + if (object == btnSettings) { lv_obj_set_hidden(btnSettings, true); lv_obj_set_hidden(btnClose, false); - lv_obj_set_hidden(btnNextColor, settingsController.GetInfineatShowSideCover()); - lv_obj_set_hidden(btnPrevColor, settingsController.GetInfineatShowSideCover()); + lv_obj_set_hidden(btnNextColor, !showSideCover); + lv_obj_set_hidden(btnPrevColor, !showSideCover); lv_obj_set_hidden(btnToggleCover, false); } if (object == btnClose) { CloseMenu(); } if (object == btnToggleCover) { - bool hidden = ToggleShowSideCover(); - lv_obj_set_hidden(btnNextColor, hidden); - lv_obj_set_hidden(btnPrevColor, hidden); - const char* labelToggle = hidden ? "OFF" : "ON"; + settingsController.SetInfineatShowSideCover(!showSideCover); + lv_obj_set_hidden(logoPine, showSideCover); + lv_obj_set_hidden(line0, showSideCover); + lv_obj_set_hidden(line1, showSideCover); + lv_obj_set_hidden(line2, showSideCover); + lv_obj_set_hidden(line3, showSideCover); + lv_obj_set_hidden(line4, showSideCover); + lv_obj_set_hidden(line5, showSideCover); + lv_obj_set_hidden(line6, showSideCover); + lv_obj_set_hidden(line7, showSideCover); + lv_obj_set_hidden(line8, showSideCover); + lv_obj_set_hidden(btnNextColor, showSideCover); + lv_obj_set_hidden(btnPrevColor, showSideCover); + const char* labelToggle = showSideCover ? "OFF" : "ON"; lv_obj_set_style_local_value_str(btnToggleCover, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, labelToggle); } if (object == btnNextColor) { - settingsController.SetInfineatColorIndex((settingsController.GetInfineatColorIndex() + 1) % nColors); + colorIndex = (colorIndex + 1) % nColors; + settingsController.SetInfineatColorIndex(colorIndex); } if (object == btnPrevColor) { - int colorIndex = settingsController.GetInfineatColorIndex() - 1; + colorIndex -= 1; if (colorIndex < 0) colorIndex = nColors - 1; settingsController.SetInfineatColorIndex(colorIndex); } if (object == btnNextColor || object == btnPrevColor) { lv_style_set_line_color(&line0Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines])); + lv_color_hex(infineatColors.orange[colorIndex*nLines])); lv_style_set_line_color(&line1Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 1])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 1])); lv_style_set_line_color(&line2Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 2])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 2])); lv_style_set_line_color(&line3Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 3])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 3])); lv_style_set_line_color(&line4Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 4])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 4])); lv_style_set_line_color(&line5Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 5])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 5])); lv_style_set_line_color(&line6Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 6])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 6])); lv_style_set_line_color(&line7Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 7])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 7])); lv_style_set_line_color(&line8Style, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 8])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 8])); lv_obj_add_style(line0, LV_LINE_PART_MAIN, &line0Style); lv_obj_add_style(line1, LV_LINE_PART_MAIN, &line1Style); lv_obj_add_style(line2, LV_LINE_PART_MAIN, &line2Style); @@ -349,7 +364,7 @@ void WatchFaceInfineat::UpdateSelected(lv_obj_t* object, lv_event_t event) { lv_obj_add_style(line7, LV_LINE_PART_MAIN, &line7Style); lv_obj_add_style(line8, LV_LINE_PART_MAIN, &line8Style); lv_obj_set_style_local_bg_color(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, - lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 7])); + lv_color_hex(infineatColors.orange[colorIndex*nLines + 7])); } } } @@ -449,19 +464,3 @@ void WatchFaceInfineat::Refresh() { } } } - -bool WatchFaceInfineat::ToggleShowSideCover() { - bool visible = !settingsController.GetInfineatShowSideCover(); - settingsController.SetInfineatShowSideCover(visible); - lv_obj_set_hidden(logoPine, visible); - lv_obj_set_hidden(line0, visible); - lv_obj_set_hidden(line1, visible); - lv_obj_set_hidden(line2, visible); - lv_obj_set_hidden(line3, visible); - lv_obj_set_hidden(line4, visible); - lv_obj_set_hidden(line5, visible); - lv_obj_set_hidden(line6, visible); - lv_obj_set_hidden(line7, visible); - lv_obj_set_hidden(line8, visible); - return visible; -} diff --git a/src/displayapp/screens/WatchFaceInfineat.h b/src/displayapp/screens/WatchFaceInfineat.h index 77730062..afc25393 100644 --- a/src/displayapp/screens/WatchFaceInfineat.h +++ b/src/displayapp/screens/WatchFaceInfineat.h @@ -123,8 +123,6 @@ namespace Pinetime { Controllers::MotionController& motionController; lv_task_t* taskRefresh; - - bool ToggleShowSideCover(); }; } } -- cgit v1.2.3-70-g09d2 From a3bfbb5e08d57c4e834e8565d103870230fa1698 Mon Sep 17 00:00:00 2001 From: Diego Miguel Date: Sun, 6 Mar 2022 13:32:06 +0100 Subject: Implement SettingWatchFace list --- src/components/settings/Settings.h | 9 +++ src/displayapp/screens/Clock.cpp | 6 +- .../screens/settings/SettingWatchFace.cpp | 91 +++++++++------------- src/displayapp/screens/settings/SettingWatchFace.h | 11 ++- 4 files changed, 55 insertions(+), 62 deletions(-) (limited to 'src/components/settings') diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 56248d02..71222da4 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -133,6 +133,14 @@ namespace Pinetime { return settingsMenu; }; + void SetWatchfacesMenu(uint8_t menu) { + watchFacesMenu = menu; + }; + + uint8_t GetWatchfacesMenu() const { + return watchFacesMenu; + }; + void SetClockType(ClockType clocktype) { if (clocktype != settings.clockType) { settingsChanged = true; @@ -262,6 +270,7 @@ namespace Pinetime { uint8_t appMenu = 0; uint8_t settingsMenu = 0; + uint8_t watchFacesMenu = 0; /* ble state is intentionally not saved with the other watch settings and initialized * to off (false) on every boot because we always want ble to be enabled on startup */ diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index de24ef88..7ed9539d 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -43,10 +43,10 @@ Clock::Clock(DisplayApp* app, case 2: return WatchFacePineTimeStyleScreen(); break; - // case 3: - // return WatchFaceTerminalScreen(); - // break; case 3: + return WatchFaceTerminalScreen(); + break; + case 4: return WatchFaceInfineatScreen(); break; } diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 3cb2a364..8cbbcf7b 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -1,59 +1,31 @@ #include "displayapp/screens/settings/SettingWatchFace.h" #include #include "displayapp/DisplayApp.h" +#include "displayapp/screens/CheckboxList.h" #include "displayapp/screens/Screen.h" #include "displayapp/screens/Styles.h" #include "displayapp/screens/Symbols.h" +#include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; -namespace { - 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 SettingWatchFace::options; +constexpr const char* SettingWatchFace::title; +constexpr const char* SettingWatchFace::symbol; SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - 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_COLUMN_LEFT); - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Watch face"); - 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_ORANGE); - lv_label_set_text_static(icon, Symbols::home); - 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]); - cbOption[i]->user_data = this; - lv_obj_set_event_cb(cbOption[i], event_handler); - SetRadioButtonStyle(cbOption[i]); - - if (settingsController.GetClockFace() == i) { - lv_checkbox_set_checked(cbOption[i], true); - } - } + : Screen(app), + settingsController {settingsController}, + screens {app, + settingsController.GetWatchfacesMenu(), + { + [this]() -> std::unique_ptr { + return CreateScreen1(); + }, + [this]() -> std::unique_ptr { + return CreateScreen2(); + } + }, + Screens::ScreenListModes::UpDown} { } SettingWatchFace::~SettingWatchFace() { @@ -61,15 +33,22 @@ SettingWatchFace::~SettingWatchFace() { settingsController.SaveSettings(); } -void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - for (unsigned int i = 0; i < options.size(); i++) { - if (object == cbOption[i]) { - lv_checkbox_set_checked(cbOption[i], true); - settingsController.SetClockFace(i); - } else { - lv_checkbox_set_checked(cbOption[i], false); - } - } - } +bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return screens.OnTouchEvent(event); +} + +std::unique_ptr SettingWatchFace::CreateScreen1() { + std::array watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; + return std::make_unique(0, 2, app, settingsController, title, + symbol, &Controllers::Settings::SetClockFace, + &Controllers::Settings::GetClockFace, + watchfaces); +} + +std::unique_ptr SettingWatchFace::CreateScreen2() { + std::array watchfaces {" Infineat face", "", "", ""}; + return std::make_unique(1, 2, app, settingsController, title, + symbol, &Controllers::Settings::SetClockFace, + &Controllers::Settings::GetClockFace, + watchfaces); } diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 62427b4f..7d14554e 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -4,8 +4,10 @@ #include #include +#include "displayapp/screens/ScreenList.h" #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" namespace Pinetime { @@ -17,13 +19,16 @@ namespace Pinetime { SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingWatchFace() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); + bool OnTouchEvent(TouchEvents event) override; private: - static constexpr std::array options = {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; Controllers::Settings& settingsController; + ScreenList<2> screens; - lv_obj_t* cbOption[options.size()]; + static constexpr const char* title = "Watch face"; + static constexpr const char* symbol = Symbols::home; + std::unique_ptr CreateScreen1(); + std::unique_ptr CreateScreen2(); }; } } -- cgit v1.2.3-70-g09d2 From b15f90aa1dfb5383becf12dcac85b27f9eb4b82e Mon Sep 17 00:00:00 2001 From: Diego Miguel Date: Sat, 12 Mar 2022 10:15:56 +0100 Subject: Bump settings version (#1) --- src/components/settings/Settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components/settings') diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 71222da4..02d28353 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -244,7 +244,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x0003; + static constexpr uint32_t settingsVersion = 0x0004; struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; -- cgit v1.2.3-70-g09d2