Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,18 @@ namespace Pinetime {
return bleRadioEnabled;
};

void SetShowBatteryPercentage(bool enabled) {
settings.showBatteryPercentage = enabled;
}

bool GetShowBatteryPercentage() {
return settings.showBatteryPercentage;
}

private:
Pinetime::Controllers::FS& fs;

static constexpr uint32_t settingsVersion = 0x0003;
static constexpr uint32_t settingsVersion = 0x0004;
struct SettingsData {
uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000;
Expand All @@ -229,6 +237,7 @@ namespace Pinetime {
std::bitset<4> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150;
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
bool showBatteryPercentage = false;
};

SettingsData settings;
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::BatteryInfo:
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SysInfo:
Expand Down
31 changes: 25 additions & 6 deletions src/displayapp/screens/BatteryIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,42 @@
using namespace Pinetime::Applications::Screens;

void BatteryIcon::Create(lv_obj_t* parent) {
batteryImg = lv_img_create(parent, nullptr);

batteryContainer = lv_cont_create(parent, nullptr);
lv_cont_set_layout(batteryContainer, LV_LAYOUT_ROW_MID);
lv_cont_set_fit(batteryContainer, LV_FIT_TIGHT);
lv_obj_set_style_local_bg_color(batteryContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_style_local_pad_inner(batteryContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_pad_hor(batteryContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);

batteryImg = lv_img_create(batteryContainer, 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);

batteryPercentageText = lv_label_create(batteryContainer, nullptr);
lv_label_set_text(batteryPercentageText, "");
lv_obj_align(batteryPercentageText, batteryContainer, LV_ALIGN_IN_RIGHT_MID, 0, 0);
}

lv_obj_t* BatteryIcon::GetObject() {
return batteryImg;
return batteryContainer;
}

void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
void BatteryIcon::SetBatteryPercentage(uint8_t percentage, bool show_percentage) {
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
lv_obj_realign(batteryJuice);
if (show_percentage) {
lv_label_set_text_fmt(batteryPercentageText, "%02i%%", percentage);
} else {
lv_label_set_text(batteryPercentageText, "");
}
lv_obj_realign(batteryPercentageText);
lv_obj_realign(batteryContainer);
}

void BatteryIcon::SetColor(lv_color_t color) {
Expand All @@ -32,8 +51,8 @@ void BatteryIcon::SetColor(lv_color_t color) {
}

const char* BatteryIcon::GetPlugIcon(bool isCharging) {
if (isCharging)
if (isCharging) {
return Symbols::plug;
else
return "";
}
return "";
}
5 changes: 4 additions & 1 deletion src/displayapp/screens/BatteryIcon.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <lvgl/src/lv_core/lv_obj.h>
#include "components/settings/Settings.h"

namespace Pinetime {
namespace Applications {
Expand All @@ -10,15 +11,17 @@ namespace Pinetime {
void Create(lv_obj_t* parent);

void SetColor(lv_color_t);
void SetBatteryPercentage(uint8_t percentage);
void SetBatteryPercentage(uint8_t percentage, bool show_percentage);
lv_obj_t* GetObject();

static const char* GetUnknownIcon();
static const char* GetPlugIcon(bool isCharging);

private:
lv_obj_t* batteryContainer;
lv_obj_t* batteryImg;
lv_obj_t* batteryJuice;
lv_obj_t* batteryPercentageText;
};
}
}
Expand Down
37 changes: 31 additions & 6 deletions src/displayapp/screens/BatteryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@

using namespace Pinetime::Applications::Screens;

BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Battery& batteryController)
: Screen(app), batteryController {batteryController} {
namespace {
void event_handler(lv_obj_t* obj, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
auto* battery = static_cast<BatteryInfo*>(obj->user_data);
battery->ToggleBatteryPercentState();
}
}
}

BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::Battery& batteryController,
Pinetime::Controllers::Settings& settingsController)
: Screen(app), batteryController {batteryController}, settingsController {settingsController} {

batteryPercent = batteryController.PercentRemaining();
batteryVoltage = batteryController.Voltage();

charging_bar = lv_bar_create(lv_scr_act(), nullptr);
lv_obj_set_size(charging_bar, 200, 15);
lv_bar_set_range(charging_bar, 0, 100);
lv_obj_align(charging_bar, nullptr, LV_ALIGN_CENTER, 0, 10);
lv_obj_align(charging_bar, nullptr, LV_ALIGN_CENTER, 0, -30);
lv_bar_set_anim_time(charging_bar, 1000);
lv_obj_set_style_local_radius(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, lv_color_hex(0x222222));
Expand All @@ -27,22 +38,31 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont
lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);

percent = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT);
lv_obj_align(percent, nullptr, LV_ALIGN_CENTER, 0, -60);
lv_obj_align(percent, nullptr, LV_ALIGN_CENTER, 0, -70);

voltage = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(voltage, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0));
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
lv_label_set_align(voltage, LV_LABEL_ALIGN_CENTER);
lv_obj_align(voltage, nullptr, LV_ALIGN_CENTER, 0, 95);
lv_obj_align(voltage, nullptr, LV_ALIGN_CENTER, 0, 55);

