Skip to content

Commit

Permalink
WatchFaceAnalog: Use status icons class
Browse files Browse the repository at this point in the history
Instead of recreating the status icons for BLE and battery, we can reuse
the StatusIcon class to automatically display them.
  • Loading branch information
vkareh committed Jan 15, 2024
1 parent 264b5be commit 1868c88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 65 deletions.
54 changes: 5 additions & 49 deletions src/displayapp/screens/WatchFaceAnalog.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "displayapp/screens/WatchFaceAnalog.h"
#include <cmath>
#include <lvgl/lvgl.h>
#include "displayapp/screens/BatteryIcon.h"
#include "displayapp/screens/BleIcon.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/NotificationIcon.h"
#include "components/settings/Settings.h"
Expand Down Expand Up @@ -47,12 +45,12 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController)
: currentDateTime {{}},
batteryIcon(true),
dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},
notificationManager {notificationManager},
settingsController {settingsController} {
settingsController {settingsController},
statusIcons(batteryController, bleController) {

statusIcons.Create();

sHour = 99;
sMinute = 99;
Expand Down Expand Up @@ -94,17 +92,6 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
lv_obj_set_pos(twelve, 110, 10);
lv_obj_set_style_local_text_color(twelve, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA);

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_align(plugIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);

bleIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(bleIcon, "");
lv_obj_align(bleIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -30, 0);

notificationIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME);
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
Expand Down Expand Up @@ -213,41 +200,10 @@ void WatchFaceAnalog::UpdateClock() {
}
}

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

void WatchFaceAnalog::Refresh() {
isCharging = batteryController.IsCharging();
if (isCharging.IsUpdated()) {
if (isCharging.Get()) {
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();
}
}
if (!isCharging.Get()) {
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
SetBatteryIcon();
}
}

bleState = bleController.IsConnected();
if (bleState.IsUpdated()) {
if (bleState.Get()) {
lv_label_set_text_static(bleIcon, Symbols::bluetooth);
} else {
lv_label_set_text_static(bleIcon, "");
}
}
statusIcons.Update();

notificationState = notificationManager.AreNewNotificationsAvailable();

if (notificationState.IsUpdated()) {
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
}
Expand Down
20 changes: 4 additions & 16 deletions src/displayapp/screens/WatchFaceAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
#include <memory>
#include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h"
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "displayapp/screens/BatteryIcon.h"
#include "displayapp/widgets/StatusIcons.h"
#include "utility/DirtyValue.h"

namespace Pinetime {
Expand Down Expand Up @@ -38,11 +35,8 @@ namespace Pinetime {
private:
uint8_t sHour, sMinute, sSecond;

Utility::DirtyValue<uint8_t> batteryPercentRemaining {0};
Utility::DirtyValue<bool> isCharging {};
Utility::DirtyValue<bool> bleState {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
Utility::DirtyValue<bool> notificationState {false};
Utility::DirtyValue<bool> notificationState {};
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;

Expand Down Expand Up @@ -70,22 +64,16 @@ namespace Pinetime {
lv_style_t second_line_style;

lv_obj_t* label_date_day;
lv_obj_t* plugIcon;
lv_obj_t* notificationIcon;
lv_obj_t* bleIcon;

BatteryIcon batteryIcon;

const Controllers::DateTime& dateTimeController;
const Controllers::Battery& batteryController;
const Controllers::Ble& bleController;
Controllers::DateTime& dateTimeController;
Controllers::NotificationManager& notificationManager;
Controllers::Settings& settingsController;

void UpdateClock();
void SetBatteryIcon();

lv_task_t* taskRefresh;
Widgets::StatusIcons statusIcons;
};
}

Expand Down

0 comments on commit 1868c88

Please sign in to comment.