Implement persistent settings

This commit is contained in:
Kieran Cawthray 2022-09-06 11:37:12 +02:00
parent 2933405158
commit b49fddd555
2 changed files with 48 additions and 10 deletions

View File

@ -36,10 +36,13 @@ namespace Pinetime {
Purple, Purple,
Orange Orange
}; };
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
struct PineTimeStyle { struct PineTimeStyle {
Colors ColorTime = Colors::Teal; Colors ColorTime = Colors::Teal;
Colors ColorBar = Colors::Teal; Colors ColorBar = Colors::Teal;
Colors ColorBG = Colors::Black; Colors ColorBG = Colors::Black;
PTSGaugeStyle gaugeStyle = PTSGaugeStyle::Full;
}; };
Settings(Pinetime::Controllers::FS& fs); Settings(Pinetime::Controllers::FS& fs);
@ -94,6 +97,15 @@ namespace Pinetime {
return settings.PTS.ColorBG; return settings.PTS.ColorBG;
}; };
void SetPTSGaugeStyle(PTSGaugeStyle gaugeStyle) {
if (gaugeStyle != settings.PTS.gaugeStyle)
settingsChanged = true;
settings.PTS.gaugeStyle = gaugeStyle;
};
PTSGaugeStyle GetPTSGaugeStyle() const {
return settings.PTS.gaugeStyle;
};
void SetAppMenu(uint8_t menu) { void SetAppMenu(uint8_t menu) {
appMenu = menu; appMenu = menu;
}; };
@ -212,7 +224,7 @@ namespace Pinetime {
private: private:
Pinetime::Controllers::FS& fs; Pinetime::Controllers::FS& fs;
static constexpr uint32_t settingsVersion = 0x0003; static constexpr uint32_t settingsVersion = 0x0004;
struct SettingsData { struct SettingsData {
uint32_t version = settingsVersion; uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000; uint32_t stepsGoal = 10000;
@ -225,6 +237,7 @@ namespace Pinetime {
ChimesOption chimesOption = ChimesOption::None; ChimesOption chimesOption = ChimesOption::None;
PineTimeStyle PTS; PineTimeStyle PTS;
//PineTimeStyle::GaugeStyle gaugeStyle = PineTimeStyle::GaugeStyle::Full;
std::bitset<4> wakeUpMode {0}; std::bitset<4> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150; uint16_t shakeWakeThreshold = 150;

View File

@ -172,14 +172,24 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(DisplayApp* app,
} }
stepGauge = lv_gauge_create(lv_scr_act(), nullptr); stepGauge = lv_gauge_create(lv_scr_act(), nullptr);
lv_gauge_set_needle_count(stepGauge, 1, needle_colors); lv_gauge_set_needle_count(stepGauge, 1, needle_colors);
lv_obj_set_size(stepGauge, 40, 40);
lv_obj_align(stepGauge, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_gauge_set_scale(stepGauge, 360, 11, 0);
lv_gauge_set_angle_offset(stepGauge, 180);
lv_gauge_set_critical_value(stepGauge, 100);
lv_gauge_set_range(stepGauge, 0, 100); lv_gauge_set_range(stepGauge, 0, 100);
lv_gauge_set_value(stepGauge, 0, 0); lv_gauge_set_value(stepGauge, 0, 0);
if (settingsController.GetPTSGaugeStyle() == Pinetime::Controllers::Settings::PTSGaugeStyle::Full) {
lv_obj_set_size(stepGauge, 40, 40);
lv_obj_align(stepGauge, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_gauge_set_scale(stepGauge, 360, 11, 0);
lv_gauge_set_angle_offset(stepGauge, 180);
lv_gauge_set_critical_value(stepGauge, 100);
} else if (settingsController.GetPTSGaugeStyle() == Pinetime::Controllers::Settings::PTSGaugeStyle::Half) {
lv_obj_set_size(stepGauge, 37, 37);
lv_obj_align(stepGauge, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
lv_gauge_set_scale(stepGauge, 180, 5, 0);
lv_gauge_set_angle_offset(stepGauge, 0);
lv_gauge_set_critical_value(stepGauge, 120);
} else if (settingsController.GetPTSGaugeStyle() == Pinetime::Controllers::Settings::PTSGaugeStyle::Numeric) {
lv_obj_set_hidden(stepGauge, true);
}
lv_obj_set_style_local_pad_right(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_pad_right(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3);
lv_obj_set_style_local_pad_left(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_pad_left(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3);
lv_obj_set_style_local_pad_bottom(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_pad_bottom(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3);
@ -195,20 +205,32 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(DisplayApp* app,
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_label_set_text_static(stepValue, "0"); lv_label_set_text_static(stepValue, "0");
lv_obj_align(stepValue, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_align(stepValue, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_obj_set_hidden(stepValue, true); if (settingsController.GetPTSGaugeStyle() == Pinetime::Controllers::Settings::PTSGaugeStyle::Numeric) {
lv_obj_set_hidden(stepValue, false);
} else {
lv_obj_set_hidden(stepValue, true);
}
stepIcon = lv_label_create(lv_scr_act(), nullptr); stepIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_label_set_text_static(stepIcon, Symbols::shoe); lv_label_set_text_static(stepIcon, Symbols::shoe);
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_TOP_MID, 0, 0); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_TOP_MID, 0, 0);
lv_obj_set_hidden(stepIcon, true); if (settingsController.GetPTSGaugeStyle() == Pinetime::Controllers::Settings::PTSGaugeStyle::Numeric) {
lv_obj_set_hidden(stepIcon, false);
} else {
lv_obj_set_hidden(stepIcon, true);
}
// Display seconds // Display seconds
timeDD3 = lv_label_create(lv_scr_act(), nullptr); timeDD3 = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(timeDD3, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); lv_obj_set_style_local_text_color(timeDD3, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_label_set_text_static(timeDD3, ":00"); lv_label_set_text_static(timeDD3, ":00");
lv_obj_align(timeDD3, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_align(timeDD3, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_obj_set_hidden(timeDD3, true); if (settingsController.GetPTSGaugeStyle() == Pinetime::Controllers::Settings::PTSGaugeStyle::Half) {
lv_obj_set_hidden(timeDD3, false);
} else {
lv_obj_set_hidden(timeDD3, true);
}
btnNextTime = lv_btn_create(lv_scr_act(), nullptr); btnNextTime = lv_btn_create(lv_scr_act(), nullptr);
btnNextTime->user_data = this; btnNextTime->user_data = this;
@ -611,12 +633,14 @@ void WatchFacePineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event)
lv_gauge_set_scale(stepGauge, 180, 5, 0); lv_gauge_set_scale(stepGauge, 180, 5, 0);
lv_gauge_set_angle_offset(stepGauge, 0); lv_gauge_set_angle_offset(stepGauge, 0);
lv_gauge_set_critical_value(stepGauge, 120); lv_gauge_set_critical_value(stepGauge, 120);
settingsController.SetPTSGaugeStyle(Controllers::Settings::PTSGaugeStyle::Half);
} else if (!lv_obj_get_hidden(timeDD3) && (lv_obj_get_hidden(stepValue))) { } else if (!lv_obj_get_hidden(timeDD3) && (lv_obj_get_hidden(stepValue))) {
// show step count & icon // show step count & icon
lv_obj_set_hidden(timeDD3, true); lv_obj_set_hidden(timeDD3, true);
lv_obj_set_hidden(stepGauge, true); lv_obj_set_hidden(stepGauge, true);
lv_obj_set_hidden(stepValue, false); lv_obj_set_hidden(stepValue, false);
lv_obj_set_hidden(stepIcon, false); lv_obj_set_hidden(stepIcon, false);
settingsController.SetPTSGaugeStyle(Controllers::Settings::PTSGaugeStyle::Numeric);
} else { } else {
// show full gauge // show full gauge
lv_obj_set_hidden(stepGauge, false); lv_obj_set_hidden(stepGauge, false);
@ -627,6 +651,7 @@ void WatchFacePineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event)
lv_gauge_set_scale(stepGauge, 360, 11, 0); lv_gauge_set_scale(stepGauge, 360, 11, 0);
lv_gauge_set_angle_offset(stepGauge, 180); lv_gauge_set_angle_offset(stepGauge, 180);
lv_gauge_set_critical_value(stepGauge, 100); lv_gauge_set_critical_value(stepGauge, 100);
settingsController.SetPTSGaugeStyle(Controllers::Settings::PTSGaugeStyle::Full);
} }
} }
if (object == btnSetColor) { if (object == btnSetColor) {