Add low battery indicator to StatusIcons, digital and analog watchfaces

Define deepOrange color in InfiniTimeTheme
This commit is contained in:
Riku Isokoski 2022-12-31 10:05:38 +02:00
parent fff0a00a4a
commit 08b4cfbb50
7 changed files with 21 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include <lvgl/lvgl.h>
namespace Colors {
static constexpr lv_color_t deepOrange = LV_COLOR_MAKE(0xff, 0x40, 0x0);
static constexpr lv_color_t orange = LV_COLOR_MAKE(0xff, 0xb0, 0x0);
static constexpr lv_color_t green = LV_COLOR_MAKE(0x0, 0xb0, 0x0);
static constexpr lv_color_t blue = LV_COLOR_MAKE(0x0, 0x50, 0xff);

View File

@ -2,9 +2,12 @@
#include <cstdint>
#include "displayapp/screens/Symbols.h"
#include "displayapp/icons/battery/batteryicon.c"
#include "displayapp/InfiniTimeTheme.h"
using namespace Pinetime::Applications::Screens;
BatteryIcon::BatteryIcon(bool colorOnLowBattery) : colorOnLowBattery {colorOnLowBattery} {};
void BatteryIcon::Create(lv_obj_t* parent) {
batteryImg = lv_img_create(parent, nullptr);
lv_img_set_src(batteryImg, &batteryicon);
@ -23,6 +26,17 @@ lv_obj_t* BatteryIcon::GetObject() {
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);
}
}
}
void BatteryIcon::SetColor(lv_color_t color) {

View File

@ -7,6 +7,7 @@ namespace Pinetime {
namespace Screens {
class BatteryIcon {
public:
explicit BatteryIcon(bool colorOnLowBattery);
void Create(lv_obj_t* parent);
void SetColor(lv_color_t);
@ -19,6 +20,7 @@ namespace Pinetime {
private:
lv_obj_t* batteryImg;
lv_obj_t* batteryJuice;
bool colorOnLowBattery = false;
};
}
}

View File

@ -49,6 +49,7 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController)
: currentDateTime {{}},
batteryIcon(true),
dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},

View File

@ -23,6 +23,7 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
Controllers::MotionController& motionController,
Controllers::FS& filesystem)
: currentDateTime {{}},
batteryIcon(false),
dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},

View File

@ -50,6 +50,7 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(Controllers::DateTime& dateTimeCo
Controllers::Settings& settingsController,
Controllers::MotionController& motionController)
: currentDateTime {{}},
batteryIcon(false),
dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},

View File

@ -4,7 +4,7 @@
using namespace Pinetime::Applications::Widgets;
StatusIcons::StatusIcons(const Controllers::Battery& batteryController, const Controllers::Ble& bleController)
: batteryController {batteryController}, bleController {bleController} {
: batteryIcon(true), batteryController {batteryController}, bleController {bleController} {
}
void StatusIcons::Create() {