Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add battery percentage & colouring #631

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingDisplay.cpp
displayapp/screens/settings/SettingSteps.cpp
displayapp/screens/settings/SettingPineTimeStyle.cpp
displayapp/screens/settings/SettingBatteryFormat.cpp

## Watch faces
displayapp/icons/bg_clock.c
Expand Down
24 changes: 24 additions & 0 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Pinetime {
public:
enum class ClockType : uint8_t { H24, H12 };
enum class Vibration : uint8_t { ON, OFF };
enum class BatteryPercentage : u_int8_t { ON, OFF };
enum class BatteryColor : u_int8_t { ON, OFF };
enum class WakeUpMode : uint8_t {
SingleTap = 0,
DoubleTap = 1,
Expand Down Expand Up @@ -103,6 +105,26 @@ namespace Pinetime {
return settings.vibrationStatus;
};

void SetBatteryPercentageStatus(BatteryPercentage status) {
if (status != settings.batteryPercentageStatus) {
settingsChanged = true;
}
settings.batteryPercentageStatus = status;
};
BatteryPercentage GetBatteryPercentageStatus() const {
return settings.batteryPercentageStatus;
};

void SetBatteryColorStatus(BatteryColor status) {
if (status != settings.batteryColorStatus) {
settingsChanged = true;
}
settings.batteryColorStatus = status;
};
BatteryColor GetBatteryColorStatus() const {
return settings.batteryColorStatus;
};

void SetScreenTimeOut(uint32_t timeout) {
if (timeout != settings.screenTimeOut) {
settingsChanged = true;
Expand Down Expand Up @@ -171,6 +193,8 @@ namespace Pinetime {

ClockType clockType = ClockType::H24;
Vibration vibrationStatus = Vibration::ON;
BatteryPercentage batteryPercentageStatus = BatteryPercentage::OFF;
BatteryColor batteryColorStatus = BatteryColor::OFF;

uint8_t clockFace = 0;

Expand Down
3 changes: 2 additions & 1 deletion src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Pinetime {
SettingDisplay,
SettingWakeUp,
SettingSteps,
SettingPineTimeStyle
SettingPineTimeStyle,
SettingBatteryFormat
};
}
}
5 changes: 5 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "displayapp/screens/settings/SettingDisplay.h"
#include "displayapp/screens/settings/SettingSteps.h"
#include "displayapp/screens/settings/SettingPineTimeStyle.h"
#include "displayapp/screens/settings/SettingBatteryFormat.h"

#include "libs/lv_conf.h"

Expand Down Expand Up @@ -382,6 +383,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
currentScreen = std::make_unique<Screens::SettingPineTimeStyle>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingBatteryFormat:
currentScreen = std::make_unique<Screens::SettingBatteryFormat>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::BatteryInfo:
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
Expand Down
15 changes: 15 additions & 0 deletions src/displayapp/screens/BatteryIcon.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cstdint>
#include <lvgl/lvgl.h>
#include "BatteryIcon.h"
#include "Symbols.h"

Expand All @@ -20,6 +21,20 @@ const char* BatteryIcon::GetUnknownIcon() {
return Symbols::batteryEmpty;
}

const lv_color_t BatteryIcon::GetBatteryColor(uint8_t batteryPercent) {
if (batteryPercent > 75)
return LV_COLOR_GREEN;
if (batteryPercent > 50)
return LV_COLOR_YELLOW;
if (batteryPercent > 25)
return LV_COLOR_ORANGE;
return LV_COLOR_RED;
}

const lv_color_t BatteryIcon::GetDefaultBatteryColor() {
return LV_COLOR_WHITE;
}

const char* BatteryIcon::GetPlugIcon(bool isCharging) {
if (isCharging)
return Symbols::plug;
Expand Down
2 changes: 2 additions & 0 deletions src/displayapp/screens/BatteryIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Pinetime {
public:
static const char* GetUnknownIcon();
static const char* GetBatteryIcon(uint8_t batteryPercent);
static const lv_color_t GetBatteryColor(uint8_t batteryPercent);
static const lv_color_t GetDefaultBatteryColor();
static const char* GetPlugIcon(bool isCharging);
};
}
Expand Down
16 changes: 16 additions & 0 deletions src/displayapp/screens/WatchFaceAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app,
lv_label_set_text(batteryIcon, Symbols::batteryHalf);
lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);

batteryValue = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(batteryValue, "");
lv_obj_align(batteryValue, NULL, LV_ALIGN_IN_TOP_LEFT, 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));
lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false));
Expand Down Expand Up @@ -181,6 +185,18 @@ void WatchFaceAnalog::Refresh() {
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));

if (settingsController.GetBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetBatteryColor(batteryPercent));
} else {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetDefaultBatteryColor());
}

if (settingsController.GetBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) {
lv_label_set_text_fmt(batteryValue, "%lu", batteryPercent);
} else {
lv_label_set_text(batteryValue, "");
}
}

