aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2025-12-29 22:25:53 +0100
committerJF <JF002@users.noreply.github.com>2026-01-05 13:19:06 +0100
commita277316f98aee49d00e51778a71760a531f1f94e (patch)
treeae7155d84063eb49ac0c323e90b8ac9ecfb42ea9
parentc2e59583e19bdb2596a09717a91c77e61366a019 (diff)
WatchFaceTerminal : Apply better curve in BatteryIcon::ColorFromPercentage() so the color doesn't start going yellow until the battery is low.
-rw-r--r--src/displayapp/screens/BatteryIcon.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp
index ec740e93..8ebb1f54 100644
--- a/src/displayapp/screens/BatteryIcon.cpp
+++ b/src/displayapp/screens/BatteryIcon.cpp
@@ -1,5 +1,6 @@
-#include "displayapp/screens/BatteryIcon.h"
#include <cstdint>
+#include <cmath>
+#include "displayapp/screens/BatteryIcon.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/icons/battery/batteryicon.c"
#include "displayapp/InfiniTimeTheme.h"
@@ -58,6 +59,8 @@ lv_color_t BatteryIcon::ColorFromPercentage(int batteryPercent) {
// 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;
+ const float normalizedPercent = batteryPercent / 100.0f;
+ // Follow -e^{-4x} + 1 curve: begins going yellow around 25%, yellow around 15%, red around 5%
+ const uint8_t hue = (-std::exp(-4.0f * normalizedPercent) + 1.0f) * 120.0f;
return lv_color_hsv_to_rgb(hue, 100, 100);
}