2021-10-13 22:08:35 +02:00
|
|
|
#include "displayapp/screens/WatchFaceDigital.h"
|
2021-02-24 20:40:24 +01:00
|
|
|
|
|
|
|
#include <date/date.h>
|
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
#include <cstdio>
|
2021-10-13 22:08:35 +02:00
|
|
|
#include "displayapp/screens/BatteryIcon.h"
|
|
|
|
#include "displayapp/screens/BleIcon.h"
|
|
|
|
#include "displayapp/screens/NotificationIcon.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
2021-02-24 20:40:24 +01:00
|
|
|
#include "components/battery/BatteryController.h"
|
|
|
|
#include "components/ble/BleController.h"
|
|
|
|
#include "components/ble/NotificationManager.h"
|
|
|
|
#include "components/heartrate/HeartRateController.h"
|
2021-03-31 19:47:27 +02:00
|
|
|
#include "components/motion/MotionController.h"
|
2021-11-21 22:48:28 +01:00
|
|
|
#include "components/settings/Settings.h"
|
2021-02-24 20:40:24 +01:00
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
|
2021-04-18 19:28:14 +02: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},
|
|
|
|
batteryController {batteryController},
|
|
|
|
bleController {bleController},
|
|
|
|
notificatioManager {notificatioManager},
|
|
|
|
settingsController {settingsController},
|
|
|
|
heartRateController {heartRateController},
|
|
|
|
motionController {motionController} {
|
2021-02-24 20:40:24 +01:00
|
|
|
settingsController.SetClockFace(0);
|
|
|
|
|
|
|
|
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_text(batteryIcon, Symbols::batteryFull);
|
2021-06-13 11:47:12 +02:00
|
|
|
lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
2021-02-24 20:40:24 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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));
|
|
|
|
lv_label_set_text(bleIcon, Symbols::bluetooth);
|
|
|
|
lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
|
|
|
|
2021-07-24 13:01:11 +02:00
|
|
|
notificationIcon = lv_label_create(lv_scr_act(), nullptr);
|
2021-02-24 20:40:24 +01:00
|
|
|
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));
|
2021-06-13 11:47:12 +02:00
|
|
|
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
2021-02-24 20:40:24 +01: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 19:28:14 +02: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 20:40:24 +01: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 19:28:14 +02:00
|
|
|
lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55);
|
|
|
|
|
2021-02-24 20:40:24 +01:00
|
|
|
backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_click(backgroundLabel, true);
|
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text(backgroundLabel, "");
|
|
|
|
|
|
|
|
heartbeatIcon = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_text(heartbeatIcon, Symbols::heartBeat);
|
|
|
|
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
|
2021-06-13 11:47:12 +02:00
|
|
|
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
2021-02-24 20:40:24 +01: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));
|
2021-04-30 22:55:42 +02:00
|
|
|
lv_label_set_text(heartbeatValue, "");
|
2021-02-24 20:40:24 +01: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));
|
|
|
|
lv_label_set_text(stepValue, "0");
|
2021-06-13 11:47:12 +02:00
|
|
|
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
2021-02-24 20:40:24 +01: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));
|
|
|
|
lv_label_set_text(stepIcon, Symbols::shoe);
|
|
|
|
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
2021-07-19 15:26:12 +02:00
|
|
|
|
2021-07-19 16:06:20 +02:00
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
2021-07-19 15:26:12 +02:00
|
|
|
Refresh();
|
2021-02-24 20:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WatchFaceDigital::~WatchFaceDigital() {
|
2021-07-19 15:26:12 +02:00
|
|
|
lv_task_del(taskRefresh);
|
2021-02-24 20:40:24 +01:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-07-19 15:26:12 +02:00
|
|
|
void WatchFaceDigital::Refresh() {
|
2021-09-22 12:58:45 +02:00
|
|
|
powerPresent = batteryController.IsPowerPresent();
|
|
|
|
if (powerPresent.IsUpdated()) {
|
|
|
|
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(powerPresent.Get()));
|
2021-09-03 13:35:38 +02:00
|
|
|
}
|
|
|
|
|
2021-02-24 20:40:24 +01:00
|
|
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
|
|
|
if (batteryPercentRemaining.IsUpdated()) {
|
|
|
|
auto batteryPercent = batteryPercentRemaining.Get();
|
2021-09-03 13:35:38 +02:00
|
|
|
if (batteryPercent == 100) {
|
|
|
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
|
|
|
} else {
|
|
|
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
|
|
}
|
2021-02-24 20:40:24 +01:00
|
|
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
|
|
|
}
|
|
|
|
|
|
|
|
bleState = bleController.IsConnected();
|
|
|
|
if (bleState.IsUpdated()) {
|
2021-07-24 13:01:11 +02:00
|
|
|
lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get()));
|
2021-02-24 20:40:24 +01:00
|
|
|
}
|
2021-06-13 11:47:12 +02:00
|
|
|
lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
2021-02-24 20:40:24 +01:00
|
|
|
lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
|
|
|
lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
|
|
|
|
|
|
|
notificationState = notificatioManager.AreNewNotificationsAvailable();
|
2021-04-18 19:28:14 +02:00
|
|
|
if (notificationState.IsUpdated()) {
|
2021-07-24 13:01:11 +02:00
|
|
|
lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
|
2021-02-24 20:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
currentDateTime = dateTimeController.CurrentDateTime();
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
if (currentDateTime.IsUpdated()) {
|
2021-02-24 20:40:24 +01:00
|
|
|
auto newDateTime = currentDateTime.Get();
|
|
|
|
|
|
|
|
auto dp = date::floor<date::days>(newDateTime);
|
2021-04-18 19:28:14 +02:00
|
|
|
auto time = date::make_time(newDateTime - dp);
|
2021-02-24 20:40:24 +01:00
|
|
|
auto yearMonthDay = date::year_month_day(dp);
|
|
|
|
|
2021-07-24 13:01:11 +02: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 20:40:24 +01:00
|
|
|
auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding());
|
|
|
|
|
|
|
|
int hour = time.hours().count();
|
|
|
|
auto minute = time.minutes().count();
|
|
|
|
|
|
|
|
char minutesChar[3];
|
|
|
|
sprintf(minutesChar, "%02d", static_cast<int>(minute));
|
|
|
|
|
|
|
|
char hoursChar[3];
|
|
|
|
char ampmChar[3];
|
2021-04-18 19:28:14 +02:00
|
|
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
|
2021-02-24 20:40:24 +01:00
|
|
|
sprintf(hoursChar, "%02d", hour);
|
|
|
|
} else {
|
2021-03-08 13:23:32 +01:00
|
|
|
if (hour == 0 && hour != 12) {
|
2021-04-18 19:28:14 +02:00
|
|
|
hour = 12;
|
|
|
|
sprintf(ampmChar, "AM");
|
|
|
|
} else if (hour == 12 && hour != 0) {
|
|
|
|
hour = 12;
|
|
|
|
sprintf(ampmChar, "PM");
|
|
|
|
} else if (hour < 12 && hour != 0) {
|
|
|
|
sprintf(ampmChar, "AM");
|
|
|
|
} else if (hour > 12 && hour != 0) {
|
|
|
|
hour = hour - 12;
|
|
|
|
sprintf(ampmChar, "PM");
|
2021-02-24 20:40:24 +01:00
|
|
|
}
|
|
|
|
sprintf(hoursChar, "%02d", hour);
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:01:11 +02:00
|
|
|
if ((hoursChar[0] != displayedChar[0]) or (hoursChar[1] != displayedChar[1]) or (minutesChar[0] != displayedChar[2]) or
|
|
|
|
(minutesChar[1] != displayedChar[3])) {
|
2021-02-24 20:40:24 +01:00
|
|
|
displayedChar[0] = hoursChar[0];
|
|
|
|
displayedChar[1] = hoursChar[1];
|
|
|
|
displayedChar[2] = minutesChar[0];
|
|
|
|
displayedChar[3] = minutesChar[1];
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
2021-02-24 20:40:24 +01:00
|
|
|
lv_label_set_text(label_time_ampm, ampmChar);
|
2021-04-18 19:28:14 +02:00
|
|
|
if (hoursChar[0] == '0') {
|
|
|
|
hoursChar[0] = ' ';
|
|
|
|
}
|
2021-02-24 20:40:24 +01:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:01:11 +02:00
|
|
|
lv_label_set_text_fmt(label_time, "%s:%s", hoursChar, minutesChar);
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
2021-02-24 20:40:24 +01:00
|
|
|
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
|
|
|
|
} else {
|
|
|
|
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 19:28:14 +02:00
|
|
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
|
2021-07-24 13:01:11 +02:00
|
|
|
lv_label_set_text_fmt(label_date, "%s %d %s %d", dateTimeController.DayOfWeekShortToString(), day, dateTimeController.MonthShortToString(), year);
|
2021-02-24 20:40:24 +01:00
|
|
|
} else {
|
2021-07-24 13:01:11 +02:00
|
|
|
lv_label_set_text_fmt(label_date, "%s %s %d %d", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString(), day, year);
|
2021-02-24 20:40:24 +01:00
|
|
|
}
|
|
|
|
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
|
|
|
|
|
|
|
|
currentYear = year;
|
|
|
|
currentMonth = month;
|
|
|
|
currentDayOfWeek = dayOfWeek;
|
|
|
|
currentDay = day;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
heartbeat = heartRateController.HeartRate();
|
|
|
|
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
|
2021-04-18 19:28:14 +02:00
|
|
|
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
|
2021-04-30 22:55:42 +02: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 19:28:14 +02:00
|
|
|
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
|
2021-04-30 22:55:42 +02: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 19:28:14 +02:00
|
|
|
|
2021-06-13 11:47:12 +02:00
|
|
|
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
2021-02-24 20:40:24 +01:00
|
|
|
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
|
|
|
}
|
|
|
|
|
2021-03-31 19:47:27 +02:00
|
|
|
stepCount = motionController.NbSteps();
|
2021-04-02 16:56:14 +02:00
|
|
|
motionSensorOk = motionController.IsSensorOk();
|
2021-04-18 19:28:14 +02:00
|
|
|
if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) {
|
2021-04-10 20:09:33 +02:00
|
|
|
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
|
2021-06-13 11:47:12 +02:00
|
|
|
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
2021-02-24 20:40:24 +01:00
|
|
|
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
|
|
|
}
|
|
|
|
}
|