diff options
Diffstat (limited to 'src/displayapp/screens')
| -rw-r--r-- | src/displayapp/screens/BatteryIcon.cpp | 31 | ||||
| -rw-r--r-- | src/displayapp/screens/BatteryIcon.h | 16 | ||||
| -rw-r--r-- | src/displayapp/screens/Brightness.cpp | 103 | ||||
| -rw-r--r-- | src/displayapp/screens/Brightness.h | 33 | ||||
| -rw-r--r-- | src/displayapp/screens/Meter.cpp | 36 | ||||
| -rw-r--r-- | src/displayapp/screens/Meter.h | 29 | ||||
| -rw-r--r-- | src/displayapp/screens/Tile.cpp | 10 | ||||
| -rw-r--r-- | src/displayapp/screens/Tile.h | 4 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog.cpp | 27 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog.h | 5 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog24.cpp | 26 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog24.h | 5 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.cpp | 17 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.h | 4 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFacePineTimeStyle.cpp | 20 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFacePineTimeStyle.h | 5 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/QuickSettings.cpp | 10 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/QuickSettings.h | 4 |
18 files changed, 109 insertions, 276 deletions
diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 08aaab7..4c8c2b2 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -1,23 +1,30 @@ #include "displayapp/screens/BatteryIcon.h" #include <cstdint> #include "displayapp/screens/Symbols.h" +#include "displayapp/icons/battery/batteryicon.c" using namespace Pinetime::Applications::Screens; -const char* BatteryIcon::GetBatteryIcon(uint8_t batteryPercent) { - if (batteryPercent > 87) - return Symbols::batteryFull; - if (batteryPercent > 62) - return Symbols::batteryThreeQuarter; - if (batteryPercent > 37) - return Symbols::batteryHalf; - if (batteryPercent > 12) - return Symbols::batteryOneQuarter; - return Symbols::batteryEmpty; +void BatteryIcon::Create(lv_obj_t* parent) { + batteryImg = lv_img_create(parent, nullptr); + lv_img_set_src(batteryImg, &batteryicon); + lv_obj_set_style_local_image_recolor(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + + batteryJuice = lv_obj_create(batteryImg, nullptr); + lv_obj_set_width(batteryJuice, 8); + lv_obj_align(batteryJuice, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -2, -2); + lv_obj_set_style_local_radius(batteryJuice, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 0); +} + +void BatteryIcon::SetBatteryPercentage(uint8_t percentage) { + lv_obj_set_height(batteryJuice, percentage * 14 / 100); + lv_obj_realign(batteryJuice); } -const char* BatteryIcon::GetUnknownIcon() { - return Symbols::batteryEmpty; +void BatteryIcon::SetColor(lv_color_t color) { + lv_obj_set_style_local_image_recolor(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, color); + lv_obj_set_style_local_image_recolor_opa(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER); + lv_obj_set_style_local_bg_color(batteryJuice, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color); } const char* BatteryIcon::GetPlugIcon(bool isCharging) { diff --git a/src/displayapp/screens/BatteryIcon.h b/src/displayapp/screens/BatteryIcon.h index bec2e4e..2f76466 100644 --- a/src/displayapp/screens/BatteryIcon.h +++ b/src/displayapp/screens/BatteryIcon.h @@ -1,15 +1,27 @@ #pragma once #include <cstdint> +#include <lvgl/src/lv_core/lv_obj.h> namespace Pinetime { namespace Applications { namespace Screens { class BatteryIcon { public: + void Create(lv_obj_t* parent); + + void SetColor(lv_color_t); + void SetBatteryPercentage(uint8_t percentage); + inline lv_obj_t* GetObject() { + return batteryImg; + } + static const char* GetUnknownIcon(); - static const char* GetBatteryIcon(uint8_t batteryPercent); static const char* GetPlugIcon(bool isCharging); + + private: + lv_obj_t* batteryImg; + lv_obj_t* batteryJuice; }; } } -}
\ No newline at end of file +} diff --git a/src/displayapp/screens/Brightness.cpp b/src/displayapp/screens/Brightness.cpp deleted file mode 100644 index d9901ae..0000000 --- a/src/displayapp/screens/Brightness.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "displayapp/screens/Brightness.h" -#include <lvgl/lvgl.h> - -using namespace Pinetime::Applications::Screens; - -void slider_event_cb(lv_obj_t* slider, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - auto* brightnessSlider = static_cast<Brightness*>(slider->user_data); - brightnessSlider->OnValueChanged(); - } -} - -Brightness::Brightness(Pinetime::Applications::DisplayApp* app, Controllers::BrightnessController& brightness) - : Screen(app), brightness {brightness} { - slider = lv_slider_create(lv_scr_act(), nullptr); - lv_obj_set_user_data(slider, this); - lv_obj_set_width(slider, LV_DPI * 2); - lv_obj_align(slider, nullptr, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_event_cb(slider, slider_event_cb); - lv_slider_set_range(slider, 0, 2); - lv_slider_set_value(slider, LevelToInt(brightness.Level()), LV_ANIM_OFF); - - slider_label = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text(slider_label, LevelToString(brightness.Level())); - lv_obj_set_auto_realign(slider_label, true); - lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 30); -} - -Brightness::~Brightness() { - lv_obj_clean(lv_scr_act()); -} - -const char* Brightness::LevelToString(Pinetime::Controllers::BrightnessController::Levels level) { - switch (level) { - case Pinetime::Controllers::BrightnessController::Levels::Off: - return "Off"; - case Pinetime::Controllers::BrightnessController::Levels::Low: - return "Low"; - case Pinetime::Controllers::BrightnessController::Levels::Medium: - return "Medium"; - case Pinetime::Controllers::BrightnessController::Levels::High: - return "High"; - default: - return "???"; - } -} - -void Brightness::OnValueChanged() { - SetValue(lv_slider_get_value(slider)); -} - -void Brightness::SetValue(uint8_t value) { - switch (value) { - case 0: - brightness.Set(Controllers::BrightnessController::Levels::Low); - break; - case 1: - brightness.Set(Controllers::BrightnessController::Levels::Medium); - break; - case 2: - brightness.Set(Controllers::BrightnessController::Levels::High); - break; - } - lv_label_set_text(slider_label, LevelToString(brightness.Level())); -} - -uint8_t Brightness::LevelToInt(Pinetime::Controllers::BrightnessController::Levels level) { - switch (level) { - case Pinetime::Controllers::BrightnessController::Levels::Off: - return 0; - case Pinetime::Controllers::BrightnessController::Levels::Low: - return 0; - case Pinetime::Controllers::BrightnessController::Levels::Medium: - return 1; - case Pinetime::Controllers::BrightnessController::Levels::High: - return 2; - default: - return 0; - } -} - -bool Brightness::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - switch (event) { - case TouchEvents::SwipeLeft: - brightness.Lower(); - if (brightness.Level() == Pinetime::Controllers::BrightnessController::Levels::Off) { - brightness.Set(Controllers::BrightnessController::Levels::Low); - } - SetValue(); - return true; - case TouchEvents::SwipeRight: - brightness.Higher(); - SetValue(); - return true; - default: - return false; - } -} - -void Brightness::SetValue() { - lv_slider_set_value(slider, LevelToInt(brightness.Level()), LV_ANIM_OFF); - lv_label_set_text(slider_label, LevelToString(brightness.Level())); -} diff --git a/src/displayapp/screens/Brightness.h b/src/displayapp/screens/Brightness.h deleted file mode 100644 index 693570c..0000000 --- a/src/displayapp/screens/Brightness.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include <lvgl/src/lv_core/lv_obj.h> -#include <cstdint> -#include "displayapp/screens/Screen.h" -#include "components/brightness/BrightnessController.h" - -namespace Pinetime { - namespace Applications { - namespace Screens { - class Brightness : public Screen { - public: - Brightness(DisplayApp* app, Controllers::BrightnessController& brightness); - ~Brightness() override; - - bool OnTouchEvent(TouchEvents event) override; - - void OnValueChanged(); - - private: - Controllers::BrightnessController& brightness; - - lv_obj_t* slider_label; - lv_obj_t* slider; - - const char* LevelToString(Controllers::BrightnessController::Levels level); - uint8_t LevelToInt(Controllers::BrightnessController::Levels level); - void SetValue(uint8_t value); - void SetValue(); - }; - } - } -} diff --git a/src/displayapp/screens/Meter.cpp b/src/displayapp/screens/Meter.cpp deleted file mode 100644 index 9c85310..0000000 --- a/src/displayapp/screens/Meter.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "displayapp/screens/Meter.h" -#include <lvgl/lvgl.h> -#include "displayapp/DisplayApp.h" - -using namespace Pinetime::Applications::Screens; - -Meter::Meter(Pinetime::Applications::DisplayApp* app) : Screen(app) { - - /*Create a line meter */ - lmeter = lv_linemeter_create(lv_scr_act(), nullptr); - lv_linemeter_set_range(lmeter, 0, 60); /*Set the range*/ - lv_linemeter_set_value(lmeter, value); /*Set the current value*/ - lv_linemeter_set_angle_offset(lmeter, 180); - lv_linemeter_set_scale(lmeter, 360, 60); /*Set the angle and number of lines*/ - - lv_obj_set_style_local_scale_end_color(lmeter, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(255, 0, 0)); - lv_obj_set_style_local_scale_grad_color(lmeter, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(160, 0, 0)); - lv_obj_set_style_local_line_width(lmeter, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, 2); - lv_obj_set_style_local_line_color(lmeter, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_SILVER); - - lv_obj_set_size(lmeter, 200, 200); - lv_obj_align(lmeter, nullptr, LV_ALIGN_CENTER, 0, 0); - - taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); -} - -Meter::~Meter() { - lv_task_del(taskRefresh); - lv_obj_clean(lv_scr_act()); -} - -void Meter::Refresh() { - lv_linemeter_set_value(lmeter, value++); /*Set the current value*/ - if (value >= 60) - value = 0; -} diff --git a/src/displayapp/screens/Meter.h b/src/displayapp/screens/Meter.h deleted file mode 100644 index 50d9f83..0000000 --- a/src/displayapp/screens/Meter.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include <cstdint> -#include "displayapp/screens/Screen.h" -#include <lvgl/src/lv_core/lv_style.h> -#include <lvgl/src/lv_core/lv_obj.h> - -namespace Pinetime { - namespace Applications { - namespace Screens { - - class Meter : public Screen { - public: - Meter(DisplayApp* app); - ~Meter() override; - - void Refresh() override; - - private: - lv_style_t style_lmeter; - lv_obj_t* lmeter; - - uint32_t value = 0; - - lv_task_t* taskRefresh; - }; - } - } -} diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index c63b5ac..3cb811a 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -33,14 +33,12 @@ Tile::Tile(uint8_t screenID, // Time label_time = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER); lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); // Battery - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining())); - lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0); + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0); if (numScreens > 1) { pageIndicatorBasePoints[0].x = LV_HOR_RES - 1; @@ -111,6 +109,8 @@ Tile::Tile(uint8_t screenID, lv_label_set_text_static(backgroundLabel, ""); taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this); + + UpdateScreen(); } Tile::~Tile() { @@ -120,7 +120,7 @@ Tile::~Tile() { void Tile::UpdateScreen() { lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining())); + batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining()); } 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 1d4b7b6..ae85dea 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -9,6 +9,7 @@ #include "components/settings/Settings.h" #include "components/datetime/DateTimeController.h" #include "components/battery/BatteryController.h" +#include <displayapp/screens/BatteryIcon.h> namespace Pinetime { namespace Applications { @@ -40,13 +41,14 @@ namespace Pinetime { lv_task_t* taskUpdate; lv_obj_t* label_time; - lv_obj_t* batteryIcon; lv_point_t pageIndicatorBasePoints[2]; lv_point_t pageIndicatorPoints[2]; lv_obj_t* pageIndicatorBase; lv_obj_t* pageIndicator; lv_obj_t* btnm1; + BatteryIcon batteryIcon; + const char* btnmMap[8]; Pinetime::Applications::Apps apps[6]; }; diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index 4cfc969..c1df675 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -66,10 +66,13 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, lv_img_set_src(bg_clock_img, &bg_clock); lv_obj_align(bg_clock_img, NULL, LV_ALIGN_CENTER, 0, 0); - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(batteryIcon, Symbols::batteryHalf); - lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - lv_obj_set_auto_realign(batteryIcon, true); + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + + plugIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(plugIcon, Symbols::plug); + lv_obj_set_style_local_text_color(plugIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_obj_align(plugIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); notificationIcon = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); @@ -121,7 +124,8 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); - UpdateClock(); + + Refresh(); } WatchFaceAnalog::~WatchFaceAnalog() { @@ -180,21 +184,18 @@ void WatchFaceAnalog::UpdateClock() { void WatchFaceAnalog::SetBatteryIcon() { auto batteryPercent = batteryPercentRemaining.Get(); - if (batteryPercent == 100) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); - } else { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - } - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + batteryIcon.SetBatteryPercentage(batteryPercent); } void WatchFaceAnalog::Refresh() { isCharging = batteryController.IsCharging(); if (isCharging.IsUpdated()) { if (isCharging.Get()) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - lv_label_set_text_static(batteryIcon, Symbols::plug); + lv_obj_set_hidden(batteryIcon.GetObject(), true); + lv_obj_set_hidden(plugIcon, false); } else { + lv_obj_set_hidden(batteryIcon.GetObject(), false); + lv_obj_set_hidden(plugIcon, true); SetBatteryIcon(); } } diff --git a/src/displayapp/screens/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h index 4d76298..04d9e71 100644 --- a/src/displayapp/screens/WatchFaceAnalog.h +++ b/src/displayapp/screens/WatchFaceAnalog.h @@ -9,6 +9,7 @@ #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/ble/NotificationManager.h" +#include <displayapp/screens/BatteryIcon.h> namespace Pinetime { namespace Controllers { @@ -64,9 +65,11 @@ namespace Pinetime { lv_style_t second_line_style; lv_obj_t* label_date_day; - lv_obj_t* batteryIcon; + lv_obj_t* plugIcon; lv_obj_t* notificationIcon; + BatteryIcon batteryIcon; + const Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; diff --git a/src/displayapp/screens/WatchFaceAnalog24.cpp b/src/displayapp/screens/WatchFaceAnalog24.cpp index 5e37e7b..500243e 100644 --- a/src/displayapp/screens/WatchFaceAnalog24.cpp +++ b/src/displayapp/screens/WatchFaceAnalog24.cpp @@ -70,15 +70,18 @@ WatchFaceAnalog24::WatchFaceAnalog24(Pinetime::Applications::DisplayApp* app, lv_img_set_src(bg_clock_img, &bg_analog24); lv_obj_align(bg_clock_img, nullptr, LV_ALIGN_CENTER, 0, 0); - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text(batteryIcon, Symbols::batteryHalf); - lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - lv_obj_set_auto_realign(batteryIcon, true); + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + + plugIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(plugIcon, Symbols::plug); + lv_obj_set_style_local_text_color(plugIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_obj_align(plugIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); bleIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x0082FC)); lv_label_set_text_static(bleIcon, Symbols::bluetooth); - lv_obj_align(bleIcon, batteryIcon, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); + lv_obj_align(bleIcon, plugIcon, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); lv_obj_set_auto_realign(bleIcon, true); notificationIcon = lv_label_create(lv_scr_act(), NULL); @@ -180,21 +183,18 @@ void WatchFaceAnalog24::UpdateClock() { void WatchFaceAnalog24::SetBatteryIcon() { auto batteryPercent = batteryPercentRemaining.Get(); - if (batteryPercent == 100) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); - } else { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - } - lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + batteryIcon.SetBatteryPercentage(batteryPercent); } void WatchFaceAnalog24::Refresh() { isCharging = batteryController.IsCharging(); if (isCharging.IsUpdated()) { if (isCharging.Get()) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - lv_label_set_text(batteryIcon, Symbols::plug); + lv_obj_set_hidden(batteryIcon.GetObject(), true); + lv_obj_set_hidden(plugIcon, false); } else { + lv_obj_set_hidden(batteryIcon.GetObject(), false); + lv_obj_set_hidden(plugIcon, true); SetBatteryIcon(); } } diff --git a/src/displayapp/screens/WatchFaceAnalog24.h b/src/displayapp/screens/WatchFaceAnalog24.h index 5df8979..033519a 100644 --- a/src/displayapp/screens/WatchFaceAnalog24.h +++ b/src/displayapp/screens/WatchFaceAnalog24.h @@ -11,6 +11,7 @@ #include "components/ble/NotificationManager.h" #include "components/heartrate/HeartRateController.h" #include "components/motion/MotionController.h" +#include <displayapp/screens/BatteryIcon.h> namespace Pinetime { namespace Controllers { @@ -65,7 +66,7 @@ namespace Pinetime { lv_style_t hour_line_style_trace; // lv_obj_t* label_date_day; - lv_obj_t* batteryIcon; + lv_obj_t* plugIcon; lv_obj_t* bleIcon; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; @@ -73,6 +74,8 @@ namespace Pinetime { lv_obj_t* stepValue; lv_obj_t* notificationIcon; + BatteryIcon batteryIcon; + Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 98e1199..46a0d81 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -36,20 +36,19 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, heartRateController {heartRateController}, motionController {motionController} { - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(batteryIcon, Symbols::batteryFull); - lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); batteryPlug = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFF0000)); lv_label_set_text_static(batteryPlug, Symbols::plug); - lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, 0, 0); + lv_obj_align(batteryPlug, batteryIcon.GetObject(), LV_ALIGN_OUT_LEFT_MID, 0, 0); batteryPercentLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color( batteryPercentLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); lv_obj_set_style_local_text_font( batteryPercentLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); lv_label_set_text_static( batteryPercentLabel, battery_percent_label_text); - lv_obj_align( batteryPercentLabel, batteryIcon, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); + lv_obj_align( batteryPercentLabel, batteryIcon.GetObject(), LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); lv_label_set_align( batteryPercentLabel, LV_LABEL_ALIGN_RIGHT); batteryVoltageLabel = lv_label_create(lv_scr_act(), nullptr); @@ -273,19 +272,13 @@ void WatchFaceDigital::Refresh() { if (batteryPercentRemaining.IsUpdated()) { batteryRefreshed = true; auto batteryPercent = batteryPercentRemaining.Get(); - if (batteryPercent == 100) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); - } else { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - } - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + batteryIcon.SetBatteryPercentage(batteryPercent); } bleState = bleController.IsConnected(); if (bleState.IsUpdated()) { lv_label_set_text_static(bleIcon, BleIcon::GetIcon(bleState.Get())); } - lv_obj_realign(batteryIcon); lv_obj_realign(batteryPlug); lv_obj_realign(bleIcon); diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 09dae6e..eac21b0 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -1,5 +1,6 @@ #pragma once +#include <displayapp/screens/BatteryIcon.h> #include <lvgl/src/lv_core/lv_obj.h> #include <chrono> #include <cstdint> @@ -84,7 +85,6 @@ namespace Pinetime { lv_obj_t* label_time_deciseconds; lv_obj_t* label_date; lv_obj_t* backgroundLabel; - lv_obj_t* batteryIcon; lv_obj_t* bleIcon; lv_obj_t* batteryPlug; lv_obj_t* heartbeatIcon; @@ -96,6 +96,8 @@ namespace Pinetime { lv_obj_t* batteryVoltageLabel; lv_obj_t* memfragLabel; + BatteryIcon batteryIcon; + Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; diff --git a/src/displayapp/screens/WatchFacePineTimeStyle.cpp b/src/displayapp/screens/WatchFacePineTimeStyle.cpp index dde07e8..b9afcc8 100644 --- a/src/displayapp/screens/WatchFacePineTimeStyle.cpp +++ b/src/displayapp/screens/WatchFacePineTimeStyle.cpp @@ -101,11 +101,14 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(DisplayApp* app, lv_obj_align(sidebar, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); // Display icons - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); - lv_label_set_text_static(batteryIcon, Symbols::batteryFull); - lv_obj_align(batteryIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2); - lv_obj_set_auto_realign(batteryIcon, true); + batteryIcon.Create(sidebar); + batteryIcon.SetColor(LV_COLOR_BLACK); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_MID, 0, 2); + + plugIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(plugIcon, Symbols::plug); + lv_obj_set_style_local_text_color(plugIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_align(plugIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2); bleIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); @@ -340,7 +343,7 @@ bool WatchFacePineTimeStyle::OnButtonPushed() { void WatchFacePineTimeStyle::SetBatteryIcon() { auto batteryPercent = batteryPercentRemaining.Get(); - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + batteryIcon.SetBatteryPercentage(batteryPercent); } void WatchFacePineTimeStyle::AlignIcons() { @@ -358,8 +361,11 @@ void WatchFacePineTimeStyle::Refresh() { isCharging = batteryController.IsCharging(); if (isCharging.IsUpdated()) { if (isCharging.Get()) { - lv_label_set_text_static(batteryIcon, Symbols::plug); + lv_obj_set_hidden(batteryIcon.GetObject(), true); + lv_obj_set_hidden(plugIcon, false); } else { + lv_obj_set_hidden(batteryIcon.GetObject(), false); + lv_obj_set_hidden(plugIcon, true); SetBatteryIcon(); } } diff --git a/src/displayapp/screens/WatchFacePineTimeStyle.h b/src/displayapp/screens/WatchFacePineTimeStyle.h index 465aa70..e703d89 100644 --- a/src/displayapp/screens/WatchFacePineTimeStyle.h +++ b/src/displayapp/screens/WatchFacePineTimeStyle.h @@ -8,6 +8,7 @@ #include "displayapp/Colors.h" #include "components/datetime/DateTimeController.h" #include "components/ble/BleController.h" +#include <displayapp/screens/BatteryIcon.h> namespace Pinetime { namespace Controllers { @@ -79,7 +80,7 @@ namespace Pinetime { lv_obj_t* dateDay; lv_obj_t* dateMonth; lv_obj_t* backgroundLabel; - lv_obj_t* batteryIcon; + lv_obj_t* plugIcon; lv_obj_t* bleIcon; lv_obj_t* calendarOuter; lv_obj_t* calendarInner; @@ -93,6 +94,8 @@ namespace Pinetime { lv_obj_t* lbl_btnSet; lv_color_t needle_colors[1]; + BatteryIcon batteryIcon; + Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index 46f2f02..be5509f 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -35,13 +35,11 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, // Time label_time = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0); - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining())); - lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); static constexpr uint8_t barHeight = 20 + innerDistance; static constexpr uint8_t buttonHeight = (LV_VER_RES_MAX - barHeight - innerDistance) / 2; @@ -113,6 +111,8 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, lv_label_set_text_static(backgroundLabel, ""); taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this); + + UpdateScreen(); } QuickSettings::~QuickSettings() { @@ -124,7 +124,7 @@ QuickSettings::~QuickSettings() { void QuickSettings::UpdateScreen() { lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining())); + batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining()); } void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { diff --git a/src/displayapp/screens/settings/QuickSettings.h b/src/displayapp/screens/settings/QuickSettings.h index 7913898..40a2a2e 100644 --- a/src/displayapp/screens/settings/QuickSettings.h +++ b/src/displayapp/screens/settings/QuickSettings.h @@ -8,6 +8,7 @@ #include "components/motor/MotorController.h" #include "components/settings/Settings.h" #include "components/battery/BatteryController.h" +#include <displayapp/screens/BatteryIcon.h> namespace Pinetime { @@ -37,7 +38,6 @@ namespace Pinetime { Controllers::Settings& settingsController; lv_task_t* taskUpdate; - lv_obj_t* batteryIcon; lv_obj_t* label_time; lv_style_t btn_style; @@ -48,6 +48,8 @@ namespace Pinetime { lv_obj_t* btn3; lv_obj_t* btn3_lvl; lv_obj_t* btn4; + + BatteryIcon batteryIcon; }; } } |