show_percentage_checkbox = lv_checkbox_create(lv_scr_act(), nullptr);
lv_checkbox_set_text(show_percentage_checkbox, "Show %");
lv_obj_align(show_percentage_checkbox, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -5);
lv_obj_add_state(show_percentage_checkbox, LV_STATE_DEFAULT);
lv_checkbox_set_checked(show_percentage_checkbox, settingsController.GetShowBatteryPercentage());
show_percentage_checkbox->user_data = this;
lv_obj_set_event_cb(show_percentage_checkbox, event_handler);

taskRefresh = lv_task_create(RefreshTaskCallback, 5000, LV_TASK_PRIO_MID, this);
Refresh();
}

BatteryInfo::~BatteryInfo() {
settingsController.SaveSettings();
lv_task_del(taskRefresh);
lv_obj_clean(lv_scr_act());
}
Expand Down Expand Up @@ -72,3 +92,8 @@ void BatteryInfo::Refresh() {
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
}

void BatteryInfo::ToggleBatteryPercentState() {
settingsController.SetShowBatteryPercentage(!settingsController.GetShowBatteryPercentage());
lv_checkbox_set_checked(show_percentage_checkbox, settingsController.GetShowBatteryPercentage());
}
8 changes: 7 additions & 1 deletion src/displayapp/screens/BatteryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include "displayapp/screens/Screen.h"
#include "components/settings/Settings.h"
#include <lvgl/lvgl.h>

namespace Pinetime {
Expand All @@ -14,14 +15,19 @@ namespace Pinetime {

class BatteryInfo : public Screen {
public:
BatteryInfo(DisplayApp* app, Pinetime::Controllers::Battery& batteryController);
BatteryInfo(DisplayApp* app,
Pinetime::Controllers::Battery& batteryController,
Pinetime::Controllers::Settings& settingsController);
~BatteryInfo() override;

void Refresh() override;
void ToggleBatteryPercentState();

private:
Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::Settings& settingsController;

lv_obj_t* show_percentage_checkbox;
lv_obj_t* voltage;
lv_obj_t* percent;
lv_obj_t* charging_bar;
Expand Down
8 changes: 6 additions & 2 deletions src/displayapp/screens/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ Tile::Tile(uint8_t screenID,
Pinetime::Controllers::Battery& batteryController,
Controllers::DateTime& dateTimeController,
std::array<Applications, 6>& applications)
: Screen(app), batteryController {batteryController}, dateTimeController {dateTimeController}, pageIndicator(screenID, numScreens) {
: Screen(app),
batteryController {batteryController},
settingsController(settingsController),
dateTimeController {dateTimeController},
pageIndicator(screenID, numScreens) {

settingsController.SetAppMenu(screenID);

Expand Down Expand Up @@ -93,7 +97,7 @@ Tile::~Tile() {

void Tile::UpdateScreen() {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining());
batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining(), settingsController.GetShowBatteryPercentage());
}

void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) {
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Pinetime {

private:
Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::Settings& settingsController;
Controllers::DateTime& dateTimeController;

lv_task_t* taskUpdate;
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/WatchFaceAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void WatchFaceAnalog::UpdateClock() {

void WatchFaceAnalog::SetBatteryIcon() {
auto batteryPercent = batteryPercentRemaining.Get();
batteryIcon.SetBatteryPercentage(batteryPercent);
batteryIcon.SetBatteryPercentage(batteryPercent, settingsController.GetShowBatteryPercentage());
}

void WatchFaceAnalog::Refresh() {
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/WatchFaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void WatchFaceDigital::Refresh() {
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
batteryIcon.SetBatteryPercentage(batteryPercent);
batteryIcon.SetBatteryPercentage(batteryPercent, settingsController.GetShowBatteryPercentage());
}

bleState = bleController.IsConnected();
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/WatchFacePineTimeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ bool WatchFacePineTimeStyle::OnButtonPushed() {

void WatchFacePineTimeStyle::SetBatteryIcon() {
auto batteryPercent = batteryPercentRemaining.Get();
batteryIcon.SetBatteryPercentage(batteryPercent);
batteryIcon.SetBatteryPercentage(batteryPercent, settingsController.GetShowBatteryPercentage());
}

void WatchFacePineTimeStyle::AlignIcons() {
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/settings/QuickSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ QuickSettings::~QuickSettings() {

void QuickSettings::UpdateScreen() {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining());
batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining(), settingsController.GetShowBatteryPercentage());
}

void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
Expand Down