2022-07-21 12:27:52 -04:00
|
|
|
#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::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
|
|
|
}
|