File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments