Add status icons widget

This commit is contained in:
Riku Isokoski
2022-07-21 19:27:52 +03:00
committed by JF
parent 77d3239866
commit edba1d9ccf
12 changed files with 151 additions and 69 deletions

View File

@@ -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();
}

View File

@@ -0,0 +1,38 @@
#pragma once
#include <lvgl/lvgl.h>
#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<uint8_t> batteryPercentRemaining {};
Screens::DirtyValue<bool> powerPresent {};
Screens::DirtyValue<bool> bleState {};
Screens::DirtyValue<bool> bleRadioEnabled {};
enum Icons { BatteryPlug, BleIcon };
lv_obj_t* icons[2];
};
}
}
}