mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-10-22 23:21:53 +02:00
BatteryIcon: Change color with charge percentage
This commit is contained in:
parent
a2356f2f4a
commit
a9aa092c7b
|
@ -27,15 +27,12 @@ void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
|
||||||
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
|
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
|
||||||
lv_obj_realign(batteryJuice);
|
lv_obj_realign(batteryJuice);
|
||||||
if (colorOnLowBattery) {
|
if (colorOnLowBattery) {
|
||||||
static constexpr int lowBatteryThreshold = 15;
|
// HSV color model has red at 0° and green at 120°.
|
||||||
static constexpr int criticalBatteryThreshold = 5;
|
// We lock satuation and brightness at 100% and traverse the cilinder
|
||||||
if (percentage > lowBatteryThreshold) {
|
// between red and green, thus avoiding the darker RGB on medium battery
|
||||||
SetColor(LV_COLOR_WHITE);
|
// charges and giving us a much nicer color range.
|
||||||
} else if (percentage > criticalBatteryThreshold) {
|
uint8_t hue = percentage * 120 / 100;
|
||||||
SetColor(LV_COLOR_ORANGE);
|
SetColor(lv_color_hsv_to_rgb(hue, 100, 100));
|
||||||
} else {
|
|
||||||
SetColor(Colors::deepOrange);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue