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
60 changes: 30 additions & 30 deletions src/displayapp/screens/BatteryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,37 @@ using namespace Pinetime::Applications::Screens;

BatteryInfo::BatteryInfo(const Pinetime::Controllers::Battery& batteryController) : batteryController {batteryController} {

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

chargingArc = lv_arc_create(lv_scr_act(), nullptr);
lv_arc_set_rotation(chargingArc, 270);
lv_arc_set_bg_angles(chargingArc, 0, 360);
lv_arc_set_adjustable(chargingArc, false);
lv_obj_set_size(chargingArc, 180, 180);
lv_obj_align(chargingArc, nullptr, LV_ALIGN_CENTER, 0, -30);
lv_arc_set_value(chargingArc, batteryPercent);
lv_obj_set_style_local_bg_opa(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, LV_OPA_0);
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, Colors::bgAlt);
lv_obj_set_style_local_border_width(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 2);
lv_obj_set_style_local_radius(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0);
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME);

status = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(status, "Reading Battery status");
lv_label_set_align(status, LV_LABEL_ALIGN_CENTER);
lv_obj_align(status, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -17);
lv_obj_align(status, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -33);
lv_obj_set_auto_realign(status, true);

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_42);
lv_label_set_text_fmt(percent, "%i%%", batteryPercent);
lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT);
lv_obj_align(percent, chargingArc, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_auto_realign(percent, true);

voltage = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(voltage, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange);
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_IN_BOTTOM_MID, 0, -7);
lv_obj_set_auto_realign(voltage, true);

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

BatteryInfo::~BatteryInfo() {
Expand All @@ -53,28 +49,32 @@ void BatteryInfo::Refresh() {

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

if (batteryController.IsCharging()) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME);
lv_label_set_text_static(status, "Charging");
} else if (batteryPercent == 100) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
lv_label_set_text_static(status, "Fully charged");
} else if (batteryPercent > 15) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN);
lv_label_set_text_static(status, "Discharging");
} else if (batteryPercent > 5) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
lv_label_set_text_static(status, "Battery low");
} else {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, Colors::deepOrange);
lv_label_set_text_static(status, "Battery critical");
if (batteryPercent.IsUpdated() || batteryCharging.IsUpdated()) {
uint8_t battPercent = batteryPercent.Get();
if (batteryCharging.Get()) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME);
lv_label_set_text_static(status, "Charging");
} else if (battPercent == 100) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
lv_label_set_text_static(status, "Fully charged");
} else if (battPercent > 15) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN);
lv_label_set_text_static(status, "Discharging");
} else if (battPercent > 5) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
lv_label_set_text_static(status, "Battery low");
} else {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, Colors::deepOrange);
lv_label_set_text_static(status, "Battery critical");
}
lv_label_set_text_fmt(percent, "%i%%", battPercent);
lv_arc_set_value(chargingArc, battPercent);
}

lv_label_set_text_fmt(percent, "%i%%", batteryPercent);
lv_obj_align(percent, chargingArc, LV_ALIGN_CENTER, 0, 0);

lv_obj_align(status, voltage, LV_ALIGN_IN_BOTTOM_MID, 0, -27);
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
lv_arc_set_value(chargingArc, batteryPercent);
if (batteryVoltage.IsUpdated()) {
uint16_t battVolts = batteryVoltage.Get();
lv_label_set_text_fmt(voltage, "%1i.%02i volts", battVolts / 1000, battVolts % 1000 / 10);
}
}
6 changes: 4 additions & 2 deletions src/displayapp/screens/BatteryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include "displayapp/screens/Screen.h"
#include <lvgl/lvgl.h>
#include "utility/DirtyValue.h"

namespace Pinetime {
namespace Controllers {
Expand All @@ -29,8 +30,9 @@ namespace Pinetime {

lv_task_t* taskRefresh;

uint8_t batteryPercent = 0;
uint16_t batteryVoltage = 0;
Utility::DirtyValue<uint8_t> batteryPercent {};
Utility::DirtyValue<uint16_t> batteryVoltage {};
Utility::DirtyValue<bool> batteryCharging {};
};
}
}
Expand Down
56 changes: 24 additions & 32 deletions src/displayapp/screens/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ using namespace Pinetime::Applications::Screens;

using Days = Pinetime::Controllers::MotionController::Days;

