2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/screens/WatchFaceDigital.h"
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
#include <date/date.h>
|
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
#include <cstdio>
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/screens/NotificationIcon.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
2021-02-24 19:40:24 +00:00
|
|
|
#include "components/battery/BatteryController.h"
|
|
|
|
#include "components/ble/BleController.h"
|
|
|
|
#include "components/ble/NotificationManager.h"
|
|
|
|
#include "components/heartrate/HeartRateController.h"
|
2021-03-31 17:47:27 +00:00
|
|
|
#include "components/motion/MotionController.h"
|
2021-11-21 21:48:28 +00:00
|
|
|
#include "components/settings/Settings.h"
|
2022-07-21 16:27:52 +00:00
|
|
|
|
2021-02-24 19:40:24 +00:00
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
|
2021-04-18 17:28:14 +00:00
|
|
|
Controllers::DateTime& dateTimeController,
|
|
|
|
Controllers::Battery& batteryController,
|
|
|
|
Controllers::Ble& bleController,
|
|
|
|
Controllers::NotificationManager& notificatioManager,
|
|
|
|
Controllers::Settings& settingsController,
|
|
|
|
Controllers::HeartRateController& heartRateController,
|
|
|
|
Controllers::MotionController& motionController)
|
|
|
|
: Screen(app),
|
|
|
|
currentDateTime {{}},
|
|
|
|
dateTimeController {dateTimeController},
|
|
|
|
notificatioManager {notificatioManager},
|
|
|
|
settingsController {settingsController},
|
|
|
|
heartRateController {heartRateController},
|
2022-07-21 16:27:52 +00:00
|
|
|
motionController {motionController},
|
|
|
|
statusIcons(batteryController, bleController) {
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2022-07-21 16:27:52 +00:00
|
|
|
statusIcons.Create();
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
notificationIcon = lv_label_create(lv_scr_act(), nullptr);
|
2022-08-16 05:21:23 +00:00
|
|
|
lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME);
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
label_time = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_extrabold_compressed);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
|
|
|
|
|
|
|
|
label_time_ampm = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_text_static(label_time_ampm, "");
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55);
|
|
|
|
|
2021-02-24 19:40:24 +00:00
|
|
|
heartbeatIcon = lv_label_create(lv_scr_act(), nullptr);
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
heartbeatValue = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text_static(heartbeatValue, "");
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
|
|
|
|
|
|
|
stepValue = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text_static(stepValue, "0");
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
stepIcon = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text_static(stepIcon, Symbols::shoe);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
2021-07-19 13:26:12 +00:00
|
|
|
|
2021-07-19 14:06:20 +00:00
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
2021-07-19 13:26:12 +00:00
|
|
|
Refresh();
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WatchFaceDigital::~WatchFaceDigital() {
|
2021-07-19 13:26:12 +00:00
|
|
|
lv_task_del(taskRefresh);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
void WatchFaceDigital::Refresh() {
|
2022-07-21 16:27:52 +00:00
|
|
|
statusIcons.Update();
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
notificationState = notificatioManager.AreNewNotificationsAvailable();
|
2021-04-18 17:28:14 +00:00
|
|
|
if (notificationState.IsUpdated()) {
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentDateTime = dateTimeController.CurrentDateTime();
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (currentDateTime.IsUpdated()) {
|
2021-02-24 19:40:24 +00:00
|
|
|
auto newDateTime = currentDateTime.Get();
|
|
|
|
|
|
|
|
auto dp = date::floor<date::days>(newDateTime);
|
2021-04-18 17:28:14 +00:00
|
|
|
auto time = date::make_time(newDateTime - dp);
|
2021-02-24 19:40:24 +00:00
|
|
|
auto yearMonthDay = date::year_month_day(dp);
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
auto year = static_cast<int>(yearMonthDay.year());
|
|
|
|
auto month = static_cast<Pinetime::Controllers::DateTime::Months>(static_cast<unsigned>(yearMonthDay.month()));
|
|
|
|
auto day = static_cast<unsigned>(yearMonthDay.day());
|
2021-02-24 19:40:24 +00:00
|
|
|
auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding());
|
|
|
|
|
2022-01-20 14:04:26 +00:00
|
|
|
uint8_t hour = time.hours().count();
|
|
|
|
uint8_t minute = time.minutes().count();
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2022-01-20 14:04:26 +00:00
|
|
|
if (displayedHour != hour || displayedMinute != minute) {
|
|
|
|
displayedHour = hour;
|
|
|
|
displayedMinute = minute;
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
2022-01-20 14:04:26 +00:00
|
|
|
char ampmChar[3] = "AM";
|
|
|
|
if (hour == 0) {
|
|
|
|
hour = 12;
|
|
|
|
} else if (hour == 12) {
|
|
|
|
ampmChar[0] = 'P';
|
|
|
|
} else if (hour > 12) {
|
|
|
|
hour = hour - 12;
|
|
|
|
ampmChar[0] = 'P';
|
2021-04-18 17:28:14 +00:00
|
|
|
}
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text(label_time_ampm, ampmChar);
|
|
|
|
lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
|
|
|
|
} else {
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
|
2021-04-18 17:28:14 +00:00
|
|
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
|
2022-05-09 15:16:08 +00:00
|
|
|
lv_label_set_text_fmt(label_date,
|
|
|
|
"%s %d %s %d",
|
|
|
|
dateTimeController.DayOfWeekShortToString(),
|
|
|
|
day,
|
|
|
|
dateTimeController.MonthShortToString(),
|
|
|
|
year);
|
2021-02-24 19:40:24 +00:00
|
|
|
} else {
|
2022-05-09 15:16:08 +00:00
|
|
|
lv_label_set_text_fmt(label_date,
|
|
|
|
"%s %s %d %d",
|
|
|
|
dateTimeController.DayOfWeekShortToString(),
|
|
|
|
dateTimeController.MonthShortToString(),
|
|
|
|
day,
|
|
|
|
year);
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_obj_realign(label_date);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
currentYear = year;
|
|
|
|
currentMonth = month;
|
|
|
|
currentDayOfWeek = dayOfWeek;
|
|
|
|
currentDay = day;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
heartbeat = heartRateController.HeartRate();
|
|
|
|
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
|
2021-04-18 17:28:14 +00:00
|
|
|
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
|
2021-04-30 20:55:42 +00:00
|
|
|
if (heartbeatRunning.Get()) {
|
|
|
|
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
|
2021-04-30 20:55:42 +00:00
|
|
|
} else {
|
|
|
|
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B));
|
|
|
|
lv_label_set_text_static(heartbeatValue, "");
|
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_obj_realign(heartbeatIcon);
|
|
|
|
lv_obj_realign(heartbeatValue);
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 17:47:27 +00:00
|
|
|
stepCount = motionController.NbSteps();
|
2021-04-02 14:56:14 +00:00
|
|
|
motionSensorOk = motionController.IsSensorOk();
|
2021-04-18 17:28:14 +00:00
|
|
|
if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) {
|
2021-04-10 18:09:33 +00:00
|
|
|
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
|
2022-01-20 14:04:26 +00:00
|
|
|
lv_obj_realign(stepValue);
|
|
|
|
lv_obj_realign(stepIcon);
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
}
|