From edba1d9ccfb2b16c26b12428acb71425f4f41cd5 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 21 Jul 2022 19:27:52 +0300 Subject: [PATCH] Add status icons widget --- src/CMakeLists.txt | 2 + src/displayapp/DisplayApp.cpp | 6 +- src/displayapp/screens/ApplicationList.cpp | 11 +++- src/displayapp/screens/ApplicationList.h | 2 + src/displayapp/screens/Tile.cpp | 19 ++++--- src/displayapp/screens/Tile.h | 10 ++-- src/displayapp/screens/WatchFaceDigital.cpp | 40 ++------------ src/displayapp/screens/WatchFaceDigital.h | 9 +-- .../screens/settings/QuickSettings.cpp | 15 ++--- .../screens/settings/QuickSettings.h | 13 +++-- src/displayapp/widgets/StatusIcons.cpp | 55 +++++++++++++++++++ src/displayapp/widgets/StatusIcons.h | 38 +++++++++++++ 12 files changed, 151 insertions(+), 69 deletions(-) create mode 100644 src/displayapp/widgets/StatusIcons.cpp create mode 100644 src/displayapp/widgets/StatusIcons.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6069aca6..e6971a56 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -406,6 +406,7 @@ list(APPEND SOURCE_FILES displayapp/Colors.cpp displayapp/widgets/Counter.cpp displayapp/widgets/PageIndicator.cpp + displayapp/widgets/StatusIcons.cpp ## Settings displayapp/screens/settings/QuickSettings.cpp @@ -611,6 +612,7 @@ set(INCLUDE_FILES displayapp/Colors.h displayapp/widgets/Counter.h displayapp/widgets/PageIndicator.h + displayapp/widgets/StatusIcons.h drivers/St7789.h drivers/SpiNorFlash.h drivers/SpiMaster.h diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 93d7277d..d5cc9810 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -311,7 +311,8 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) switch (app) { case Apps::Launcher: - currentScreen = std::make_unique(this, settingsController, batteryController, dateTimeController); + currentScreen = + std::make_unique(this, settingsController, batteryController, bleController, dateTimeController); ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::None: @@ -377,7 +378,8 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) dateTimeController, brightnessController, motorController, - settingsController); + settingsController, + bleController); ReturnApp(Apps::Clock, FullRefreshDirections::LeftAnim, TouchEvents::SwipeLeft); break; case Apps::Settings: diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index 9fd408e1..9f3e9568 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -21,10 +21,12 @@ auto ApplicationList::CreateScreenList() const { ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::Battery& batteryController, + Pinetime::Controllers::Ble& bleController, Controllers::DateTime& dateTimeController) : Screen(app), settingsController {settingsController}, batteryController {batteryController}, + bleController {bleController}, dateTimeController {dateTimeController}, screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} { } @@ -43,5 +45,12 @@ std::unique_ptr ApplicationList::CreateScreen(unsigned int screenNum) co apps[i] = applications[screenNum * appsPerScreen + i]; } - return std::make_unique(screenNum, nScreens, app, settingsController, batteryController, dateTimeController, apps); + return std::make_unique(screenNum, + nScreens, + app, + settingsController, + batteryController, + bleController, + dateTimeController, + apps); } diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index 14d7623c..e7c094bf 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -19,6 +19,7 @@ namespace Pinetime { explicit ApplicationList(DisplayApp* app, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::Battery& batteryController, + Pinetime::Controllers::Ble& bleController, Controllers::DateTime& dateTimeController); ~ApplicationList() override; bool OnTouchEvent(TouchEvents event) override; @@ -29,6 +30,7 @@ namespace Pinetime { Controllers::Settings& settingsController; Pinetime::Controllers::Battery& batteryController; + Pinetime::Controllers::Ble& bleController; Controllers::DateTime& dateTimeController; static constexpr int appsPerScreen = 6; diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index c633e17b..2af04ab0 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -1,6 +1,7 @@ #include "displayapp/screens/Tile.h" #include "displayapp/DisplayApp.h" #include "displayapp/screens/BatteryIcon.h" +#include "components/ble/BleController.h" using namespace Pinetime::Applications::Screens; @@ -26,22 +27,26 @@ Tile::Tile(uint8_t screenID, uint8_t numScreens, DisplayApp* app, Controllers::Settings& settingsController, - Pinetime::Controllers::Battery& batteryController, + Controllers::Battery& batteryController, + Controllers::Ble& bleController, Controllers::DateTime& dateTimeController, std::array& applications) - : Screen(app), batteryController {batteryController}, dateTimeController {dateTimeController}, pageIndicator(screenID, numScreens) { + : Screen(app), + dateTimeController {dateTimeController}, + pageIndicator(screenID, numScreens), + statusIcons(batteryController, bleController) { settingsController.SetAppMenu(screenID); + statusIcons.Create(); + lv_obj_align(statusIcons.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -8, 0); + statusIcons.Align(); + // Time label_time = lv_label_create(lv_scr_act(), nullptr); 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.Create(lv_scr_act()); - lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0); - pageIndicator.Create(); uint8_t btIndex = 0; @@ -93,7 +98,7 @@ Tile::~Tile() { void Tile::UpdateScreen() { lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); - batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining()); + statusIcons.Update(); } 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 ff121376..d8a68128 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -7,10 +7,9 @@ #include "displayapp/Apps.h" #include "components/datetime/DateTimeController.h" #include "components/settings/Settings.h" -#include "components/datetime/DateTimeController.h" #include "components/battery/BatteryController.h" -#include "displayapp/screens/BatteryIcon.h" #include "displayapp/widgets/PageIndicator.h" +#include "displayapp/widgets/StatusIcons.h" namespace Pinetime { namespace Applications { @@ -26,7 +25,8 @@ namespace Pinetime { uint8_t numScreens, DisplayApp* app, Controllers::Settings& settingsController, - Pinetime::Controllers::Battery& batteryController, + Controllers::Battery& batteryController, + Controllers::Ble& bleController, Controllers::DateTime& dateTimeController, std::array& applications); @@ -36,7 +36,6 @@ namespace Pinetime { void OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId); private: - Pinetime::Controllers::Battery& batteryController; Controllers::DateTime& dateTimeController; lv_task_t* taskUpdate; @@ -45,8 +44,7 @@ namespace Pinetime { lv_obj_t* btnm1; Widgets::PageIndicator pageIndicator; - - BatteryIcon batteryIcon; + Widgets::StatusIcons statusIcons; const char* btnmMap[8]; Pinetime::Applications::Apps apps[6]; diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index d10f8532..7e876d8f 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -3,8 +3,6 @@ #include #include #include -#include "displayapp/screens/BatteryIcon.h" -#include "displayapp/screens/BleIcon.h" #include "displayapp/screens/NotificationIcon.h" #include "displayapp/screens/Symbols.h" #include "components/battery/BatteryController.h" @@ -13,6 +11,7 @@ #include "components/heartrate/HeartRateController.h" #include "components/motion/MotionController.h" #include "components/settings/Settings.h" + using namespace Pinetime::Applications::Screens; WatchFaceDigital::WatchFaceDigital(DisplayApp* app, @@ -26,25 +25,13 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, : Screen(app), currentDateTime {{}}, dateTimeController {dateTimeController}, - batteryController {batteryController}, - bleController {bleController}, notificatioManager {notificatioManager}, settingsController {settingsController}, heartRateController {heartRateController}, - motionController {motionController} { + motionController {motionController}, + statusIcons(batteryController, bleController) { - batteryIcon.Create(lv_scr_act()); - lv_obj_align(batteryIcon.GetObject(), lv_scr_act(), 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.GetObject(), LV_ALIGN_OUT_LEFT_MID, -5, 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, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); + statusIcons.Create(); notificationIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); @@ -94,24 +81,7 @@ WatchFaceDigital::~WatchFaceDigital() { } void WatchFaceDigital::Refresh() { - powerPresent = batteryController.IsPowerPresent(); - if (powerPresent.IsUpdated()) { - lv_label_set_text_static(batteryPlug, BatteryIcon::GetPlugIcon(powerPresent.Get())); - } - - batteryPercentRemaining = batteryController.PercentRemaining(); - if (batteryPercentRemaining.IsUpdated()) { - auto batteryPercent = batteryPercentRemaining.Get(); - batteryIcon.SetBatteryPercentage(batteryPercent); - } - - bleState = bleController.IsConnected(); - bleRadioEnabled = bleController.IsRadioEnabled(); - if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) { - lv_label_set_text_static(bleIcon, BleIcon::GetIcon(bleState.Get())); - } - lv_obj_realign(batteryPlug); - lv_obj_realign(bleIcon); + statusIcons.Update(); notificationState = notificatioManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index bd27806f..49935792 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -8,6 +7,7 @@ #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" #include "components/ble/BleController.h" +#include "displayapp/widgets/StatusIcons.h" namespace Pinetime { namespace Controllers { @@ -59,25 +59,20 @@ namespace Pinetime { lv_obj_t* label_time; lv_obj_t* label_time_ampm; lv_obj_t* label_date; - lv_obj_t* bleIcon; - lv_obj_t* batteryPlug; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; lv_obj_t* stepIcon; lv_obj_t* stepValue; lv_obj_t* notificationIcon; - BatteryIcon batteryIcon; - Controllers::DateTime& dateTimeController; - Controllers::Battery& batteryController; - Controllers::Ble& bleController; Controllers::NotificationManager& notificatioManager; Controllers::Settings& settingsController; Controllers::HeartRateController& heartRateController; Controllers::MotionController& motionController; lv_task_t* taskRefresh; + Widgets::StatusIcons statusIcons; }; } } diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index ab5a437b..f7560066 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -2,6 +2,7 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" #include "displayapp/screens/BatteryIcon.h" +#include using namespace Pinetime::Applications::Screens; @@ -22,13 +23,16 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::BrightnessController& brightness, Controllers::MotorController& motorController, - Pinetime::Controllers::Settings& settingsController) + Pinetime::Controllers::Settings& settingsController, + Controllers::Ble& bleController) : Screen(app), - batteryController {batteryController}, dateTimeController {dateTimeController}, brightness {brightness}, motorController {motorController}, - settingsController {settingsController} { + settingsController {settingsController}, + statusIcons(batteryController, bleController) { + + statusIcons.Create(); // This is the distance (padding) between all objects on this screen. static constexpr uint8_t innerDistance = 10; @@ -38,9 +42,6 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, 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.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; static constexpr uint8_t buttonWidth = (LV_HOR_RES_MAX - innerDistance) / 2; // wide buttons @@ -117,7 +118,7 @@ QuickSettings::~QuickSettings() { void QuickSettings::UpdateScreen() { lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str()); - batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining()); + statusIcons.Update(); } 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 40a2a2ef..fd1b5ea4 100644 --- a/src/displayapp/screens/settings/QuickSettings.h +++ b/src/displayapp/screens/settings/QuickSettings.h @@ -8,7 +8,7 @@ #include "components/motor/MotorController.h" #include "components/settings/Settings.h" #include "components/battery/BatteryController.h" -#include +#include "displayapp/widgets/StatusIcons.h" namespace Pinetime { @@ -22,7 +22,8 @@ namespace Pinetime { Controllers::DateTime& dateTimeController, Controllers::BrightnessController& brightness, Controllers::MotorController& motorController, - Pinetime::Controllers::Settings& settingsController); + Pinetime::Controllers::Settings& settingsController, + Controllers::Ble& bleController); ~QuickSettings() override; @@ -31,7 +32,6 @@ namespace Pinetime { void UpdateScreen(); private: - Pinetime::Controllers::Battery& batteryController; Controllers::DateTime& dateTimeController; Controllers::BrightnessController& brightness; Controllers::MotorController& motorController; @@ -40,6 +40,11 @@ namespace Pinetime { lv_task_t* taskUpdate; lv_obj_t* label_time; + DirtyValue batteryPercentRemaining {}; + DirtyValue powerPresent {}; + DirtyValue bleState {}; + DirtyValue bleRadioEnabled {}; + lv_style_t btn_style; lv_obj_t* btn1; @@ -49,7 +54,7 @@ namespace Pinetime { lv_obj_t* btn3_lvl; lv_obj_t* btn4; - BatteryIcon batteryIcon; + Widgets::StatusIcons statusIcons; }; } } diff --git a/src/displayapp/widgets/StatusIcons.cpp b/src/displayapp/widgets/StatusIcons.cpp new file mode 100644 index 00000000..d8f294b5 --- /dev/null +++ b/src/displayapp/widgets/StatusIcons.cpp @@ -0,0 +1,55 @@ +#include "displayapp/widgets/StatusIcons.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Widgets; + +StatusIcons::StatusIcons(Controllers::Battery& batteryController, Controllers::Ble& bleController) + : batteryController {batteryController}, bleController {bleController} { +} + +void StatusIcons::Align() { + lv_obj_t* lastIcon = batteryIcon.GetObject(); + + for (auto& icon : icons) { + if (!lv_obj_get_hidden(icon)) { + lv_obj_align(icon, lastIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); + lastIcon = icon; + } + } +} + +void StatusIcons::Create() { + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); + + icons[Icons::BatteryPlug] = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icons[Icons::BatteryPlug], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFF0000)); + lv_label_set_text_static(icons[Icons::BatteryPlug], Screens::Symbols::plug); + + icons[Icons::BleIcon] = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icons[Icons::BleIcon], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x0082FC)); + lv_label_set_text_static(icons[Icons::BleIcon], Screens::Symbols::bluetooth); + + Align(); +} + +void StatusIcons::Update() { + powerPresent = batteryController.IsPowerPresent(); + if (powerPresent.IsUpdated()) { + lv_obj_set_hidden(icons[Icons::BatteryPlug], !powerPresent.Get()); + } + + batteryPercentRemaining = batteryController.PercentRemaining(); + if (batteryPercentRemaining.IsUpdated()) { + auto batteryPercent = batteryPercentRemaining.Get(); + batteryIcon.SetBatteryPercentage(batteryPercent); + } + + bleState = bleController.IsConnected(); + bleRadioEnabled = bleController.IsRadioEnabled(); + if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) { + lv_obj_set_hidden(icons[Icons::BleIcon], !bleState.Get()); + } + + Align(); +} diff --git a/src/displayapp/widgets/StatusIcons.h b/src/displayapp/widgets/StatusIcons.h new file mode 100644 index 00000000..b6e713e2 --- /dev/null +++ b/src/displayapp/widgets/StatusIcons.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include "displayapp/screens/Screen.h" +#include "components/battery/BatteryController.h" +#include "components/ble/BleController.h" +#include "displayapp/screens/BatteryIcon.h" + +namespace Pinetime { + namespace Applications { + namespace Widgets { + class StatusIcons { + public: + StatusIcons(Controllers::Battery& batteryController, Controllers::Ble& bleController); + void Align(); + void Create(); + lv_obj_t* GetObject() { + return batteryIcon.GetObject(); + } + void Update(); + + private: + Screens::BatteryIcon batteryIcon; + Pinetime::Controllers::Battery& batteryController; + Controllers::Ble& bleController; + + Screens::DirtyValue batteryPercentRemaining {}; + Screens::DirtyValue powerPresent {}; + Screens::DirtyValue bleState {}; + Screens::DirtyValue bleRadioEnabled {}; + + enum Icons { BatteryPlug, BleIcon }; + lv_obj_t* icons[2]; + }; + } + } +}