New sharper batteryicon. Remove old unused batteryicons

This commit is contained in:
Riku Isokoski
2022-04-07 17:28:04 +03:00
parent 54df828665
commit b31fbb4adb
61 changed files with 145 additions and 1392 deletions

View File

@@ -1,23 +1,34 @@
#include "displayapp/screens/BatteryIcon.h"
#include <cstdint>
#include "displayapp/screens/Symbols.h"
#include "displayapp/icons/battery/batteryicon.c"
using namespace Pinetime::Applications::Screens;
const char* BatteryIcon::GetBatteryIcon(uint8_t batteryPercent) {
if (batteryPercent > 87)
return Symbols::batteryFull;
if (batteryPercent > 62)
return Symbols::batteryThreeQuarter;
if (batteryPercent > 37)
return Symbols::batteryHalf;
if (batteryPercent > 12)
return Symbols::batteryOneQuarter;
return Symbols::batteryEmpty;
void BatteryIcon::Create(lv_obj_t* parent) {
batteryImg = lv_img_create(parent, nullptr);
lv_img_set_src(batteryImg, &batteryicon);
lv_obj_set_style_local_image_recolor(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
batteryJuice = lv_obj_create(batteryImg, nullptr);
lv_obj_set_width(batteryJuice, 8);
lv_obj_align(batteryJuice, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -2, -2);
lv_obj_set_style_local_radius(batteryJuice, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 0);
}
const char* BatteryIcon::GetUnknownIcon() {
return Symbols::batteryEmpty;
lv_obj_t* BatteryIcon::GetObject() {
return batteryImg;
}
void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
lv_obj_realign(batteryJuice);
}
void BatteryIcon::SetColor(lv_color_t color) {
lv_obj_set_style_local_image_recolor(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, color);
lv_obj_set_style_local_image_recolor_opa(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_obj_set_style_local_bg_color(batteryJuice, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color);
}
const char* BatteryIcon::GetPlugIcon(bool isCharging) {

View File

@@ -1,15 +1,24 @@
#pragma once
#include <cstdint>
#include <lvgl/src/lv_core/lv_obj.h>
namespace Pinetime {
namespace Applications {
namespace Screens {
class BatteryIcon {
public:
void Create(lv_obj_t* parent);
void SetColor(lv_color_t);
void SetBatteryPercentage(uint8_t percentage);
lv_obj_t* GetObject();
static const char* GetUnknownIcon();
static const char* GetBatteryIcon(uint8_t batteryPercent);
static const char* GetPlugIcon(bool isCharging);
private:
lv_obj_t* batteryImg;
lv_obj_t* batteryJuice;
};
}
}
}
}

View File

@@ -35,14 +35,12 @@ Tile::Tile(uint8_t screenID,
// Time
label_time = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
// Battery
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0);
batteryIcon.Create(lv_scr_act());
lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0);
if (numScreens > 1) {
pageIndicatorBasePoints[0].x = LV_HOR_RES - 1;
@@ -113,6 +111,8 @@ Tile::Tile(uint8_t screenID,
lv_label_set_text_static(backgroundLabel, "");
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);
UpdateScreen();
}
Tile::~Tile() {
@@ -122,7 +122,7 @@ Tile::~Tile() {
void Tile::UpdateScreen() {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining());
}
void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) {

View File

@@ -9,6 +9,7 @@
#include "components/settings/Settings.h"
#include "components/datetime/DateTimeController.h"
#include "components/battery/BatteryController.h"
#include <displayapp/screens/BatteryIcon.h>
namespace Pinetime {
namespace Applications {
@@ -40,13 +41,14 @@ namespace Pinetime {
lv_task_t* taskUpdate;
lv_obj_t* label_time;
lv_obj_t* batteryIcon;
lv_point_t pageIndicatorBasePoints[2];
lv_point_t pageIndicatorPoints[2];
lv_obj_t* pageIndicatorBase;
lv_obj_t* pageIndicator;
lv_obj_t* btnm1;
BatteryIcon batteryIcon;
const char* btnmMap[8];
Pinetime::Applications::Apps apps[6];
};

View File

@@ -66,10 +66,13 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app,
lv_img_set_src(bg_clock_img, &bg_clock);
lv_obj_align(bg_clock_img, NULL, LV_ALIGN_CENTER, 0, 0);
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(batteryIcon, Symbols::batteryHalf);
lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
lv_obj_set_auto_realign(batteryIcon, true);
batteryIcon.Create(lv_scr_act());
lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
plugIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(plugIcon, Symbols::plug);
lv_obj_set_style_local_text_color(plugIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
lv_obj_align(plugIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
notificationIcon = lv_label_create(lv_scr_act(), NULL);
lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00));
@@ -121,7 +124,8 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app,
lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace);
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
UpdateClock();
Refresh();
}
WatchFaceAnalog::~WatchFaceAnalog() {
@@ -180,21 +184,18 @@ void WatchFaceAnalog::UpdateClock() {
void WatchFaceAnalog::SetBatteryIcon() {
auto batteryPercent = batteryPercentRemaining.Get();
if (batteryPercent == 100) {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
} else {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
}
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
batteryIcon.SetBatteryPercentage(batteryPercent);
}
void WatchFaceAnalog::Refresh() {
isCharging = batteryController.IsCharging();
if (isCharging.IsUpdated()) {
if (isCharging.Get()) {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
lv_label_set_text_static(batteryIcon, Symbols::plug);
lv_obj_set_hidden(batteryIcon.GetObject(), true);
lv_obj_set_hidden(plugIcon, false);
} else {
lv_obj_set_hidden(batteryIcon.GetObject(), false);
lv_obj_set_hidden(plugIcon, true);
SetBatteryIcon();
}
}

View File

@@ -9,6 +9,7 @@
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include <displayapp/screens/BatteryIcon.h>
namespace Pinetime {
namespace Controllers {
@@ -64,9 +65,11 @@ namespace Pinetime {
lv_style_t second_line_style;
lv_obj_t* label_date_day;
lv_obj_t* batteryIcon;
lv_obj_t* plugIcon;
lv_obj_t* notificationIcon;
BatteryIcon batteryIcon;
const Controllers::DateTime& dateTimeController;
Controllers::Battery& batteryController;
Controllers::Ble& bleController;

View File

@@ -33,14 +33,13 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
heartRateController {heartRateController},
motionController {motionController} {
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(batteryIcon, Symbols::batteryFull);
lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
batteryIcon.Create(lv_scr_act());
lv_obj_align(batteryIcon.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
batteryPlug = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFF0000));
lv_label_set_text_static(batteryPlug, Symbols::plug);
lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0);
lv_obj_align(batteryPlug, batteryIcon.GetObject(), LV_ALIGN_OUT_LEFT_MID, -5, 0);
bleIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x0082FC));
@@ -110,12 +109,7 @@ void WatchFaceDigital::Refresh() {
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
if (batteryPercent == 100) {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
} else {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
}
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
batteryIcon.SetBatteryPercentage(batteryPercent);
}
bleState = bleController.IsConnected();
@@ -123,7 +117,6 @@ void WatchFaceDigital::Refresh() {
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {
lv_label_set_text_static(bleIcon, BleIcon::GetIcon(bleState.Get()));
}
lv_obj_realign(batteryIcon);
lv_obj_realign(batteryPlug);
lv_obj_realign(bleIcon);

View File

@@ -1,5 +1,6 @@
#pragma once
#include <displayapp/screens/BatteryIcon.h>
#include <lvgl/src/lv_core/lv_obj.h>
#include <chrono>
#include <cstdint>
@@ -59,7 +60,6 @@ namespace Pinetime {
lv_obj_t* label_time_ampm;
lv_obj_t* label_date;
lv_obj_t* backgroundLabel;
lv_obj_t* batteryIcon;
lv_obj_t* bleIcon;
lv_obj_t* batteryPlug;
lv_obj_t* heartbeatIcon;
@@ -68,6 +68,8 @@ namespace Pinetime {
lv_obj_t* stepValue;
lv_obj_t* notificationIcon;
BatteryIcon batteryIcon;
Controllers::DateTime& dateTimeController;
Controllers::Battery& batteryController;
Controllers::Ble& bleController;

View File

@@ -101,11 +101,14 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(DisplayApp* app,
lv_obj_align(sidebar, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
// Display icons
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_label_set_text_static(batteryIcon, Symbols::batteryFull);
lv_obj_align(batteryIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2);
lv_obj_set_auto_realign(batteryIcon, true);
batteryIcon.Create(sidebar);
batteryIcon.SetColor(LV_COLOR_BLACK);
lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_MID, 0, 2);
plugIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(plugIcon, Symbols::plug);
lv_obj_set_style_local_text_color(plugIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_align(plugIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2);
bleIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
@@ -340,7 +343,7 @@ bool WatchFacePineTimeStyle::OnButtonPushed() {
void WatchFacePineTimeStyle::SetBatteryIcon() {
auto batteryPercent = batteryPercentRemaining.Get();
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
batteryIcon.SetBatteryPercentage(batteryPercent);
}
void WatchFacePineTimeStyle::AlignIcons() {
@@ -358,8 +361,11 @@ void WatchFacePineTimeStyle::Refresh() {
isCharging = batteryController.IsCharging();
if (isCharging.IsUpdated()) {
if (isCharging.Get()) {
lv_label_set_text_static(batteryIcon, Symbols::plug);
lv_obj_set_hidden(batteryIcon.GetObject(), true);
lv_obj_set_hidden(plugIcon, false);
} else {
lv_obj_set_hidden(batteryIcon.GetObject(), false);
lv_obj_set_hidden(plugIcon, true);
SetBatteryIcon();
}
}

View File

@@ -8,6 +8,7 @@
#include "displayapp/Colors.h"
#include "components/datetime/DateTimeController.h"
#include "components/ble/BleController.h"
#include <displayapp/screens/BatteryIcon.h>
namespace Pinetime {
namespace Controllers {
@@ -79,7 +80,7 @@ namespace Pinetime {
lv_obj_t* dateDay;
lv_obj_t* dateMonth;
lv_obj_t* backgroundLabel;
lv_obj_t* batteryIcon;
lv_obj_t* plugIcon;
lv_obj_t* bleIcon;
lv_obj_t* calendarOuter;
lv_obj_t* calendarInner;
@@ -93,6 +94,8 @@ namespace Pinetime {
lv_obj_t* lbl_btnSet;
lv_color_t needle_colors[1];
BatteryIcon batteryIcon;
Controllers::DateTime& dateTimeController;
Controllers::Battery& batteryController;
Controllers::Ble& bleController;

View File

@@ -35,13 +35,11 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
// Time
label_time = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
batteryIcon.Create(lv_scr_act());
lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
static constexpr uint8_t barHeight = 20 + innerDistance;
static constexpr uint8_t buttonHeight = (LV_VER_RES_MAX - barHeight - innerDistance) / 2;
@@ -113,6 +111,8 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
lv_label_set_text_static(backgroundLabel, "");
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);
UpdateScreen();
}
QuickSettings::~QuickSettings() {
@@ -124,7 +124,7 @@ QuickSettings::~QuickSettings() {
void QuickSettings::UpdateScreen() {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining());
}
void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {

View File

@@ -8,6 +8,7 @@
#include "components/motor/MotorController.h"
#include "components/settings/Settings.h"
#include "components/battery/BatteryController.h"
#include <displayapp/screens/BatteryIcon.h>
namespace Pinetime {
@@ -37,7 +38,6 @@ namespace Pinetime {
Controllers::Settings& settingsController;
lv_task_t* taskUpdate;
lv_obj_t* batteryIcon;
lv_obj_t* label_time;
lv_style_t btn_style;
@@ -48,6 +48,8 @@ namespace Pinetime {
lv_obj_t* btn3;
lv_obj_t* btn3_lvl;
lv_obj_t* btn4;
BatteryIcon batteryIcon;
};
}
}