Skip to content

Commit

Permalink
Move the time remaining widget to StatusIcons
Browse files Browse the repository at this point in the history
  • Loading branch information
JustScott committed Oct 9, 2024
1 parent 247f6a4 commit 0cdbac0
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 40 deletions.
4 changes: 3 additions & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
batteryController,
bleController,
dateTimeController,
timer,
filesystem,
std::move(apps));
} break;
Expand Down Expand Up @@ -558,7 +559,8 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
brightnessController,
motorController,
settingsController,
bleController);
bleController,
timer);
break;
case Apps::Settings:
currentScreen = std::make_unique<Screens::Settings>(this, settingsController);
Expand Down
5 changes: 4 additions & 1 deletion src/displayapp/screens/ApplicationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ ApplicationList::ApplicationList(DisplayApp* app,
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
Controllers::Timer& timer,
Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps)
: app {app},
settingsController {settingsController},
batteryController {batteryController},
bleController {bleController},
dateTimeController {dateTimeController},
timer {timer},
filesystem {filesystem},
apps {std::move(apps)},
screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
Expand Down Expand Up @@ -60,5 +62,6 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) co
batteryController,
bleController,
dateTimeController,
pageApps);
pageApps,
timer);
}
2 changes: 2 additions & 0 deletions src/displayapp/screens/ApplicationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Pinetime {
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
Pinetime::Controllers::Timer& timer,
Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps);
~ApplicationList() override;
Expand All @@ -33,6 +34,7 @@ namespace Pinetime {
const Pinetime::Controllers::Battery& batteryController;
const Pinetime::Controllers::Ble& bleController;
Controllers::DateTime& dateTimeController;
Pinetime::Controllers::Timer& timer;
Pinetime::Controllers::FS& filesystem;
std::array<Tile::Applications, UserAppTypes::Count> apps;

Expand Down
7 changes: 4 additions & 3 deletions src/displayapp/screens/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ Tile::Tile(uint8_t screenID,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
std::array<Applications, 6>& applications)
: app {app}, dateTimeController {dateTimeController}, pageIndicator(screenID, numScreens), statusIcons(batteryController, bleController) {
std::array<Applications, 6>& applications,
Controllers::Timer& timer)
: app {app}, dateTimeController {dateTimeController}, pageIndicator(screenID, numScreens), statusIcons(batteryController, bleController, timer) {

settingsController.SetAppMenu(screenID);

Expand Down Expand Up @@ -83,7 +84,7 @@ 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);
taskUpdate = lv_task_create(lv_update_task, 500, LV_TASK_PRIO_MID, this);

UpdateScreen();
}
Expand Down
3 changes: 2 additions & 1 deletion src/displayapp/screens/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace Pinetime {
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
std::array<Applications, 6>& applications);
std::array<Applications, 6>& applications,
Controllers::Timer& timer);

~Tile() override;

Expand Down
26 changes: 1 addition & 25 deletions src/displayapp/screens/WatchFaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
motionController {motionController},
weatherService {weatherService},
timer {timer},
statusIcons(batteryController, bleController) {
statusIcons(batteryController, bleController, timer) {

statusIcons.Create();

Expand All @@ -53,16 +53,6 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
lv_label_set_text(temperature, "");
lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 50);

timerIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(timerIcon, Symbols::hourGlass);
lv_obj_set_style_local_text_color(timerIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
lv_obj_align(timerIcon, lv_scr_act(), LV_ALIGN_IN_TOP_MID, -32, 60);

timeRemaining = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(timeRemaining, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
lv_label_set_text(timeRemaining, "00:00");
lv_obj_align(timeRemaining, nullptr, LV_ALIGN_IN_TOP_MID, 10, 60);

label_date = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
Expand Down Expand Up @@ -113,20 +103,6 @@ void WatchFaceDigital::Refresh() {
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
}

if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());

uint8_t minutes = secondsRemaining.count() / 60;
uint8_t seconds = secondsRemaining.count() % 60;
lv_label_set_text_fmt(timeRemaining, "%02d:%02d", minutes, seconds);

lv_obj_set_hidden(timeRemaining, false);
lv_obj_set_hidden(timerIcon, false);
} else {
lv_obj_set_hidden(timeRemaining, true);
lv_obj_set_hidden(timerIcon, true);
}

currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());