notificationState = notificationManager.AreNewNotificationsAvailable();
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/WatchFaceAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace Pinetime {

lv_obj_t* label_date_day;
lv_obj_t* batteryIcon;
lv_obj_t* batteryValue;
lv_obj_t* notificationIcon;

Controllers::DateTime& dateTimeController;
Expand Down
22 changes: 20 additions & 2 deletions src/displayapp/screens/WatchFaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
lv_label_set_text(batteryIcon, Symbols::batteryFull);
lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);

batteryValue = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(batteryValue, "");
lv_obj_align(batteryValue, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 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(batteryPlug, Symbols::plug);
lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0);
lv_obj_align(batteryPlug, batteryValue, 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(0x0000FF));
Expand Down Expand Up @@ -106,6 +110,19 @@ void WatchFaceDigital::Refresh() {
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));

if (settingsController.GetBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetBatteryColor(batteryPercent));
} else {
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetDefaultBatteryColor());
}

if (settingsController.GetBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) {
lv_label_set_text_fmt(batteryValue, "%lu", batteryPercent);
This conversation was marked as resolved.
Show resolved Hide resolved
} else {
lv_label_set_text(batteryValue, "");
}

auto isCharging = batteryController.IsCharging() or batteryController.IsPowerPresent();
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging));
}
Expand All @@ -115,7 +132,8 @@ void WatchFaceDigital::Refresh() {
lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get()));
}
lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0);
lv_obj_align(batteryValue, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0);
lv_obj_align(batteryPlug, batteryValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0);

notificationState = notificatioManager.AreNewNotificationsAvailable();
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/WatchFaceDigital.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Pinetime {
lv_obj_t* label_date;
lv_obj_t* backgroundLabel;
lv_obj_t* batteryIcon;
lv_obj_t* batteryValue;
lv_obj_t* bleIcon;
lv_obj_t* batteryPlug;
lv_obj_t* heartbeatIcon;
Expand Down
95 changes: 95 additions & 0 deletions src/displayapp/screens/settings/SettingBatteryFormat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "SettingBatteryFormat.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"

using namespace Pinetime::Applications::Screens;

namespace {
static void event_handler(lv_obj_t* obj, lv_event_t event) {
SettingBatteryFormat* screen = static_cast<SettingBatteryFormat*>(obj->user_data);
screen->UpdateSelected(obj, event);
}
}

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

lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);

lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);

lv_obj_set_pos(container1, 10, 60);
lv_obj_set_width(container1, LV_HOR_RES - 20);
lv_obj_set_height(container1, LV_VER_RES - 50);
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);

lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Battery style");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);

lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
lv_label_set_text_static(icon, Symbols::batteryThreeQuarter);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);

optionsTotal = 0;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Show percent");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}

optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Colorful icon");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
}

SettingBatteryFormat::~SettingBatteryFormat() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

void SettingBatteryFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
int index = 0;
for (; index < optionsTotal; ++index) {
if (cbOption[index] == object) {
break;
}
}

if (index == 0) {
if (settingsController.GetBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) {
settingsController.SetBatteryPercentageStatus(Controllers::Settings::BatteryPercentage::OFF);
lv_checkbox_set_checked(cbOption[index], false);
} else {
settingsController.SetBatteryPercentageStatus(Controllers::Settings::BatteryPercentage::ON);
lv_checkbox_set_checked(cbOption[index], true);
}
};
if (index == 1) {
if (settingsController.GetBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) {
settingsController.SetBatteryColorStatus(Controllers::Settings::BatteryColor::OFF);
lv_checkbox_set_checked(cbOption[index], false);
} else {
settingsController.SetBatteryColorStatus(Controllers::Settings::BatteryColor::ON);
lv_checkbox_set_checked(cbOption[index], true);
}
};
}
}
27 changes: 27 additions & 0 deletions src/displayapp/screens/settings/SettingBatteryFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

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

namespace Pinetime {

namespace Applications {
namespace Screens {

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

void UpdateSelected(lv_obj_t* object, lv_event_t event);

private:
Controllers::Settings& settingsController;
uint8_t optionsTotal;
lv_obj_t* cbOption[1];
};
}
}
}
6 changes: 3 additions & 3 deletions src/displayapp/screens/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
std::array<Screens::List::Applications, 4> applications {{
{Symbols::shoe, "Steps", Apps::SettingSteps},
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
{Symbols::batteryThreeQuarter, "Battery style", Apps::SettingBatteryFormat},
{Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle},
{Symbols::check, "Firmware", Apps::FirmwareValidation},
}};

return std::make_unique<Screens::List>(1, 3, app, settingsController, applications);
Expand All @@ -60,10 +60,10 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
std::unique_ptr<Screen> Settings::CreateScreen3() {

std::array<Screens::List::Applications, 4> applications {{
{Symbols::check, "Firmware", Apps::FirmwareValidation},
{Symbols::list, "About", Apps::SysInfo},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None}
}};

return std::make_unique<Screens::List>(2, 3, app, settingsController, applications);
Expand Down