2021-11-03 22:08:57 +00:00
|
|
|
#include <lvgl/lvgl.h>
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/screens/WatchFaceAnalog.h"
|
|
|
|
#include "displayapp/screens/BatteryIcon.h"
|
|
|
|
#include "displayapp/screens/BleIcon.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
|
|
|
#include "displayapp/screens/NotificationIcon.h"
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
LV_IMG_DECLARE(bg_clock);
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-07-11 18:18:07 +00:00
|
|
|
namespace {
|
2021-07-24 11:01:11 +00:00
|
|
|
constexpr int16_t HourLength = 70;
|
|
|
|
constexpr int16_t MinuteLength = 90;
|
|
|
|
constexpr int16_t SecondLength = 110;
|
2021-07-11 18:18:07 +00:00
|
|
|
|
|
|
|
// sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor
|
|
|
|
const auto LV_TRIG_SCALE = _lv_trigo_sin(90);
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
int16_t Cosine(int16_t angle) {
|
2021-07-11 18:18:07 +00:00
|
|
|
return _lv_trigo_sin(angle + 90);
|
|
|
|
}
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
int16_t Sine(int16_t angle) {
|
2021-07-11 18:18:07 +00:00
|
|
|
return _lv_trigo_sin(angle);
|
|
|
|
}
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
int16_t CoordinateXRelocate(int16_t x) {
|
2021-07-11 18:18:07 +00:00
|
|
|
return (x + LV_HOR_RES / 2);
|
|
|
|
}
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
int16_t CoordinateYRelocate(int16_t y) {
|
2021-07-11 18:18:07 +00:00
|
|
|
return std::abs(y - LV_HOR_RES / 2);
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) {
|
2021-07-11 18:18:07 +00:00
|
|
|
return lv_point_t{
|
2021-07-24 11:01:11 +00:00
|
|
|
.x = CoordinateXRelocate(radius * static_cast<int32_t>(Sine(angle)) / LV_TRIG_SCALE),
|
|
|
|
.y = CoordinateYRelocate(radius * static_cast<int32_t>(Cosine(angle)) / LV_TRIG_SCALE)
|
2021-07-11 18:18:07 +00:00
|
|
|
};
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
}
|
2021-07-11 18:18:07 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app,
|
|
|
|
Controllers::DateTime& dateTimeController,
|
|
|
|
Controllers::Battery& batteryController,
|
|
|
|
Controllers::Ble& bleController,
|
2021-06-22 18:34:46 +00:00
|
|
|
Controllers::NotificationManager& notificationManager,
|
2021-04-18 17:28:14 +00:00
|
|
|
Controllers::Settings& settingsController)
|
|
|
|
: Screen(app),
|
|
|
|
currentDateTime {{}},
|
|
|
|
dateTimeController {dateTimeController},
|
|
|
|
batteryController {batteryController},
|
|
|
|
bleController {bleController},
|
2021-06-22 18:34:46 +00:00
|
|
|
notificationManager {notificationManager},
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsController {settingsController} {
|
2021-02-24 19:40:24 +00:00
|
|
|
settingsController.SetClockFace(1);
|
|
|
|
|
|
|
|
sHour = 99;
|
|
|
|
sMinute = 99;
|
2021-04-18 17:28:14 +00:00
|
|
|
sSecond = 99;
|
|
|
|
|
|
|
|
lv_obj_t* bg_clock_img = lv_img_create(lv_scr_act(), NULL);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_img_set_src(bg_clock_img, &bg_clock);
|
|
|
|
lv_obj_align(bg_clock_img, NULL, LV_ALIGN_CENTER, 0, 0);
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_label_set_text(batteryIcon, Symbols::batteryHalf);
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
2021-09-03 11:57:07 +00:00
|
|
|
lv_obj_set_auto_realign(batteryIcon, true);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
notificationIcon = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
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 09:47:12 +00:00
|
|
|
lv_obj_align(notificationIcon, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
// Date - Day / Week day
|
|
|
|
|
|
|
|
label_date_day = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xf0a500));
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day());
|
|
|
|
lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_obj_align(label_date_day, NULL, LV_ALIGN_CENTER, 50, 0);
|
|
|
|
|
2021-02-24 19:40:24 +00:00
|
|
|
minute_body = lv_line_create(lv_scr_act(), NULL);
|
|
|
|
minute_body_trace = lv_line_create(lv_scr_act(), NULL);
|
2021-04-18 17:28:14 +00:00
|
|
|
hour_body = lv_line_create(lv_scr_act(), NULL);
|
|
|
|
hour_body_trace = lv_line_create(lv_scr_act(), NULL);
|
2021-02-24 19:40:24 +00:00
|
|
|
second_body = lv_line_create(lv_scr_act(), NULL);
|
|
|
|
|
|
|
|
lv_style_init(&second_line_style);
|
|
|
|
lv_style_set_line_width(&second_line_style, LV_STATE_DEFAULT, 3);
|
|
|
|
lv_style_set_line_color(&second_line_style, LV_STATE_DEFAULT, LV_COLOR_RED);
|
|
|
|
lv_style_set_line_rounded(&second_line_style, LV_STATE_DEFAULT, true);
|
|
|
|
lv_obj_add_style(second_body, LV_LINE_PART_MAIN, &second_line_style);
|
|
|
|
|
|
|
|
lv_style_init(&minute_line_style);
|
|
|
|
lv_style_set_line_width(&minute_line_style, LV_STATE_DEFAULT, 7);
|
|
|
|
lv_style_set_line_color(&minute_line_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
|
|
lv_style_set_line_rounded(&minute_line_style, LV_STATE_DEFAULT, true);
|
|
|
|
lv_obj_add_style(minute_body, LV_LINE_PART_MAIN, &minute_line_style);
|
|
|
|
|
|
|
|
lv_style_init(&minute_line_style_trace);
|
|
|
|
lv_style_set_line_width(&minute_line_style_trace, LV_STATE_DEFAULT, 3);
|
|
|
|
lv_style_set_line_color(&minute_line_style_trace, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
|
|
lv_style_set_line_rounded(&minute_line_style_trace, LV_STATE_DEFAULT, false);
|
|
|
|
lv_obj_add_style(minute_body_trace, LV_LINE_PART_MAIN, &minute_line_style_trace);
|
|
|
|
|
|
|
|
lv_style_init(&hour_line_style);
|
|
|
|
lv_style_set_line_width(&hour_line_style, LV_STATE_DEFAULT, 7);
|
|
|
|
lv_style_set_line_color(&hour_line_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
|
|
lv_style_set_line_rounded(&hour_line_style, LV_STATE_DEFAULT, true);
|
|
|
|
lv_obj_add_style(hour_body, LV_LINE_PART_MAIN, &hour_line_style);
|
|
|
|
|
|
|
|
lv_style_init(&hour_line_style_trace);
|
|
|
|
lv_style_set_line_width(&hour_line_style_trace, LV_STATE_DEFAULT, 3);
|
|
|
|
lv_style_set_line_color(&hour_line_style_trace, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
|
|
lv_style_set_line_rounded(&hour_line_style_trace, LV_STATE_DEFAULT, false);
|
|
|
|
lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace);
|
|
|
|
|
2021-07-19 14:06:20 +00:00
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
2021-02-24 19:40:24 +00:00
|
|
|
UpdateClock();
|
|
|
|
}
|
|
|
|
|
|
|
|
WatchFaceAnalog::~WatchFaceAnalog() {
|
2021-07-19 13:26:12 +00:00
|
|
|
lv_task_del(taskRefresh);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
lv_style_reset(&hour_line_style);
|
|
|
|
lv_style_reset(&hour_line_style_trace);
|
|
|
|
lv_style_reset(&minute_line_style);
|
|
|
|
lv_style_reset(&minute_line_style_trace);
|
|
|
|
lv_style_reset(&second_line_style);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchFaceAnalog::UpdateClock() {
|
|
|
|
hour = dateTimeController.Hours();
|
|
|
|
minute = dateTimeController.Minutes();
|
2021-04-18 17:28:14 +00:00
|
|
|
second = dateTimeController.Seconds();
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (sMinute != minute) {
|
2021-07-11 18:18:07 +00:00
|
|
|
auto const angle = minute * 6;
|
2021-07-24 11:01:11 +00:00
|
|
|
minute_point[0] = CoordinateRelocate(30, angle);
|
|
|
|
minute_point[1] = CoordinateRelocate(MinuteLength, angle);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
minute_point_trace[0] = CoordinateRelocate(5, angle);
|
|
|
|
minute_point_trace[1] = CoordinateRelocate(31, angle);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_line_set_points(minute_body, minute_point, 2);
|
|
|
|
lv_line_set_points(minute_body_trace, minute_point_trace, 2);
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (sHour != hour || sMinute != minute) {
|
2021-02-24 19:40:24 +00:00
|
|
|
sHour = hour;
|
|
|
|
sMinute = minute;
|
2021-07-11 18:18:07 +00:00
|
|
|
auto const angle = (hour * 30 + minute / 2);
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
hour_point[0] = CoordinateRelocate(30, angle);
|
|
|
|
hour_point[1] = CoordinateRelocate(HourLength, angle);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
hour_point_trace[0] = CoordinateRelocate(5, angle);
|
|
|
|
hour_point_trace[1] = CoordinateRelocate(31, angle);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
lv_line_set_points(hour_body, hour_point, 2);
|
|
|
|
lv_line_set_points(hour_body_trace, hour_point_trace, 2);
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (sSecond != second) {
|
2021-02-24 19:40:24 +00:00
|
|
|
sSecond = second;
|
2021-07-11 18:18:07 +00:00
|
|
|
auto const angle = second * 6;
|
|
|
|
|
2021-07-24 11:01:11 +00:00
|
|
|
second_point[0] = CoordinateRelocate(-20, angle);
|
|
|
|
second_point[1] = CoordinateRelocate(SecondLength, angle);
|
2021-02-24 19:40:24 +00:00
|
|
|
lv_line_set_points(second_body, second_point, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-03 11:35:38 +00:00
|
|
|
void WatchFaceAnalog::SetBatteryIcon() {
|
|
|
|
auto batteryPercent = batteryPercentRemaining.Get();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
|
|
|
}
|
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
void WatchFaceAnalog::Refresh() {
|
2021-09-03 11:35:38 +00:00
|
|
|
isCharging = batteryController.IsCharging();
|
|
|
|
if (isCharging.IsUpdated()) {
|
|
|
|
if (isCharging.Get()) {
|
|
|
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
|
|
|
lv_label_set_text(batteryIcon, Symbols::plug);
|
|
|
|
} else {
|
|
|
|
SetBatteryIcon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isCharging.Get()) {
|
|
|
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
|
|
|
if (batteryPercentRemaining.IsUpdated()) {
|
|
|
|
SetBatteryIcon();
|
|
|
|
}
|
2021-02-24 19:40:24 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 18:34:46 +00:00
|
|
|
notificationState = notificationManager.AreNewNotificationsAvailable();
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (notificationState.IsUpdated()) {
|
2021-07-24 11:01:11 +00:00
|
|
|
lv_label_set_text(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
|
|
|
month = dateTimeController.Month();
|
|
|
|
day = dateTimeController.Day();
|
|
|
|
dayOfWeek = dateTimeController.DayOfWeek();
|
|
|
|
|
|
|
|
UpdateClock();
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-02-24 19:40:24 +00:00
|
|
|
if ((month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), day);
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
currentMonth = month;
|
|
|
|
currentDayOfWeek = dayOfWeek;
|
|
|
|
currentDay = day;
|
|
|
|
}
|
|
|
|
}
|
2021-06-22 18:34:46 +00:00
|
|
|
}
|