Add low battery indicator to StatusIcons, digital and analog watchfaces

Define deepOrange color in InfiniTimeTheme
This commit is contained in:
Riku Isokoski
2022-12-31 10:05:38 +02:00
parent fff0a00a4a
commit 08b4cfbb50
7 changed files with 21 additions and 1 deletions

View File

@@ -2,9 +2,12 @@
#include <cstdint>
#include "displayapp/screens/Symbols.h"
#include "displayapp/icons/battery/batteryicon.c"
#include "displayapp/InfiniTimeTheme.h"
using namespace Pinetime::Applications::Screens;
BatteryIcon::BatteryIcon(bool colorOnLowBattery) : colorOnLowBattery {colorOnLowBattery} {};
void BatteryIcon::Create(lv_obj_t* parent) {
batteryImg = lv_img_create(parent, nullptr);
lv_img_set_src(batteryImg, &batteryicon);
@@ -23,6 +26,17 @@ lv_obj_t* BatteryIcon::GetObject() {
void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
lv_obj_realign(batteryJuice);
if (colorOnLowBattery) {
static constexpr int lowBatteryThreshold = 15;
static constexpr int criticalBatteryThreshold = 5;
if (percentage > lowBatteryThreshold) {
SetColor(LV_COLOR_WHITE);
} else if (percentage > criticalBatteryThreshold) {
SetColor(LV_COLOR_ORANGE);
} else {
SetColor(Colors::deepOrange);
}
}
}
void BatteryIcon::SetColor(lv_color_t color) {