Skip to content

Commit ec452d0

Browse files
committed
BatteryIcon: Change color with charge percentage
1 parent c2c53bc commit ec452d0

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/displayapp/screens/BatteryIcon.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
2727
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
2828
lv_obj_realign(batteryJuice);
2929
if (colorOnLowBattery) {
30-
static constexpr int lowBatteryThreshold = 15;
31-
static constexpr int criticalBatteryThreshold = 5;
32-
if (percentage > lowBatteryThreshold) {
33-
SetColor(LV_COLOR_WHITE);
34-
} else if (percentage > criticalBatteryThreshold) {
35-
SetColor(LV_COLOR_ORANGE);
36-
} else {
37-
SetColor(Colors::deepOrange);
38-
}
30+
// HSV color model has red at 0° and green at 120°.
31+
// We lock satuation and brightness at 100% and traverse the cilinder
32+
// between red and green, thus avoiding the darker RGB on medium battery
33+
// charges and giving us a much nicer color range.
34+
uint8_t hue = percentage * 120 / 100;
35+
SetColor(lv_color_hsv_to_rgb(hue, 100, 100));
3936
}
4037
}
4138

0 commit comments

Comments
 (0)