Skip to content

Commit 1213bb0

Browse files
JF002mark9064
authored andcommitted
WatchFaceTerminal : Apply better curve in BatteryIcon::ColorFromPercentage() so the color doesn't start going yellow until the battery is low.
1 parent 465d5b6 commit 1213bb0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/displayapp/screens/BatteryIcon.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include "displayapp/screens/BatteryIcon.h"
21
#include <cstdint>
2+
#include <cmath>
3+
#include "displayapp/screens/BatteryIcon.h"
34
#include "displayapp/screens/Symbols.h"
45
#include "displayapp/icons/battery/batteryicon.c"
56
#include "displayapp/InfiniTimeTheme.h"
@@ -58,6 +59,8 @@ lv_color_t BatteryIcon::ColorFromPercentage(int batteryPercent) {
5859
// We lock saturation and brightness at 100% and traverse the cylinder
5960
// between red and green, thus avoiding the darker RGB on medium battery
6061
// charges and giving us a much nicer color range.
61-
const uint8_t hue = batteryPercent * 120 / 100;
62+
const float normalizedPercent = batteryPercent / 100.0f;
63+
// Follow -e^{-4x} + 1 curve: begins going yellow around 25%, yellow around 15%, red around 5%
64+
const uint8_t hue = (-std::exp(-4.0f * normalizedPercent) + 1.0f) * 120.0f;
6265
return lv_color_hsv_to_rgb(hue, 100, 100);
6366
}

0 commit comments

Comments
 (0)