diff options
Diffstat (limited to 'src/displayapp/widgets/StatusIcons.cpp')
-rw-r--r-- | src/displayapp/widgets/StatusIcons.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
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(); +} |