diff --git a/src/displayapp/screens/BatteryInfo.cpp b/src/displayapp/screens/BatteryInfo.cpp index 16845d53e7..8ce3090370 100644 --- a/src/displayapp/screens/BatteryInfo.cpp +++ b/src/displayapp/screens/BatteryInfo.cpp @@ -7,16 +7,12 @@ using namespace Pinetime::Applications::Screens; BatteryInfo::BatteryInfo(const Pinetime::Controllers::Battery& batteryController) : batteryController {batteryController} { - batteryPercent = batteryController.PercentRemaining(); - batteryVoltage = batteryController.Voltage(); - chargingArc = lv_arc_create(lv_scr_act(), nullptr); lv_arc_set_rotation(chargingArc, 270); lv_arc_set_bg_angles(chargingArc, 0, 360); lv_arc_set_adjustable(chargingArc, false); lv_obj_set_size(chargingArc, 180, 180); lv_obj_align(chargingArc, nullptr, LV_ALIGN_CENTER, 0, -30); - lv_arc_set_value(chargingArc, batteryPercent); lv_obj_set_style_local_bg_opa(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, Colors::bgAlt); lv_obj_set_style_local_border_width(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 2); @@ -24,24 +20,24 @@ BatteryInfo::BatteryInfo(const Pinetime::Controllers::Battery& batteryController lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME); status = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(status, "Reading Battery status"); lv_label_set_align(status, LV_LABEL_ALIGN_CENTER); - lv_obj_align(status, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -17); + lv_obj_align(status, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -33); + lv_obj_set_auto_realign(status, true); percent = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_label_set_text_fmt(percent, "%i%%", batteryPercent); lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT); lv_obj_align(percent, chargingArc, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_auto_realign(percent, true); voltage = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(voltage, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange); - lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10); lv_label_set_align(voltage, LV_LABEL_ALIGN_CENTER); lv_obj_align(voltage, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -7); + lv_obj_set_auto_realign(voltage, true); - taskRefresh = lv_task_create(RefreshTaskCallback, 5000, LV_TASK_PRIO_MID, this); Refresh(); + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } BatteryInfo::~BatteryInfo() { @@ -53,28 +49,32 @@ void BatteryInfo::Refresh() { batteryPercent = batteryController.PercentRemaining(); batteryVoltage = batteryController.Voltage(); + batteryCharging = batteryController.IsCharging(); - if (batteryController.IsCharging()) { - lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME); - lv_label_set_text_static(status, "Charging"); - } else if (batteryPercent == 100) { - lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE); - lv_label_set_text_static(status, "Fully charged"); - } else if (batteryPercent > 15) { - lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN); - lv_label_set_text_static(status, "Discharging"); - } else if (batteryPercent > 5) { - lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(status, "Battery low"); - } else { - lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, Colors::deepOrange); - lv_label_set_text_static(status, "Battery critical"); + if (batteryPercent.IsUpdated() || batteryCharging.IsUpdated()) { + uint8_t battPercent = batteryPercent.Get(); + if (batteryCharging.Get()) { + lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME); + lv_label_set_text_static(status, "Charging"); + } else if (battPercent == 100) { + lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE); + lv_label_set_text_static(status, "Fully charged"); + } else if (battPercent > 15) { + lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN); + lv_label_set_text_static(status, "Discharging"); + } else if (battPercent > 5) { + lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text_static(status, "Battery low"); + } else { + lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, Colors::deepOrange); + lv_label_set_text_static(status, "Battery critical"); + } + lv_label_set_text_fmt(percent, "%i%%", battPercent); + lv_arc_set_value(chargingArc, battPercent); } - lv_label_set_text_fmt(percent, "%i%%", batteryPercent); - lv_obj_align(percent, chargingArc, LV_ALIGN_CENTER, 0, 0); - - lv_obj_align(status, voltage, LV_ALIGN_IN_BOTTOM_MID, 0, -27); - lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10); - lv_arc_set_value(chargingArc, batteryPercent); + if (batteryVoltage.IsUpdated()) { + uint16_t battVolts = batteryVoltage.Get(); + lv_label_set_text_fmt(voltage, "%1i.%02i volts", battVolts / 1000, battVolts % 1000 / 10); + } } diff --git a/src/displayapp/screens/BatteryInfo.h b/src/displayapp/screens/BatteryInfo.h index 27bbaa00c0..a58cfc33b9 100644 --- a/src/displayapp/screens/BatteryInfo.h +++ b/src/displayapp/screens/BatteryInfo.h @@ -3,6 +3,7 @@ #include #include "displayapp/screens/Screen.h" #include +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -29,8 +30,9 @@ namespace Pinetime { lv_task_t* taskRefresh; - uint8_t batteryPercent = 0; - uint16_t batteryVoltage = 0; + Utility::DirtyValue batteryPercent {}; + Utility::DirtyValue batteryVoltage {}; + Utility::DirtyValue batteryCharging {}; }; } } diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index 2e73dab512..6d0e1cde39 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -7,10 +7,6 @@ using namespace Pinetime::Applications::Screens; using Days = Pinetime::Controllers::MotionController::Days; -namespace { - constexpr const char* yesterdayStr = "Yest: %5lu"; -} - static void lap_event_handler(lv_obj_t* obj, lv_event_t event) { auto* steps = static_cast(obj->user_data); steps->lapBtnEventHandler(event); @@ -31,16 +27,11 @@ Steps::Steps(Controllers::MotionController& motionController, Controllers::Setti lv_arc_set_range(stepsArc, 0, 500); lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, 0); - stepsCount = motionController.NbSteps(); - currentTripSteps = stepsCount - motionController.GetTripSteps(); - - lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal())); - lSteps = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME); lv_obj_set_style_local_text_font(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_label_set_text_fmt(lSteps, "%lu", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); + lv_obj_set_auto_realign(lSteps, true); lv_obj_t* lstepsL = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lstepsL, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); @@ -49,15 +40,15 @@ Steps::Steps(Controllers::MotionController& motionController, Controllers::Setti lStepsYesterday = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lStepsYesterday, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); - lv_label_set_text_fmt(lStepsYesterday, yesterdayStr, motionController.NbSteps(Days::Yesterday)); lv_label_set_align(lStepsYesterday, LV_LABEL_ALIGN_CENTER); lv_obj_align(lStepsYesterday, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); + lv_obj_set_auto_realign(lStepsYesterday, true); - lv_obj_t* lstepsGoal = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(lstepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); - lv_label_set_text_fmt(lstepsGoal, "Goal: %5lu", settingsController.GetStepsGoal()); - lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 40); + lStepsGoal = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(lStepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); + lv_label_set_align(lStepsGoal, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lStepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 40); + lv_obj_set_auto_realign(lStepsGoal, true); resetBtn = lv_btn_create(lv_scr_act(), nullptr); resetBtn->user_data = this; @@ -69,14 +60,13 @@ Steps::Steps(Controllers::MotionController& motionController, Controllers::Setti resetButtonLabel = lv_label_create(resetBtn, nullptr); lv_label_set_text_static(resetButtonLabel, "Reset"); - currentTripSteps = motionController.GetTripSteps(); - tripLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(tripLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps); - lv_obj_align(tripLabel, lstepsGoal, LV_ALIGN_IN_LEFT_MID, 0, 20); + lv_obj_align(tripLabel, lStepsGoal, LV_ALIGN_IN_LEFT_MID, 0, 20); + lv_obj_set_auto_realign(tripLabel, true); - taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); + Refresh(); + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } Steps::~Steps() { @@ -87,26 +77,28 @@ Steps::~Steps() { void Steps::Refresh() { stepsCount = motionController.NbSteps(); currentTripSteps = motionController.GetTripSteps(); + stepsGoal = settingsController.GetStepsGoal(); - lv_label_set_text_fmt(lSteps, "%lu", stepsCount); - lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); - - lv_label_set_text_fmt(lStepsYesterday, yesterdayStr, motionController.NbSteps(Days::Yesterday)); - lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); + if (stepsCount.IsUpdated() || stepsGoal.IsUpdated()) { + lv_label_set_text_fmt(lSteps, "%lu", stepsCount.Get()); + lv_label_set_text_fmt(lStepsGoal, "Goal: %5lu", stepsGoal.Get()); + lv_label_set_text_fmt(lStepsYesterday, "Yest: %5lu", motionController.NbSteps(Days::Yesterday)); + lv_arc_set_value(stepsArc, int16_t(500 * stepsCount.Get() / stepsGoal.Get())); + } - if (currentTripSteps < 100000) { - lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps); - } else { - lv_label_set_text_fmt(tripLabel, "Trip: 99999+"); + if (currentTripSteps.IsUpdated()) { + if (currentTripSteps.Get() < 100000) { + lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps.Get()); + } else { + lv_label_set_text_fmt(tripLabel, "Trip: 99999+"); + } } - lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal())); } void Steps::lapBtnEventHandler(lv_event_t event) { if (event != LV_EVENT_CLICKED) { return; } - stepsCount = motionController.NbSteps(); motionController.ResetTrip(); Refresh(); } diff --git a/src/displayapp/screens/Steps.h b/src/displayapp/screens/Steps.h index 4824be6aad..5e8648452d 100644 --- a/src/displayapp/screens/Steps.h +++ b/src/displayapp/screens/Steps.h @@ -7,6 +7,7 @@ #include "displayapp/apps/Apps.h" #include "displayapp/Controllers.h" #include "Symbols.h" +#include "utility/DirtyValue.h" namespace Pinetime { @@ -29,17 +30,18 @@ namespace Pinetime { Controllers::MotionController& motionController; Controllers::Settings& settingsController; - uint32_t currentTripSteps = 0; + Utility::DirtyValue currentTripSteps {}; + Utility::DirtyValue stepsCount {}; + Utility::DirtyValue stepsGoal {}; lv_obj_t* lSteps; lv_obj_t* lStepsYesterday; + lv_obj_t* lStepsGoal; lv_obj_t* stepsArc; lv_obj_t* resetBtn; lv_obj_t* resetButtonLabel; lv_obj_t* tripLabel; - uint32_t stepsCount; - lv_task_t* taskRefresh; }; } diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index 45f715b55a..8d9890c501 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -6,11 +6,6 @@ using namespace Pinetime::Applications::Screens; namespace { - void lv_update_task(struct _lv_task_t* task) { - auto* user_data = static_cast(task->user_data); - user_data->UpdateScreen(); - } - void event_handler(lv_obj_t* obj, lv_event_t event) { if (event != LV_EVENT_VALUE_CHANGED) { return; @@ -86,19 +81,21 @@ Tile::Tile(uint8_t screenID, btnm1->user_data = this; lv_obj_set_event_cb(btnm1, event_handler); - taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this); - - UpdateScreen(); + Refresh(); + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } Tile::~Tile() { - lv_task_del(taskUpdate); + lv_task_del(taskRefresh); lv_obj_clean(lv_scr_act()); } -void Tile::UpdateScreen() { - lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); +void Tile::Refresh() { statusIcons.Update(); + currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); + if (currentDateTime.IsUpdated()) { + lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); + } } void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) { diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h index c16151d0e1..ed0a4036b6 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -10,6 +10,7 @@ #include "components/battery/BatteryController.h" #include "displayapp/widgets/PageIndicator.h" #include "displayapp/widgets/StatusIcons.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Applications { @@ -34,14 +35,15 @@ namespace Pinetime { ~Tile() override; - void UpdateScreen(); + void Refresh() override; void OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId); private: DisplayApp* app; + Utility::DirtyValue> currentDateTime {}; Controllers::DateTime& dateTimeController; - lv_task_t* taskUpdate; + lv_task_t* taskRefresh; lv_obj_t* label_time; lv_obj_t* btnm1; diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index c5c3071aef..d473240fce 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -15,11 +15,6 @@ namespace { } } - void lv_update_task(struct _lv_task_t* task) { - auto* user_data = static_cast(task->user_data); - user_data->UpdateScreen(); - } - enum class ButtonState : lv_state_t { NotificationsOn = LV_STATE_CHECKED, NotificationsOff = LV_STATE_DEFAULT, @@ -119,21 +114,23 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); lv_label_set_text_static(lbl_btn, Symbols::settings); - taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this); - - UpdateScreen(); + Refresh(); + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } QuickSettings::~QuickSettings() { lv_style_reset(&btn_style); - lv_task_del(taskUpdate); + lv_task_del(taskRefresh); lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } -void QuickSettings::UpdateScreen() { - lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); +void QuickSettings::Refresh() { statusIcons.Update(); + currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); + if (currentDateTime.IsUpdated()) { + lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); + } } void QuickSettings::OnButtonEvent(lv_obj_t* object) { diff --git a/src/displayapp/screens/settings/QuickSettings.h b/src/displayapp/screens/settings/QuickSettings.h index 87c126b7fa..ac514130dd 100644 --- a/src/displayapp/screens/settings/QuickSettings.h +++ b/src/displayapp/screens/settings/QuickSettings.h @@ -9,6 +9,7 @@ #include "components/settings/Settings.h" #include "components/battery/BatteryController.h" #include "displayapp/widgets/StatusIcons.h" +#include "utility/DirtyValue.h" namespace Pinetime { @@ -30,16 +31,19 @@ namespace Pinetime { void OnButtonEvent(lv_obj_t* object); - void UpdateScreen(); + void Refresh() override; private: DisplayApp* app; + + Utility::DirtyValue> currentDateTime {}; + Controllers::DateTime& dateTimeController; Controllers::BrightnessController& brightness; Controllers::MotorController& motorController; Controllers::Settings& settingsController; - lv_task_t* taskUpdate; + lv_task_t* taskRefresh; lv_obj_t* label_time; lv_style_t btn_style;