namespace {
constexpr const char* yesterdayStr = "Yest: %5lu";
}

static void lap_event_handler(lv_obj_t* obj, lv_event_t event) {
auto* steps = static_cast<Steps*>(obj->user_data);
steps->lapBtnEventHandler(event);
Expand All @@ -31,16 +27,11 @@ Steps::Steps(Controllers::MotionController& motionController, Controllers::Setti
lv_arc_set_range(stepsArc, 0, 500);
lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, 0);

stepsCount = motionController.NbSteps();
currentTripSteps = stepsCount - motionController.GetTripSteps();

lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal()));

lSteps = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME);
lv_obj_set_style_local_text_font(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_label_set_text_fmt(lSteps, "%lu", stepsCount);
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
lv_obj_set_auto_realign(lSteps, true);

lv_obj_t* lstepsL = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(lstepsL, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
Expand All @@ -49,15 +40,15 @@ Steps::Steps(Controllers::MotionController& motionController, Controllers::Setti

lStepsYesterday = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(lStepsYesterday, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
lv_label_set_text_fmt(lStepsYesterday, yesterdayStr, motionController.NbSteps(Days::Yesterday));
lv_label_set_align(lStepsYesterday, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lStepsYesterday, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
lv_obj_set_auto_realign(lStepsYesterday, true);

lv_obj_t* lstepsGoal = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(lstepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN);
lv_label_set_text_fmt(lstepsGoal, "Goal: %5lu", settingsController.GetStepsGoal());
lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 40);
lStepsGoal = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(lStepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN);
lv_label_set_align(lStepsGoal, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lStepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 40);
lv_obj_set_auto_realign(lStepsGoal, true);

resetBtn = lv_btn_create(lv_scr_act(), nullptr);
resetBtn->user_data = this;
Expand All @@ -69,14 +60,13 @@ Steps::Steps(Controllers::MotionController& motionController, Controllers::Setti
resetButtonLabel = lv_label_create(resetBtn, nullptr);
lv_label_set_text_static(resetButtonLabel, "Reset");

currentTripSteps = motionController.GetTripSteps();

tripLabel = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(tripLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps);
lv_obj_align(tripLabel, lstepsGoal, LV_ALIGN_IN_LEFT_MID, 0, 20);
lv_obj_align(tripLabel, lStepsGoal, LV_ALIGN_IN_LEFT_MID, 0, 20);
lv_obj_set_auto_realign(tripLabel, true);

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

Steps::~Steps() {
Expand All @@ -87,26 +77,28 @@ Steps::~Steps() {
void Steps::Refresh() {
stepsCount = motionController.NbSteps();
currentTripSteps = motionController.GetTripSteps();
stepsGoal = settingsController.GetStepsGoal();

lv_label_set_text_fmt(lSteps, "%lu", stepsCount);
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);

lv_label_set_text_fmt(lStepsYesterday, yesterdayStr, motionController.NbSteps(Days::Yesterday));
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
if (stepsCount.IsUpdated() || stepsGoal.IsUpdated()) {
lv_label_set_text_fmt(lSteps, "%lu", stepsCount.Get());
lv_label_set_text_fmt(lStepsGoal, "Goal: %5lu", stepsGoal.Get());
lv_label_set_text_fmt(lStepsYesterday, "Yest: %5lu", motionController.NbSteps(Days::Yesterday));
lv_arc_set_value(stepsArc, int16_t(500 * stepsCount.Get() / stepsGoal.Get()));
}

if (currentTripSteps < 100000) {
lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps);
} else {
lv_label_set_text_fmt(tripLabel, "Trip: 99999+");
if (currentTripSteps.IsUpdated()) {
if (currentTripSteps.Get() < 100000) {
lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps.Get());
} else {
lv_label_set_text_fmt(tripLabel, "Trip: 99999+");
}
}
lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal()));
}

void Steps::lapBtnEventHandler(lv_event_t event) {
if (event != LV_EVENT_CLICKED) {
return;
}
stepsCount = motionController.NbSteps();
motionController.ResetTrip();
Refresh();
}
8 changes: 5 additions & 3 deletions src/displayapp/screens/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "displayapp/apps/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
#include "utility/DirtyValue.h"

namespace Pinetime {

Expand All @@ -29,17 +30,18 @@ namespace Pinetime {
Controllers::MotionController& motionController;
Controllers::Settings& settingsController;

uint32_t currentTripSteps = 0;
Utility::DirtyValue<uint32_t> currentTripSteps {};
Utility::DirtyValue<uint32_t> stepsCount {};
Utility::DirtyValue<uint32_t> stepsGoal {};

lv_obj_t* lSteps;
lv_obj_t* lStepsYesterday;
lv_obj_t* lStepsGoal;
lv_obj_t* stepsArc;
lv_obj_t* resetBtn;
lv_obj_t* resetButtonLabel;
lv_obj_t* tripLabel;

uint32_t stepsCount;

lv_task_t* taskRefresh;
};
}
Expand Down
19 changes: 8 additions & 11 deletions src/displayapp/screens/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
using namespace Pinetime::Applications::Screens;

namespace {
void lv_update_task(struct _lv_task_t* task) {
auto* user_data = static_cast<Tile*>(task->user_data);
user_data->UpdateScreen();
}

void event_handler(lv_obj_t* obj, lv_event_t event) {
if (event != LV_EVENT_VALUE_CHANGED) {
return;
Expand Down Expand Up @@ -86,19 +81,21 @@ Tile::Tile(uint8_t screenID,
btnm1->user_data = this;
lv_obj_set_event_cb(btnm1, event_handler);

taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);

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

Tile::~Tile() {
lv_task_del(taskUpdate);
lv_task_del(taskRefresh);
lv_obj_clean(lv_scr_act());
}

void Tile::UpdateScreen() {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
void Tile::Refresh() {
statusIcons.Update();
currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
if (currentDateTime.IsUpdated()) {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
}
}

void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) {
Expand Down
6 changes: 4 additions & 2 deletions src/displayapp/screens/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "components/battery/BatteryController.h"
#include "displayapp/widgets/PageIndicator.h"
#include "displayapp/widgets/StatusIcons.h"
#include "utility/DirtyValue.h"

namespace Pinetime {
namespace Applications {
Expand All @@ -34,14 +35,15 @@ namespace Pinetime {

~Tile() override;

void UpdateScreen();
void Refresh() override;
void OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId);

private:
DisplayApp* app;
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
Controllers::DateTime& dateTimeController;

lv_task_t* taskUpdate;
lv_task_t* taskRefresh;

lv_obj_t* label_time;
lv_obj_t* btnm1;
Expand Down
19 changes: 8 additions & 11 deletions src/displayapp/screens/settings/QuickSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ namespace {
}
}

void lv_update_task(struct _lv_task_t* task) {
auto* user_data = static_cast<QuickSettings*>(task->user_data);
user_data->UpdateScreen();
}

enum class ButtonState : lv_state_t {
NotificationsOn = LV_STATE_CHECKED,
NotificationsOff = LV_STATE_DEFAULT,
Expand Down Expand Up @@ -119,21 +114,23 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
lv_label_set_text_static(lbl_btn, Symbols::settings);

taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);

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

QuickSettings::~QuickSettings() {
lv_style_reset(&btn_style);
lv_task_del(taskUpdate);
lv_task_del(taskRefresh);
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

void QuickSettings::UpdateScreen() {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
void QuickSettings::Refresh() {
statusIcons.Update();
currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
if (currentDateTime.IsUpdated()) {
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
}
}

void QuickSettings::OnButtonEvent(lv_obj_t* object) {
Expand Down
8 changes: 6 additions & 2 deletions src/displayapp/screens/settings/QuickSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "components/settings/Settings.h"
#include "components/battery/BatteryController.h"
#include "displayapp/widgets/StatusIcons.h"
#include "utility/DirtyValue.h"

namespace Pinetime {

Expand All @@ -30,16 +31,19 @@ namespace Pinetime {

void OnButtonEvent(lv_obj_t* object);

void UpdateScreen();
void Refresh() override;

private:
DisplayApp* app;

Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};

Controllers::DateTime& dateTimeController;
Controllers::BrightnessController& brightness;
Controllers::MotorController& motorController;
Controllers::Settings& settingsController;

lv_task_t* taskUpdate;
lv_task_t* taskRefresh;
lv_obj_t* label_time;

lv_style_t btn_style;
Expand Down
Loading