From 8c53d0b70baa03c2b07360444a7cd0ad99bb8381 Mon Sep 17 00:00:00 2001 From: Joaquim Date: Wed, 24 Feb 2021 19:40:24 +0000 Subject: Multi face support, analog clock, 12/24 config --- src/displayapp/screens/WatchFaceAnalog.cpp | 214 +++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 src/displayapp/screens/WatchFaceAnalog.cpp (limited to 'src/displayapp/screens/WatchFaceAnalog.cpp') diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp new file mode 100644 index 00000000..efca10c2 --- /dev/null +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -0,0 +1,214 @@ +#include +#include "WatchFaceAnalog.h" +#include "BatteryIcon.h" +#include "BleIcon.h" +#include "Symbols.h" +#include "NotificationIcon.h" + +LV_IMG_DECLARE(bg_clock); + +using namespace Pinetime::Applications::Screens; + +#define HOUR_LENGTH 70 +#define MINUTE_LENGTH 90 +#define SECOND_LENGTH 110 +#define PI 3.14159265358979323846 + +// ## +static int16_t coordinate_x_relocate(int16_t x) +{ + return ((x) + LV_HOR_RES / 2); +} + +// ## +static int16_t coordinate_y_relocate(int16_t y) +{ + return (((y) - LV_HOR_RES / 2) < 0) ? (0 - ((y) - LV_HOR_RES / 2)) : ((y) - LV_HOR_RES / 2); +} + +WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp *app, + Controllers::DateTime& dateTimeController, + Controllers::Battery& batteryController, + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager, + Controllers::Settings &settingsController) : Screen(app), currentDateTime{{}}, + dateTimeController{dateTimeController}, batteryController{batteryController}, + bleController{bleController}, notificatioManager{notificatioManager}, + settingsController{settingsController} { + settingsController.SetClockFace(1); + + sHour = 99; + sMinute = 99; + sSecond = 99; + + lv_obj_t * bg_clock_img = lv_img_create(lv_scr_act(), NULL); + lv_img_set_src(bg_clock_img, &bg_clock); + lv_obj_align(bg_clock_img, NULL, LV_ALIGN_CENTER, 0, 0); + + batteryIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text(batteryIcon, Symbols::batteryHalf); + lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -8, -4); + + + 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)); + lv_obj_align(notificationIcon, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 8, -4); + + // 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)); + 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); + + minute_body = lv_line_create(lv_scr_act(), NULL); + minute_body_trace = lv_line_create(lv_scr_act(), NULL); + hour_body = lv_line_create(lv_scr_act(), NULL); + hour_body_trace = lv_line_create(lv_scr_act(), NULL); + 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); + + UpdateClock(); + + /*lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr); + 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_static(backgroundLabel, "");*/ + +} + +WatchFaceAnalog::~WatchFaceAnalog() { + + 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); + + lv_obj_clean(lv_scr_act()); +} + +void WatchFaceAnalog::UpdateClock() { + + hour = dateTimeController.Hours(); + minute = dateTimeController.Minutes(); + second = dateTimeController.Seconds(); + + if(sMinute != minute) { + minute_point[0].x = coordinate_x_relocate(30 * sin(minute * 6 * PI / 180)); + minute_point[0].y = coordinate_y_relocate(30 * cos(minute * 6 * PI / 180)); + minute_point[1].x = coordinate_x_relocate(MINUTE_LENGTH * sin(minute * 6 * PI / 180)); + minute_point[1].y = coordinate_y_relocate(MINUTE_LENGTH * cos(minute * 6 * PI / 180)); + + minute_point_trace[0].x = coordinate_x_relocate(5 * sin(minute * 6 * PI / 180)); + minute_point_trace[0].y = coordinate_y_relocate(5 * cos(minute * 6 * PI / 180)); + minute_point_trace[1].x = coordinate_x_relocate(31 * sin(minute * 6 * PI / 180)); + minute_point_trace[1].y = coordinate_y_relocate(31 * cos(minute * 6 * PI / 180)); + + lv_line_set_points(minute_body, minute_point, 2); + lv_line_set_points(minute_body_trace, minute_point_trace, 2); + } + + if(sHour != hour || sMinute != minute) { + sHour = hour; + sMinute = minute; + hour_point[0].x = coordinate_x_relocate(30 * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + hour_point[0].y = coordinate_y_relocate(30 * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + hour_point[1].x = coordinate_x_relocate(HOUR_LENGTH * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + hour_point[1].y = coordinate_y_relocate(HOUR_LENGTH * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + + hour_point_trace[0].x = coordinate_x_relocate(5 * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + hour_point_trace[0].y = coordinate_y_relocate(5 * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + hour_point_trace[1].x = coordinate_x_relocate(31 * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + hour_point_trace[1].y = coordinate_y_relocate(31 * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180)); + + lv_line_set_points(hour_body, hour_point, 2); + lv_line_set_points(hour_body_trace, hour_point_trace, 2); + } + + if(sSecond != second) { + sSecond = second; + second_point[0].x = coordinate_x_relocate(20 * sin((180 + second * 6) * PI / 180)); + second_point[0].y = coordinate_y_relocate(20 * cos((180 + second * 6) * PI / 180)); + second_point[1].x = coordinate_x_relocate(SECOND_LENGTH * sin(second * 6 * PI / 180)); + second_point[1].y = coordinate_y_relocate(SECOND_LENGTH * cos(second * 6 * PI / 180)); + lv_line_set_points(second_body, second_point, 2); + + } +} + + +bool WatchFaceAnalog::Refresh() { + + batteryPercentRemaining = batteryController.PercentRemaining(); + if (batteryPercentRemaining.IsUpdated()) { + auto batteryPercent = batteryPercentRemaining.Get(); + lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + } + + + notificationState = notificatioManager.AreNewNotificationsAvailable(); + + if(notificationState.IsUpdated()) { + if(notificationState.Get() == true) + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true)); + else + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); + } + + currentDateTime = dateTimeController.CurrentDateTime(); + + if(currentDateTime.IsUpdated()) { + + month = dateTimeController.Month(); + day = dateTimeController.Day(); + dayOfWeek = dateTimeController.DayOfWeek(); + + UpdateClock(); + + if ((month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { + + lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), day); + + currentMonth = month; + currentDayOfWeek = dayOfWeek; + currentDay = day; + } + } + + return true; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 97deb43fb78b581535887938a0c3c0813896fcbe Mon Sep 17 00:00:00 2001 From: Joaquim Date: Sat, 6 Mar 2021 19:55:53 +0000 Subject: Update from JF comments to PR --- src/components/settings/Settings.cpp | 2 -- src/displayapp/screens/Clock.h | 6 ++++-- src/displayapp/screens/ScreenList.h | 18 ++---------------- src/displayapp/screens/WatchFaceAnalog.cpp | 6 ------ src/displayapp/screens/WatchFaceDigital.cpp | 7 ------- 5 files changed, 6 insertions(+), 33 deletions(-) (limited to 'src/displayapp/screens/WatchFaceAnalog.cpp') diff --git a/src/components/settings/Settings.cpp b/src/components/settings/Settings.cpp index 87cfe885..0c6cf610 100644 --- a/src/components/settings/Settings.cpp +++ b/src/components/settings/Settings.cpp @@ -6,9 +6,7 @@ using namespace Pinetime::Controllers; // TODO (team): // Read and write the settings to Flash // - void Settings::Init() { - // default Clock face clockFace = 0; diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 2b1be4ac..964ccbf6 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -49,8 +49,10 @@ namespace Pinetime { ScreenList<2> screens; std::unique_ptr WatchFaceDigitalScreen(); std::unique_ptr WatchFaceAnalogScreen(); - std::unique_ptr WatchFaceMinimalScreen(); - std::unique_ptr WatchFaceCustomScreen(); + + // Examples for more watch faces + //std::unique_ptr WatchFaceMinimalScreen(); + //std::unique_ptr WatchFaceCustomScreen(); bool running = true; diff --git a/src/displayapp/screens/ScreenList.h b/src/displayapp/screens/ScreenList.h index 56d9abe0..43b33f40 100644 --- a/src/displayapp/screens/ScreenList.h +++ b/src/displayapp/screens/ScreenList.h @@ -15,26 +15,12 @@ namespace Pinetime { class ScreenList : public Screen { public: - ScreenList( - DisplayApp* app, - uint8_t initScreen, - std::array()>, N>&& screens, - ScreenListModes mode - ) - : Screen(app), - initScreen{initScreen}, - screens{std::move(screens)}, - mode{mode}, - current{this->screens[initScreen]()} - { + ScreenList(DisplayApp* app, uint8_t initScreen, std::array()>, N>&& screens, ScreenListModes mode) + : Screen(app), initScreen{initScreen}, screens{std::move(screens)}, mode{mode}, current{this->screens[initScreen]()} { screenIndex = initScreen; } ~ScreenList() override { - current.reset(nullptr); - /*for(uint8_t i = 0; i < screens.size(); i++) { - screens[i]().reset(nullptr); - }*/ lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index efca10c2..b51d48c7 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -103,12 +103,6 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp *app, UpdateClock(); - /*lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr); - 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_static(backgroundLabel, "");*/ - } WatchFaceAnalog::~WatchFaceAnalog() { diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 99df318a..4560ccdb 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -30,13 +30,6 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, heartRateController{heartRateController} { settingsController.SetClockFace(0); - // init - /*currentDateTime = dateTimeController.CurrentDateTime(); - batteryPercentRemaining = batteryController.PercentRemaining(); - bleState = bleController.IsConnected(); - notificationState = notificatioManager.AreNewNotificationsAvailable(); - heartbeat = heartRateController.HeartRate();*/ - displayedChar[0] = 0; displayedChar[1] = 0; displayedChar[2] = 0; -- cgit v1.2.3-70-g09d2