InfiniTime/src/displayapp/widgets/StatusIcons.cpp

48 lines
1.6 KiB
C++
Raw Normal View History

2022-07-21 12:27:52 -04:00
#include "displayapp/widgets/StatusIcons.h"
#include "displayapp/screens/Symbols.h"
using namespace Pinetime::Applications::Widgets;
2023-02-23 15:24:07 -05:00
StatusIcons::StatusIcons(const Controllers::Battery& batteryController, const Controllers::Ble& bleController)
2022-07-21 12:27:52 -04:00
: batteryController {batteryController}, bleController {bleController} {
}
void StatusIcons::Create() {
2022-07-23 12:13:56 -04:00
container = lv_cont_create(lv_scr_act(), nullptr);
lv_cont_set_layout(container, LV_LAYOUT_ROW_TOP);
lv_cont_set_fit(container, LV_FIT_TIGHT);
lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_bg_opa(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
bleIcon = lv_label_create(container, nullptr);
lv_label_set_text_static(bleIcon, Screens::Symbols::bluetooth);
2022-07-21 12:27:52 -04:00
2022-07-23 12:13:56 -04:00
batteryPlug = lv_label_create(container, nullptr);
lv_label_set_text_static(batteryPlug, Screens::Symbols::plug);
2022-07-21 12:27:52 -04:00
2022-07-23 12:13:56 -04:00
batteryIcon.Create(container);
2022-07-21 12:27:52 -04:00
2022-07-23 12:13:56 -04:00
lv_obj_align(container, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
2022-07-21 12:27:52 -04:00
}
void StatusIcons::Update() {
powerPresent = batteryController.IsPowerPresent();
if (powerPresent.IsUpdated()) {
2022-07-23 12:13:56 -04:00
lv_obj_set_hidden(batteryPlug, !powerPresent.Get());
2022-07-21 12:27:52 -04:00
}
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
batteryIcon.SetBatteryPercentage(batteryPercent);
}
bleState = bleController.IsConnected();
bleRadioEnabled = bleController.IsRadioEnabled();
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {
2022-07-23 12:13:56 -04:00
lv_obj_set_hidden(bleIcon, !bleState.Get());
2022-07-21 12:27:52 -04:00
}
2022-07-23 12:13:56 -04:00
lv_obj_realign(container);
2022-07-21 12:27:52 -04:00
}