diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/displayapp/screens/BatteryIcon.cpp | 10 | ||||
| -rw-r--r-- | src/displayapp/screens/BatteryIcon.h | 1 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceTerminal.cpp | 10 |
3 files changed, 15 insertions, 6 deletions
diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 6194807d..ec740e93 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -3,6 +3,7 @@ #include "displayapp/screens/Symbols.h" #include "displayapp/icons/battery/batteryicon.c" #include "displayapp/InfiniTimeTheme.h" +#include <lvgl/src/lv_misc/lv_color.h> using namespace Pinetime::Applications::Screens; @@ -51,3 +52,12 @@ const char* BatteryIcon::GetPlugIcon(bool isCharging) { else return ""; } + +lv_color_t BatteryIcon::ColorFromPercentage(int batteryPercent) { + // HSV color model has red at 0° and green at 120°. + // We lock saturation and brightness at 100% and traverse the cylinder + // between red and green, thus avoiding the darker RGB on medium battery + // charges and giving us a much nicer color range. + const uint8_t hue = batteryPercent * 120 / 100; + return lv_color_hsv_to_rgb(hue, 100, 100); +} diff --git a/src/displayapp/screens/BatteryIcon.h b/src/displayapp/screens/BatteryIcon.h index 19fea967..ffce57c7 100644 --- a/src/displayapp/screens/BatteryIcon.h +++ b/src/displayapp/screens/BatteryIcon.h @@ -16,6 +16,7 @@ namespace Pinetime { static const char* GetUnknownIcon(); static const char* GetPlugIcon(bool isCharging); + static lv_color_t ColorFromPercentage(int batteryPercent); private: lv_obj_t* batteryImg; diff --git a/src/displayapp/screens/WatchFaceTerminal.cpp b/src/displayapp/screens/WatchFaceTerminal.cpp index 4442b29c..69fbc3ce 100644 --- a/src/displayapp/screens/WatchFaceTerminal.cpp +++ b/src/displayapp/screens/WatchFaceTerminal.cpp @@ -123,12 +123,10 @@ void WatchFaceTerminal::Refresh() { powerPresent = batteryController.IsPowerPresent(); batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated() || powerPresent.IsUpdated()) { - // HSV color model has red at 0° and green at 120°. - // We lock satuation and brightness at 100% and traverse the cilinder - // between red and green, thus avoiding the darker RGB on medium battery - // charges and giving us a much nicer color range. - uint8_t hue = batteryPercentRemaining.Get() * 120 / 100; - lv_obj_set_style_local_text_color(batteryValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hsv_to_rgb(hue, 100, 100)); + lv_obj_set_style_local_text_color(batteryValue, + LV_LABEL_PART_MAIN, + LV_STATE_DEFAULT, + BatteryIcon::ColorFromPercentage(batteryPercentRemaining.Get())); lv_label_set_text_fmt(batteryValue, "#ffffff [BATT]# %d%%", batteryPercentRemaining.Get()); if (batteryController.IsCharging()) { lv_label_ins_text(batteryValue, LV_LABEL_POS_LAST, " Charging"); |
