From c451d2ce9fae0c491a5e516a85f2faf1cf25273e Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Fri, 26 Dec 2025 14:50:01 +0100 Subject: Refactor battery color calculation logic into `BatteryIcon::ColorFromPercentage()`. --- src/displayapp/screens/BatteryIcon.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/displayapp/screens/BatteryIcon.cpp') diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 6194807d..ec740e93 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -3,6 +3,7 @@ #include "displayapp/screens/Symbols.h" #include "displayapp/icons/battery/batteryicon.c" #include "displayapp/InfiniTimeTheme.h" +#include using namespace Pinetime::Applications::Screens; @@ -51,3 +52,12 @@ const char* BatteryIcon::GetPlugIcon(bool isCharging) { else return ""; } + +lv_color_t BatteryIcon::ColorFromPercentage(int batteryPercent) { + // HSV color model has red at 0° and green at 120°. + // We lock saturation and brightness at 100% and traverse the cylinder + // between red and green, thus avoiding the darker RGB on medium battery + // charges and giving us a much nicer color range. + const uint8_t hue = batteryPercent * 120 / 100; + return lv_color_hsv_to_rgb(hue, 100, 100); +} -- cgit v1.2.3-70-g09d2