From 08b4cfbb50a5ad7b6d2aebea4ef605165d88832b Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 31 Dec 2022 10:05:38 +0200 Subject: Add low battery indicator to StatusIcons, digital and analog watchfaces Define deepOrange color in InfiniTimeTheme --- src/displayapp/screens/BatteryIcon.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/displayapp/screens/BatteryIcon.cpp') diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 2fe7c251..6194807d 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -2,9 +2,12 @@ #include #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) { -- cgit v1.2.3-70-g09d2