if (currentDateTime.IsUpdated()) {
Expand Down
2 changes: 0 additions & 2 deletions src/displayapp/screens/WatchFaceDigital.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ namespace Pinetime {

Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;

lv_obj_t* timerIcon;
lv_obj_t* timeRemaining;
lv_obj_t* label_time;
lv_obj_t* label_time_ampm;
lv_obj_t* label_date;
Expand Down
7 changes: 4 additions & 3 deletions src/displayapp/screens/settings/QuickSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
Controllers::BrightnessController& brightness,
Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController,
const Controllers::Ble& bleController)
const Controllers::Ble& bleController,
Controllers::Timer& timer)
: app {app},
dateTimeController {dateTimeController},
brightness {brightness},
motorController {motorController},
settingsController {settingsController},
statusIcons(batteryController, bleController) {
statusIcons(batteryController, bleController, timer) {

statusIcons.Create();

Expand Down Expand Up @@ -118,7 +119,7 @@ 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);
taskUpdate = lv_task_create(lv_update_task, 500, LV_TASK_PRIO_MID, this);

UpdateScreen();
}
Expand Down
3 changes: 2 additions & 1 deletion src/displayapp/screens/settings/QuickSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace Pinetime {
Controllers::BrightnessController& brightness,
Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController,
const Controllers::Ble& bleController);
const Controllers::Ble& bleController,
Controllers::Timer& timer);

~QuickSettings() override;

Expand Down
29 changes: 27 additions & 2 deletions src/displayapp/widgets/StatusIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@

using namespace Pinetime::Applications::Widgets;

StatusIcons::StatusIcons(const Controllers::Battery& batteryController, const Controllers::Ble& bleController)
: batteryIcon(true), batteryController {batteryController}, bleController {bleController} {
StatusIcons::StatusIcons(const Controllers::Battery& batteryController, const Controllers::Ble& bleController, Controllers::Timer& timer)
: batteryIcon(true), batteryController {batteryController}, bleController {bleController}, timer {timer} {
}

void StatusIcons::Create() {
timerIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(timerIcon, Screens::Symbols::hourGlass);
lv_obj_set_style_local_text_color(timerIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
lv_obj_align(timerIcon, lv_scr_act(), LV_ALIGN_IN_TOP_MID, -32, 0);

timeRemaining = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(timeRemaining, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
lv_label_set_text(timeRemaining, "00:00");
lv_obj_align(timeRemaining, nullptr, LV_ALIGN_IN_TOP_MID, 10, 0);


container = lv_cont_create(lv_scr_act(), nullptr);
lv_cont_set_layout(container, LV_LAYOUT_ROW_TOP);
lv_cont_set_fit(container, LV_FIT_TIGHT);
Expand All @@ -26,6 +37,20 @@ void StatusIcons::Create() {
}

void StatusIcons::Update() {
if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());

uint8_t minutes = secondsRemaining.count() / 60;
uint8_t seconds = secondsRemaining.count() % 60;
lv_label_set_text_fmt(timeRemaining, "%02d:%02d", minutes, seconds);

lv_obj_set_hidden(timeRemaining, false);
lv_obj_set_hidden(timerIcon, false);
} else {
lv_obj_set_hidden(timeRemaining, true);
lv_obj_set_hidden(timerIcon, true);
}

powerPresent = batteryController.IsPowerPresent();
if (powerPresent.IsUpdated()) {
lv_obj_set_hidden(batteryPlug, !powerPresent.Get());
Expand Down
5 changes: 4 additions & 1 deletion src/displayapp/widgets/StatusIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Pinetime {
namespace Widgets {
class StatusIcons {
public:
StatusIcons(const Controllers::Battery& batteryController, const Controllers::Ble& bleController);
StatusIcons(const Controllers::Battery& batteryController, const Controllers::Ble& bleController, Controllers::Timer& timer);
void Align();
void Create();

Expand All @@ -27,12 +27,15 @@ namespace Pinetime {
Screens::BatteryIcon batteryIcon;
const Pinetime::Controllers::Battery& batteryController;
const Controllers::Ble& bleController;
Controllers::Timer& timer;

Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
Utility::DirtyValue<bool> powerPresent {};
Utility::DirtyValue<bool> bleState {};
Utility::DirtyValue<bool> bleRadioEnabled {};

lv_obj_t* timerIcon;
lv_obj_t* timeRemaining;
lv_obj_t* bleIcon;
lv_obj_t* batteryPlug;
lv_obj_t* container;
Expand Down

0 comments on commit 0cdbac0

Please sign in to comment.