Skip to content

Commit 08b4cfb

Browse files
committed
Add low battery indicator to StatusIcons, digital and analog watchfaces
Define deepOrange color in InfiniTimeTheme
1 parent fff0a00 commit 08b4cfb

7 files changed

+21
-1
lines changed

src/displayapp/InfiniTimeTheme.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <lvgl/lvgl.h>
44

55
namespace Colors {
6+
static constexpr lv_color_t deepOrange = LV_COLOR_MAKE(0xff, 0x40, 0x0);
67
static constexpr lv_color_t orange = LV_COLOR_MAKE(0xff, 0xb0, 0x0);
78
static constexpr lv_color_t green = LV_COLOR_MAKE(0x0, 0xb0, 0x0);
89
static constexpr lv_color_t blue = LV_COLOR_MAKE(0x0, 0x50, 0xff);

src/displayapp/screens/BatteryIcon.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#include <cstdint>
33
#include "displayapp/screens/Symbols.h"
44
#include "displayapp/icons/battery/batteryicon.c"
5+
#include "displayapp/InfiniTimeTheme.h"
56

67
using namespace Pinetime::Applications::Screens;
78

9+
BatteryIcon::BatteryIcon(bool colorOnLowBattery) : colorOnLowBattery {colorOnLowBattery} {};
10+
811
void BatteryIcon::Create(lv_obj_t* parent) {
912
batteryImg = lv_img_create(parent, nullptr);
1013
lv_img_set_src(batteryImg, &batteryicon);
@@ -23,6 +26,17 @@ lv_obj_t* BatteryIcon::GetObject() {
2326
void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
2427
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
2528
lv_obj_realign(batteryJuice);
29+
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+
}
39+
}
2640
}
2741

2842
void BatteryIcon::SetColor(lv_color_t color) {

src/displayapp/screens/BatteryIcon.h

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Pinetime {
77
namespace Screens {
88
class BatteryIcon {
99
public:
10+
explicit BatteryIcon(bool colorOnLowBattery);
1011
void Create(lv_obj_t* parent);
1112

1213
void SetColor(lv_color_t);
@@ -19,6 +20,7 @@ namespace Pinetime {
1920
private:
2021
lv_obj_t* batteryImg;
2122
lv_obj_t* batteryJuice;
23+
bool colorOnLowBattery = false;
2224
};
2325
}
2426
}

src/displayapp/screens/WatchFaceAnalog.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
4949
Controllers::NotificationManager& notificationManager,
5050
Controllers::Settings& settingsController)
5151
: currentDateTime {{}},
52+
batteryIcon(true),
5253
dateTimeController {dateTimeController},
5354
batteryController {batteryController},
5455
bleController {bleController},

src/displayapp/screens/WatchFaceCasioStyleG7710.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
2323
Controllers::MotionController& motionController,
2424
Controllers::FS& filesystem)
2525
: currentDateTime {{}},
26+
batteryIcon(false),
2627
dateTimeController {dateTimeController},
2728
batteryController {batteryController},
2829
bleController {bleController},

src/displayapp/screens/WatchFacePineTimeStyle.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(Controllers::DateTime& dateTimeCo
5050
Controllers::Settings& settingsController,
5151
Controllers::MotionController& motionController)
5252
: currentDateTime {{}},
53+
batteryIcon(false),
5354
dateTimeController {dateTimeController},
5455
batteryController {batteryController},
5556
bleController {bleController},

src/displayapp/widgets/StatusIcons.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using namespace Pinetime::Applications::Widgets;
55

66
StatusIcons::StatusIcons(const Controllers::Battery& batteryController, const Controllers::Ble& bleController)
7-
: batteryController {batteryController}, bleController {bleController} {
7+
: batteryIcon(true), batteryController {batteryController}, bleController {bleController} {
88
}
99

1010
void StatusIcons::Create() {

0 commit comments

Comments
 (0)