2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/screens/BatteryInfo.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
2021-04-04 02:08:51 +00:00
|
|
|
#include "components/battery/BatteryController.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Battery& batteryController)
|
|
|
|
: Screen(app), batteryController {batteryController} {
|
2021-04-04 02:08:51 +00:00
|
|
|
|
|
|
|
batteryPercent = batteryController.PercentRemaining();
|
|
|
|
batteryVoltage = batteryController.Voltage();
|
|
|
|
|
|
|
|
charging_bar = lv_bar_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_size(charging_bar, 200, 15);
|
|
|
|
lv_bar_set_range(charging_bar, 0, 100);
|
|
|
|
lv_obj_align(charging_bar, nullptr, LV_ALIGN_CENTER, 0, 10);
|
2021-07-07 12:47:47 +00:00
|
|
|
lv_bar_set_anim_time(charging_bar, 1000);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_obj_set_style_local_radius(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
|
|
|
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, lv_color_hex(0x222222));
|
|
|
|
lv_obj_set_style_local_bg_opa(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_100);
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, lv_color_hex(0xFF0000));
|
2021-07-07 12:47:47 +00:00
|
|
|
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
status = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_text_static(status, "Reading Battery status");
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_label_set_align(status, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-04-04 02:08:51 +00:00
|
|
|
percent = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
|
2021-07-11 14:55:06 +00:00
|
|
|
lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT);
|
|
|
|
lv_obj_align(percent, nullptr, LV_ALIGN_CENTER, 0, -60);
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
voltage = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_obj_set_style_local_text_color(voltage, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xC6A600));
|
2021-07-02 15:30:32 +00:00
|
|
|
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_label_set_align(voltage, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_obj_align(voltage, nullptr, LV_ALIGN_CENTER, 0, 95);
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text_static(backgroundLabel, "");
|
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, 5000, LV_TASK_PRIO_MID, this);
|
|
|
|
Refresh();
|
2021-04-04 02:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BatteryInfo::~BatteryInfo() {
|
2021-07-19 13:26:12 +00:00
|
|
|
lv_task_del(taskRefresh);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
void BatteryInfo::Refresh() {
|
2021-04-04 02:08:51 +00:00
|
|
|
|
|
|
|
batteryPercent = batteryController.PercentRemaining();
|
|
|
|
batteryVoltage = batteryController.Voltage();
|
|
|
|
|
2021-09-03 11:35:38 +00:00
|
|
|
if (batteryController.IsCharging()) {
|
2021-07-11 14:55:06 +00:00
|
|
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
|
2021-07-13 18:31:26 +00:00
|
|
|
lv_label_set_text_static(status, "Charging");
|
2021-09-03 13:57:00 +00:00
|
|
|
} else if (batteryPercent == 100) {
|
2021-07-11 14:55:06 +00:00
|
|
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
|
2021-07-13 18:31:26 +00:00
|
|
|
lv_label_set_text_static(status, "Fully charged");
|
2021-07-11 14:55:06 +00:00
|
|
|
} else if (batteryPercent < 10) {
|
|
|
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
2021-07-13 18:31:26 +00:00
|
|
|
lv_label_set_text_static(status, "Battery low");
|
2021-04-04 02:08:51 +00:00
|
|
|
} else {
|
2021-07-11 14:55:06 +00:00
|
|
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
2021-07-13 18:31:26 +00:00
|
|
|
lv_label_set_text_static(status, "Discharging");
|
2021-04-04 02:08:51 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 14:55:06 +00:00
|
|
|
lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
|
|
|
|
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
|
2021-07-02 15:30:32 +00:00
|
|
|
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
|
2021-07-07 12:47:47 +00:00
|
|
|
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
|
2021-04-04 02:08:51 +00:00
|
|
|
}
|