Skip to content

Commit

Permalink
BatteryIcon: Change color with charge percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
vkareh committed Jan 13, 2024
1 parent 0503248 commit bfaaffd
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/displayapp/screens/BatteryIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
lv_obj_realign(batteryJuice);
if (colorOnLowBattery) {
static constexpr int lowBatteryThreshold = 15;
static constexpr int criticalBatteryThreshold = 5;
if (percentage > lowBatteryThreshold) {
SetColor(LV_COLOR_WHITE);
} else if (percentage > criticalBatteryThreshold) {
SetColor(LV_COLOR_ORANGE);
} else {
SetColor(Colors::deepOrange);
}
uint8_t green = percentage * 255 / 100;
uint8_t red = 255 - green;
SetColor(LV_COLOR_MAKE(red, green, 0x0));
}
}

Expand Down

0 comments on commit bfaaffd

Please sign in to comment.