From 319dfd23e7dd1ecfedea113e49dfe30b5a814c67 Mon Sep 17 00:00:00 2001 From: ITCactus Date: Mon, 9 May 2022 17:45:53 +0200 Subject: [new watchface] watchface inspired by G7710, with day of year and week number info --- src/displayapp/screens/CheckboxList.cpp | 115 ++++++++ src/displayapp/screens/CheckboxList.h | 49 ++++ src/displayapp/screens/Clock.cpp | 15 ++ src/displayapp/screens/Clock.h | 1 + .../screens/WatchFaceCasioStyleG7710.cpp | 297 +++++++++++++++++++++ src/displayapp/screens/WatchFaceCasioStyleG7710.h | 91 +++++++ src/displayapp/screens/settings/SettingWatchFace.h | 13 +- 7 files changed, 577 insertions(+), 4 deletions(-) create mode 100644 src/displayapp/screens/CheckboxList.cpp create mode 100644 src/displayapp/screens/CheckboxList.h create mode 100644 src/displayapp/screens/WatchFaceCasioStyleG7710.cpp create mode 100644 src/displayapp/screens/WatchFaceCasioStyleG7710.h (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/CheckboxList.cpp b/src/displayapp/screens/CheckboxList.cpp new file mode 100644 index 00000000..7667946a --- /dev/null +++ b/src/displayapp/screens/CheckboxList.cpp @@ -0,0 +1,115 @@ +#include "displayapp/screens/CheckboxList.h" +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Styles.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t* obj, lv_event_t event) { + CheckboxList* screen = static_cast(obj->user_data); + screen->UpdateSelected(obj, event); + } + +} + +CheckboxList::CheckboxList(const uint8_t screenID, + const uint8_t numScreens, + DisplayApp* app, + Controllers::Settings& settingsController, + const char* optionsTitle, + const char* optionsSymbol, + void (Controllers::Settings::*SetOptionIndex)(uint8_t), + uint8_t (Controllers::Settings::*GetOptionIndex )() const, + std::array options) + : Screen(app), screenID {screenID}, settingsController {settingsController}, + SetOptionIndex {SetOptionIndex}, GetOptionIndex {GetOptionIndex}, + options {options} { + + settingsController.SetWatchfacesMenu(screenID); + + // Set the background to Black + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + + if (numScreens > 1) { + pageIndicatorBasePoints[0].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[0].y = 0; + pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[1].y = LV_VER_RES; + + pageIndicatorBase = lv_line_create(lv_scr_act(), NULL); + lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); + lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); + lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); + + const uint16_t indicatorSize = LV_VER_RES / numScreens; + const uint16_t indicatorPos = indicatorSize * screenID; + + pageIndicatorPoints[0].x = LV_HOR_RES - 1; + pageIndicatorPoints[0].y = indicatorPos; + pageIndicatorPoints[1].x = LV_HOR_RES - 1; + pageIndicatorPoints[1].y = indicatorPos + indicatorSize; + + pageIndicator = lv_line_create(lv_scr_act(), NULL); + lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); + lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); + } + + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); + + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(container1, 10, 60); + lv_obj_set_width(container1, LV_HOR_RES - 20); + lv_obj_set_height(container1, LV_VER_RES - 50); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, optionsTitle); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); + + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text_static(icon, optionsSymbol); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + for (unsigned int i = 0; i < options.size(); i++) { + if (strcmp(options[i], "")) { + cbOption[i] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text(cbOption[i], options[i]); + cbOption[i]->user_data = this; + lv_obj_set_event_cb(cbOption[i], event_handler); + SetRadioButtonStyle(cbOption[i]); + + if (static_cast((settingsController.*GetOptionIndex)() - MAXLISTITEMS*screenID) == i) { + lv_checkbox_set_checked(cbOption[i], true); + } + } + } +} + +CheckboxList::~CheckboxList() { + lv_obj_clean(lv_scr_act()); + settingsController.SaveSettings(); +} + +void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_VALUE_CHANGED) { + for (unsigned int i = 0; i < options.size(); i++) { + if (strcmp(options[i], "")) { + if (object == cbOption[i]) { + lv_checkbox_set_checked(cbOption[i], true); + (settingsController.*SetOptionIndex)(MAXLISTITEMS*screenID + i); + } else { + lv_checkbox_set_checked(cbOption[i], false); + } + } + } + } +} \ No newline at end of file diff --git a/src/displayapp/screens/CheckboxList.h b/src/displayapp/screens/CheckboxList.h new file mode 100644 index 00000000..e90dcd30 --- /dev/null +++ b/src/displayapp/screens/CheckboxList.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include +#include "displayapp/screens/Screen.h" +#include "displayapp/Apps.h" +#include "components/settings/Settings.h" + +#define MAXLISTITEMS 4 + +namespace Pinetime { + namespace Applications { + namespace Screens { + class CheckboxList : public Screen { + public: + CheckboxList(const uint8_t screenID, + const uint8_t numScreens, + DisplayApp* app, + Controllers::Settings& settingsController, + const char* optionsTitle, + const char* optionsSymbol, + void (Controllers::Settings::*SetOptionIndex)(uint8_t), + uint8_t (Controllers::Settings::*GetOptionIndex)() const, + std::array options); + + ~CheckboxList() override; + + void UpdateSelected(lv_obj_t* object, lv_event_t event); + + private: + const uint8_t screenID; + Controllers::Settings& settingsController; + const char* optionsTitle; + const char* optionsSymbol; + void (Controllers::Settings::*SetOptionIndex)(uint8_t); + uint8_t (Controllers::Settings::*GetOptionIndex)() const; + std::array options; + + lv_obj_t* cbOption[MAXLISTITEMS]; + + lv_point_t pageIndicatorBasePoints[2]; + lv_point_t pageIndicatorPoints[2]; + lv_obj_t* pageIndicatorBase; + lv_obj_t* pageIndicator; + }; + } + } +} \ No newline at end of file diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 1687dccf..4e76af18 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -12,6 +12,7 @@ #include "displayapp/screens/WatchFaceTerminal.h" #include "displayapp/screens/WatchFaceAnalog.h" #include "displayapp/screens/WatchFacePineTimeStyle.h" +#include "displayapp/screens/WatchFaceCasioStyleG7710.h" using namespace Pinetime::Applications::Screens; @@ -45,6 +46,9 @@ Clock::Clock(DisplayApp* app, case 3: return WatchFaceTerminalScreen(); break; + case 4: + return WatchFaceCasioStyleG7710(); + break; } return WatchFaceDigitalScreen(); }()} { @@ -103,3 +107,14 @@ std::unique_ptr Clock::WatchFaceTerminalScreen() { heartRateController, motionController); } + +std::unique_ptr Clock::WatchFaceCasioStyleG7710() { + return std::make_unique(app, + dateTimeController, + batteryController, + bleController, + notificatioManager, + settingsController, + heartRateController, + motionController); +} diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 1ba752c7..5446a11b 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -48,6 +48,7 @@ namespace Pinetime { std::unique_ptr WatchFaceAnalogScreen(); std::unique_ptr WatchFacePineTimeStyleScreen(); std::unique_ptr WatchFaceTerminalScreen(); + std::unique_ptr WatchFaceCasioStyleG7710(); }; } } diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp new file mode 100644 index 00000000..8f730d52 --- /dev/null +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -0,0 +1,297 @@ +#include "displayapp/screens/WatchFaceCasioStyleG7710.h" + +#include +#include +#include +#include "displayapp/screens/BatteryIcon.h" +#include "displayapp/screens/BleIcon.h" +#include "displayapp/screens/NotificationIcon.h" +#include "displayapp/screens/Symbols.h" +#include "components/battery/BatteryController.h" +#include "components/ble/BleController.h" +#include "components/ble/NotificationManager.h" +#include "components/heartrate/HeartRateController.h" +#include "components/motion/MotionController.h" +#include "components/settings/Settings.h" +using namespace Pinetime::Applications::Screens; + + +WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, + 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} { + + batteryIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(batteryIcon, Symbols::batteryFull); + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 0); + + 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(0x98B69A)); + lv_label_set_text_static(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(0x98B69A)); + lv_label_set_text_static(bleIcon, Symbols::bluetooth); + lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 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_hex(0x98B69A)); + lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 5, 0); + + + label_day_of_week = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(label_day_of_week, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 10, 64); + lv_obj_set_style_local_text_color(label_day_of_week, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_font(label_day_of_week, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_dots_40); + lv_label_set_text_static(label_day_of_week, "SUN"); + + label_week_number = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(label_week_number, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 34); + lv_obj_set_style_local_text_color(label_week_number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_font(label_week_number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_dots_40); + lv_label_set_text_static(label_week_number, "WK26"); + + label_day_of_year = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(label_day_of_year, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 25); + lv_obj_set_style_local_text_color(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_font(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_40); + lv_label_set_text_static(label_day_of_year, "181-184"); + + static lv_style_t style_line; + lv_style_init(&style_line); + lv_style_set_line_width(&style_line, LV_STATE_DEFAULT, 2); + lv_style_set_line_color(&style_line, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_style_set_line_rounded(&style_line, LV_STATE_DEFAULT, true); + + static lv_style_t style_border; + lv_style_init(&style_border); + lv_style_set_line_width(&style_border, LV_STATE_DEFAULT, 6); + lv_style_set_line_color(&style_border, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_style_set_line_rounded(&style_border, LV_STATE_DEFAULT, true); + + line_day_of_week_number = lv_line_create(lv_scr_act(), nullptr); + static lv_point_t line_day_of_week_number_points[] = {{0, 0}, {100, 0}, {94, 70}, {0, 70}}; + lv_line_set_points(line_day_of_week_number, line_day_of_week_number_points, 4); + lv_obj_add_style(line_day_of_week_number, LV_LINE_PART_MAIN, &style_border); + lv_obj_align(line_day_of_week_number, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 28); + + line_day_of_year = lv_line_create(lv_scr_act(), nullptr); + static lv_point_t line_day_of_year_points[] = {{0, 5}, {130, 5}, {135, 0}}; + lv_line_set_points(line_day_of_year, line_day_of_year_points, 3); + lv_obj_add_style(line_day_of_year, LV_LINE_PART_MAIN, &style_line); + lv_obj_align(line_day_of_year, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 55); + + label_date = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 65); + lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_font(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_40); + lv_label_set_text_static(label_date, "6-30"); + + line_date = lv_line_create(lv_scr_act(), nullptr); + static lv_point_t line_date_points[] = {{0, 5}, {135, 5}, {140, 0}}; + lv_line_set_points(line_date, line_date_points, 3); + lv_obj_add_style(line_date, LV_LINE_PART_MAIN, &style_line); + lv_obj_align(line_date, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 95); + + label_time = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_115); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + + line_time = lv_line_create(lv_scr_act(), nullptr); + static lv_point_t line_time_points[] = {{0, 0}, {230, 0}, {235, 5}}; + lv_line_set_points(line_time, line_time_points, 3); + lv_obj_add_style(line_time, LV_LINE_PART_MAIN, &style_line); + lv_obj_align(line_time, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -35); + + label_time_ampm = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(label_time_ampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_label_set_text_static(label_time_ampm, ""); + lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 5, -5); + + 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_static(backgroundLabel, ""); + + heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); + lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); + + 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(0x98B69A)); + lv_label_set_text_static(heartbeatValue, ""); + 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(0x98B69A)); + lv_label_set_text_static(stepValue, "0"); + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); + + 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(0x98B69A)); + lv_label_set_text_static(stepIcon, Symbols::shoe); + lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); + + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); + Refresh(); +} + +WatchFaceCasioStyleG7710::~WatchFaceCasioStyleG7710() { + lv_task_del(taskRefresh); + lv_obj_clean(lv_scr_act()); +} + +void WatchFaceCasioStyleG7710::Refresh() { + powerPresent = batteryController.IsPowerPresent(); + if (powerPresent.IsUpdated()) { + lv_label_set_text_static(batteryPlug, BatteryIcon::GetPlugIcon(powerPresent.Get())); + } + + batteryPercentRemaining = batteryController.PercentRemaining(); + if (batteryPercentRemaining.IsUpdated()) { + auto batteryPercent = batteryPercentRemaining.Get(); + lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + } + + bleState = bleController.IsConnected(); + bleRadioEnabled = bleController.IsRadioEnabled(); + if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) { + lv_label_set_text_static(bleIcon, BleIcon::GetIcon(bleState.Get())); + } + lv_obj_realign(batteryPlug); + lv_obj_realign(bleIcon); + + notificationState = notificatioManager.AreNewNotificationsAvailable(); + if (notificationState.IsUpdated()) { + lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); + } + + currentDateTime = dateTimeController.CurrentDateTime(); + + if (currentDateTime.IsUpdated()) { + auto newDateTime = currentDateTime.Get(); + + auto dp = date::floor(newDateTime); + auto time = date::make_time(newDateTime - dp); + auto yearMonthDay = date::year_month_day(dp); + + auto year = static_cast(yearMonthDay.year()); + auto month = static_cast(static_cast(yearMonthDay.month())); + auto day = static_cast(yearMonthDay.day()); + auto dayOfWeek = static_cast(date::weekday(yearMonthDay).iso_encoding()); + + uint8_t hour = time.hours().count(); + uint8_t minute = time.minutes().count(); + auto weekNumberFormat = "%V"; + + if (displayedHour != hour || displayedMinute != minute) { + displayedHour = hour; + displayedMinute = minute; + + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { + char ampmChar[2] = "A"; + if (hour == 0) { + hour = 12; + } else if (hour == 12) { + ampmChar[0] = 'P'; + } else if (hour > 12) { + hour = hour - 12; + ampmChar[0] = 'P'; + } + lv_label_set_text(label_time_ampm, ampmChar); + lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 30); + } else { + lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 30); + } + } + + if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { + // 24h mode: ddmmyyyy, first DOW=Monday; + lv_label_set_text_fmt( + label_date, "%3d-%2d", day, month); + weekNumberFormat = "%V"; // Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday] + } else { + // 12h mode: mmddyyyy, first DOW=Sunday; + lv_label_set_text_fmt( + label_date, "%3d-%2d", month, day); + weekNumberFormat = "%U"; // Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday] + } + + uint8_t weekNumber; + uint16_t dayOfYearNumber, daysTillEndOfYearNumber; + + std::tm date = {}; + date.tm_year = year - 1900; + date.tm_mon = static_cast(yearMonthDay.month()) - 1; + date.tm_mday = day + 1; + std::mktime( &date ); + + dayOfYearNumber = date.tm_yday; + daysTillEndOfYearNumber = yearMonthDay.year().is_leap() ? 366 : 365 - dayOfYearNumber; + + char buffer[8]; + strftime(buffer, 8, weekNumberFormat, &date); + weekNumber = atoi(buffer); + + lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString()); + lv_label_set_text_fmt(label_day_of_year, "%3d-%3d", dayOfYearNumber, daysTillEndOfYearNumber); + lv_label_set_text_fmt(label_week_number, "WK%02d", weekNumber); + + lv_obj_realign(label_day_of_week); + lv_obj_realign(label_day_of_year); + lv_obj_realign(label_week_number); + lv_obj_realign(label_date); + + currentYear = year; + currentMonth = month; + currentDayOfWeek = dayOfWeek; + currentDay = day; + } + } + + heartbeat = heartRateController.HeartRate(); + heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; + if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { + if (heartbeatRunning.Get()) { + lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get()); + } 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, ""); + } + + lv_obj_realign(heartbeatIcon); + lv_obj_realign(heartbeatValue); + } + + stepCount = motionController.NbSteps(); + motionSensorOk = motionController.IsSensorOk(); + if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) { + lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get()); + lv_obj_realign(stepValue); + lv_obj_realign(stepIcon); + } +} diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h new file mode 100644 index 00000000..0cf7bbbf --- /dev/null +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -0,0 +1,91 @@ +#pragma once + +#include +#include +#include +#include +#include +#include "displayapp/screens/Screen.h" +#include "components/datetime/DateTimeController.h" +#include "components/ble/BleController.h" + +namespace Pinetime { + namespace Controllers { + class Settings; + class Battery; + class Ble; + class NotificationManager; + class HeartRateController; + class MotionController; + } + + namespace Applications { + namespace Screens { + + class WatchFaceCasioStyleG7710 : public Screen { + public: + WatchFaceCasioStyleG7710(DisplayApp* app, + Controllers::DateTime& dateTimeController, + Controllers::Battery& batteryController, + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager, + Controllers::Settings& settingsController, + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController); + ~WatchFaceCasioStyleG7710() override; + + void Refresh() override; + + private: + uint8_t displayedHour = -1; + uint8_t displayedMinute = -1; + + uint16_t currentYear = 1970; + Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown; + Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; + uint8_t currentDay = 0; + + DirtyValue batteryPercentRemaining {}; + DirtyValue powerPresent {}; + DirtyValue bleState {}; + DirtyValue bleRadioEnabled {}; + DirtyValue> currentDateTime {}; + DirtyValue motionSensorOk {}; + DirtyValue stepCount {}; + DirtyValue heartbeat {}; + DirtyValue heartbeatRunning {}; + DirtyValue notificationState {}; + + lv_obj_t* label_time; + lv_obj_t* line_time; + lv_obj_t* label_time_ampm; + lv_obj_t* label_date; + lv_obj_t* line_date; + lv_obj_t* label_day_of_week; + lv_obj_t* label_week_number; + lv_obj_t* line_day_of_week_number; + lv_obj_t* label_day_of_year; + lv_obj_t* line_day_of_year; + lv_obj_t* backgroundLabel; + lv_obj_t* bleIcon; + lv_obj_t* batteryPlug; + lv_obj_t* heartbeatIcon; + lv_obj_t* heartbeatValue; + lv_obj_t* stepIcon; + lv_obj_t* stepValue; + lv_obj_t* notificationIcon; + lv_obj_t* batteryIcon; + + Controllers::DateTime& dateTimeController; + Controllers::Battery& batteryController; + Controllers::Ble& bleController; + Controllers::NotificationManager& notificatioManager; + Controllers::Settings& settingsController; + Controllers::HeartRateController& heartRateController; + Controllers::MotionController& motionController; + + lv_task_t* taskRefresh; + }; + } + } +} diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 62427b4f..801dcd73 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -4,8 +4,10 @@ #include #include +#include "displayapp/screens/ScreenList.h" #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" namespace Pinetime { @@ -17,14 +19,17 @@ namespace Pinetime { SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingWatchFace() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); + bool OnTouchEvent(TouchEvents event) override; private: - static constexpr std::array options = {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; Controllers::Settings& settingsController; + ScreenList<2> screens; - lv_obj_t* cbOption[options.size()]; + static constexpr const char* title = "Watch face"; + static constexpr const char* symbol = Symbols::home; + std::unique_ptr CreateScreen1(); + std::unique_ptr CreateScreen2(); }; } } -} +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 917e46c684a590f708b12458dc5f197cc9bee0fc Mon Sep 17 00:00:00 2001 From: ITCactus Date: Mon, 16 May 2022 12:05:14 +0200 Subject: post rebase fixes --- src/components/settings/Settings.h | 9 ++- src/displayapp/fonts/CMakeLists.txt | 2 +- src/displayapp/fonts/fonts.json | 32 +++++++- src/displayapp/screens/CheckboxList.cpp | 2 +- src/displayapp/screens/CheckboxList.h | 2 +- .../screens/WatchFaceCasioStyleG7710.cpp | 53 ++++++++----- src/displayapp/screens/WatchFaceCasioStyleG7710.h | 5 +- .../screens/settings/SettingWatchFace.cpp | 91 +++++++++------------- src/displayapp/screens/settings/SettingWatchFace.h | 2 +- 9 files changed, 113 insertions(+), 85 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 83987b77..becd57bc 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -98,10 +98,6 @@ namespace Pinetime { appMenu = menu; }; - uint8_t GetAppMenu() const { - return appMenu; - }; - void SetWatchfacesMenu(uint8_t menu) { watchFacesMenu = menu; }; @@ -110,6 +106,11 @@ namespace Pinetime { return watchFacesMenu; }; + + uint8_t GetAppMenu() const { + return appMenu; + }; + void SetSettingsMenu(uint8_t menu) { settingsMenu = menu; }; diff --git a/src/displayapp/fonts/CMakeLists.txt b/src/displayapp/fonts/CMakeLists.txt index 84830cc0..7af899ba 100644 --- a/src/displayapp/fonts/CMakeLists.txt +++ b/src/displayapp/fonts/CMakeLists.txt @@ -1,6 +1,6 @@ set(FONTS jetbrains_mono_42 jetbrains_mono_76 jetbrains_mono_bold_20 jetbrains_mono_extrabold_compressed lv_font_navi_80 lv_font_sys_48 - open_sans_light) + open_sans_light lv_font_dots_40 lv_font_7segment_40 lv_font_7segment_115) find_program(LV_FONT_CONV "lv_font_conv" NO_CACHE REQUIRED HINTS "${CMAKE_SOURCE_DIR}/node_modules/.bin") message(STATUS "Using ${LV_FONT_CONV} to generate font files") diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index abdb4512..b1593312 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -74,5 +74,35 @@ "bpp": 2, "size": 80, "compress": true + }, + "lv_font_dots_40": { + "sources": [ + { + "file": "repetitionscrolling.ttf", + "symbols": "0123456789-MONTUEWEDTHUFRISATSUN WK" + } + ], + "bpp": 1, + "size": 40 + }, + "lv_font_7segment_40": { + "sources": [ + { + "file": "7segment.woff", + "symbols": "0123456789: -" + } + ], + "bpp": 1, + "size": 40 + }, + "lv_font_7segment_115": { + "sources": [ + { + "file": "7segment.woff", + "symbols": "0123456789: -" + } + ], + "bpp": 1, + "size": 115 } -} +} \ No newline at end of file diff --git a/src/displayapp/screens/CheckboxList.cpp b/src/displayapp/screens/CheckboxList.cpp index 7667946a..4da7826c 100644 --- a/src/displayapp/screens/CheckboxList.cpp +++ b/src/displayapp/screens/CheckboxList.cpp @@ -112,4 +112,4 @@ void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) { } } } -} \ No newline at end of file +} diff --git a/src/displayapp/screens/CheckboxList.h b/src/displayapp/screens/CheckboxList.h index e90dcd30..6660acde 100644 --- a/src/displayapp/screens/CheckboxList.h +++ b/src/displayapp/screens/CheckboxList.h @@ -46,4 +46,4 @@ namespace Pinetime { }; } } -} \ No newline at end of file +} diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index 8f730d52..eb4cb63e 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -15,7 +15,6 @@ #include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; - WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, @@ -34,15 +33,21 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, heartRateController {heartRateController}, motionController {motionController} { - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(batteryIcon, Symbols::batteryFull); - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); - lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 0); + + label_battery_vallue = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(label_battery_vallue, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); + lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_label_set_text_static(label_battery_vallue, "00%"); + + + batteryIcon.Create(lv_scr_act()); + batteryIcon.SetColor(lv_color_hex(0x98B69A)); + lv_obj_align(batteryIcon.GetObject(), label_battery_vallue, LV_ALIGN_OUT_LEFT_MID, -5, 0); 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(0x98B69A)); lv_label_set_text_static(batteryPlug, Symbols::plug); - lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); + lv_obj_align(batteryPlug, batteryIcon.GetObject(), 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(0x98B69A)); @@ -52,7 +57,7 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, 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_hex(0x98B69A)); lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); - lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 5, 0); + lv_obj_align(notificationIcon, bleIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); label_day_of_week = lv_label_create(lv_scr_act(), nullptr); @@ -62,13 +67,13 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, lv_label_set_text_static(label_day_of_week, "SUN"); label_week_number = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(label_week_number, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 34); + lv_obj_align(label_week_number, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 22); lv_obj_set_style_local_text_color(label_week_number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); lv_obj_set_style_local_text_font(label_week_number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_dots_40); lv_label_set_text_static(label_week_number, "WK26"); label_day_of_year = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(label_day_of_year, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 25); + lv_obj_align(label_day_of_year, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 30); lv_obj_set_style_local_text_color(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); lv_obj_set_style_local_text_font(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_40); lv_label_set_text_static(label_day_of_year, "181-184"); @@ -85,20 +90,26 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, lv_style_set_line_color(&style_border, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); lv_style_set_line_rounded(&style_border, LV_STATE_DEFAULT, true); + line_icons = lv_line_create(lv_scr_act(), nullptr); + static lv_point_t line_icons_points[] = {{0, 5}, {117, 5}, {122, 0}}; + lv_line_set_points(line_icons, line_icons_points, 3); + lv_obj_add_style(line_icons, LV_LINE_PART_MAIN, &style_line); + lv_obj_align(line_icons, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 18); + line_day_of_week_number = lv_line_create(lv_scr_act(), nullptr); - static lv_point_t line_day_of_week_number_points[] = {{0, 0}, {100, 0}, {94, 70}, {0, 70}}; + static lv_point_t line_day_of_week_number_points[] = {{0, 0}, {100, 0}, {95, 95}, {0, 95}}; lv_line_set_points(line_day_of_week_number, line_day_of_week_number_points, 4); lv_obj_add_style(line_day_of_week_number, LV_LINE_PART_MAIN, &style_border); - lv_obj_align(line_day_of_week_number, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 28); + lv_obj_align(line_day_of_week_number, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 8); line_day_of_year = lv_line_create(lv_scr_act(), nullptr); static lv_point_t line_day_of_year_points[] = {{0, 5}, {130, 5}, {135, 0}}; lv_line_set_points(line_day_of_year, line_day_of_year_points, 3); lv_obj_add_style(line_day_of_year, LV_LINE_PART_MAIN, &style_line); - lv_obj_align(line_day_of_year, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 55); + lv_obj_align(line_day_of_year, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 60); label_date = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 65); + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 70); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); lv_obj_set_style_local_text_font(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_40); lv_label_set_text_static(label_date, "6-30"); @@ -107,18 +118,18 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, static lv_point_t line_date_points[] = {{0, 5}, {135, 5}, {140, 0}}; lv_line_set_points(line_date, line_date_points, 3); lv_obj_add_style(line_date, LV_LINE_PART_MAIN, &style_line); - lv_obj_align(line_date, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 95); + lv_obj_align(line_date, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 100); label_time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_115); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); line_time = lv_line_create(lv_scr_act(), nullptr); static lv_point_t line_time_points[] = {{0, 0}, {230, 0}, {235, 5}}; lv_line_set_points(line_time, line_time_points, 3); lv_obj_add_style(line_time, LV_LINE_PART_MAIN, &style_line); - lv_obj_align(line_time, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -35); + lv_obj_align(line_time, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -25); label_time_ampm = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_time_ampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); @@ -170,7 +181,8 @@ void WatchFaceCasioStyleG7710::Refresh() { batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated()) { auto batteryPercent = batteryPercentRemaining.Get(); - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + batteryIcon.SetBatteryPercentage(batteryPercent); + lv_label_set_text_fmt(label_battery_vallue, "%d%%", batteryPercent); } bleState = bleController.IsConnected(); @@ -178,8 +190,11 @@ void WatchFaceCasioStyleG7710::Refresh() { if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) { lv_label_set_text_static(bleIcon, BleIcon::GetIcon(bleState.Get())); } + lv_obj_realign(label_battery_vallue); + lv_obj_realign(batteryIcon.GetObject()); lv_obj_realign(batteryPlug); lv_obj_realign(bleIcon); + lv_obj_realign(notificationIcon); notificationState = notificatioManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { @@ -220,10 +235,10 @@ void WatchFaceCasioStyleG7710::Refresh() { } lv_label_set_text(label_time_ampm, ampmChar); lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 30); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); } else { lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 30); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); } } diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index 0cf7bbbf..d77393e0 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -69,12 +69,15 @@ namespace Pinetime { lv_obj_t* backgroundLabel; lv_obj_t* bleIcon; lv_obj_t* batteryPlug; + lv_obj_t* label_battery_vallue; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; lv_obj_t* stepIcon; lv_obj_t* stepValue; lv_obj_t* notificationIcon; - lv_obj_t* batteryIcon; + lv_obj_t* line_icons; + + BatteryIcon batteryIcon; Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 3cb2a364..3c88b936 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -1,59 +1,31 @@ #include "displayapp/screens/settings/SettingWatchFace.h" #include #include "displayapp/DisplayApp.h" +#include "displayapp/screens/CheckboxList.h" #include "displayapp/screens/Screen.h" #include "displayapp/screens/Styles.h" #include "displayapp/screens/Symbols.h" +#include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; -namespace { - void event_handler(lv_obj_t* obj, lv_event_t event) { - auto* screen = static_cast(obj->user_data); - screen->UpdateSelected(obj, event); - } -} - -constexpr std::array SettingWatchFace::options; +constexpr const char* SettingWatchFace::title; +constexpr const char* SettingWatchFace::symbol; SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); - lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); - lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - - lv_obj_set_pos(container1, 10, 60); - lv_obj_set_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Watch face"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); - - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(icon, Symbols::home); - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); - - for (unsigned int i = 0; i < options.size(); i++) { - cbOption[i] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text(cbOption[i], options[i]); - cbOption[i]->user_data = this; - lv_obj_set_event_cb(cbOption[i], event_handler); - SetRadioButtonStyle(cbOption[i]); - - if (settingsController.GetClockFace() == i) { - lv_checkbox_set_checked(cbOption[i], true); - } - } + : Screen(app), + settingsController {settingsController}, + screens {app, + settingsController.GetWatchfacesMenu(), + { + [this]() -> std::unique_ptr { + return CreateScreen1(); + }, + [this]() -> std::unique_ptr { + return CreateScreen2(); + } + }, + Screens::ScreenListModes::UpDown} { } SettingWatchFace::~SettingWatchFace() { @@ -61,15 +33,22 @@ SettingWatchFace::~SettingWatchFace() { settingsController.SaveSettings(); } -void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - for (unsigned int i = 0; i < options.size(); i++) { - if (object == cbOption[i]) { - lv_checkbox_set_checked(cbOption[i], true); - settingsController.SetClockFace(i); - } else { - lv_checkbox_set_checked(cbOption[i], false); - } - } - } +bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return screens.OnTouchEvent(event); +} + +std::unique_ptr SettingWatchFace::CreateScreen1() { + std::array watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; + return std::make_unique(0, 2, app, settingsController, title, + symbol, &Controllers::Settings::SetClockFace, + &Controllers::Settings::GetClockFace, + watchfaces); +} + +std::unique_ptr SettingWatchFace::CreateScreen2() { + std::array watchfaces {" Casio G7710", "", "", ""}; + return std::make_unique(1, 2, app, settingsController, title, + symbol, &Controllers::Settings::SetClockFace, + &Controllers::Settings::GetClockFace, + watchfaces); } diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 801dcd73..7d14554e 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -32,4 +32,4 @@ namespace Pinetime { }; } } -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2 From e7c0b2c5c250f9dc43175bb8d73b2961bfae6b93 Mon Sep 17 00:00:00 2001 From: ITCactus Date: Fri, 20 May 2022 14:24:22 +0200 Subject: fix memory leak + refactoring --- .../screens/WatchFaceCasioStyleG7710.cpp | 49 ++++++++++------------ src/displayapp/screens/WatchFaceCasioStyleG7710.h | 11 +++++ 2 files changed, 33 insertions(+), 27 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index eb4cb63e..7feaaa6a 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -36,103 +36,94 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, label_battery_vallue = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_battery_vallue, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); - lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(label_battery_vallue, "00%"); - batteryIcon.Create(lv_scr_act()); - batteryIcon.SetColor(lv_color_hex(0x98B69A)); + batteryIcon.SetColor(color_text); lv_obj_align(batteryIcon.GetObject(), label_battery_vallue, LV_ALIGN_OUT_LEFT_MID, -5, 0); 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(0x98B69A)); + lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(batteryPlug, Symbols::plug); lv_obj_align(batteryPlug, batteryIcon.GetObject(), 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(0x98B69A)); + lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(bleIcon, Symbols::bluetooth); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 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_hex(0x98B69A)); + lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); lv_obj_align(notificationIcon, bleIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); - label_day_of_week = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_day_of_week, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 10, 64); - lv_obj_set_style_local_text_color(label_day_of_week, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(label_day_of_week, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_font(label_day_of_week, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_dots_40); lv_label_set_text_static(label_day_of_week, "SUN"); label_week_number = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_week_number, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 22); - lv_obj_set_style_local_text_color(label_week_number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(label_week_number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_font(label_week_number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_dots_40); lv_label_set_text_static(label_week_number, "WK26"); label_day_of_year = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_day_of_year, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 30); - lv_obj_set_style_local_text_color(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_font(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_40); lv_label_set_text_static(label_day_of_year, "181-184"); - static lv_style_t style_line; lv_style_init(&style_line); lv_style_set_line_width(&style_line, LV_STATE_DEFAULT, 2); - lv_style_set_line_color(&style_line, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_style_set_line_color(&style_line, LV_STATE_DEFAULT, color_text); lv_style_set_line_rounded(&style_line, LV_STATE_DEFAULT, true); - static lv_style_t style_border; lv_style_init(&style_border); lv_style_set_line_width(&style_border, LV_STATE_DEFAULT, 6); - lv_style_set_line_color(&style_border, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_style_set_line_color(&style_border, LV_STATE_DEFAULT, color_text); lv_style_set_line_rounded(&style_border, LV_STATE_DEFAULT, true); line_icons = lv_line_create(lv_scr_act(), nullptr); - static lv_point_t line_icons_points[] = {{0, 5}, {117, 5}, {122, 0}}; lv_line_set_points(line_icons, line_icons_points, 3); lv_obj_add_style(line_icons, LV_LINE_PART_MAIN, &style_line); lv_obj_align(line_icons, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 18); line_day_of_week_number = lv_line_create(lv_scr_act(), nullptr); - static lv_point_t line_day_of_week_number_points[] = {{0, 0}, {100, 0}, {95, 95}, {0, 95}}; lv_line_set_points(line_day_of_week_number, line_day_of_week_number_points, 4); lv_obj_add_style(line_day_of_week_number, LV_LINE_PART_MAIN, &style_border); lv_obj_align(line_day_of_week_number, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 8); line_day_of_year = lv_line_create(lv_scr_act(), nullptr); - static lv_point_t line_day_of_year_points[] = {{0, 5}, {130, 5}, {135, 0}}; lv_line_set_points(line_day_of_year, line_day_of_year_points, 3); lv_obj_add_style(line_day_of_year, LV_LINE_PART_MAIN, &style_line); lv_obj_align(line_day_of_year, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 60); label_date = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 70); - lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_font(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_40); lv_label_set_text_static(label_date, "6-30"); line_date = lv_line_create(lv_scr_act(), nullptr); - static lv_point_t line_date_points[] = {{0, 5}, {135, 5}, {140, 0}}; lv_line_set_points(line_date, line_date_points, 3); lv_obj_add_style(line_date, LV_LINE_PART_MAIN, &style_line); lv_obj_align(line_date, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 100); label_time = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_7segment_115); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); line_time = lv_line_create(lv_scr_act(), nullptr); - static lv_point_t line_time_points[] = {{0, 0}, {230, 0}, {235, 5}}; lv_line_set_points(line_time, line_time_points, 3); lv_obj_add_style(line_time, LV_LINE_PART_MAIN, &style_line); lv_obj_align(line_time, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -25); label_time_ampm = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(label_time_ampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(label_time_ampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(label_time_ampm, ""); lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 5, -5); @@ -145,21 +136,21 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); 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(0x98B69A)); + lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(heartbeatValue, ""); 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(0x98B69A)); + lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(stepValue, "0"); lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); 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(0x98B69A)); + lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_static(stepIcon, Symbols::shoe); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); @@ -169,6 +160,10 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, WatchFaceCasioStyleG7710::~WatchFaceCasioStyleG7710() { lv_task_del(taskRefresh); + + lv_style_reset(&style_line); + lv_style_reset(&style_border); + lv_obj_clean(lv_scr_act()); } @@ -291,7 +286,7 @@ void WatchFaceCasioStyleG7710::Refresh() { heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { if (heartbeatRunning.Get()) { - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x98B69A)); + lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get()); } else { lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B)); diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index d77393e0..a8382ff2 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -56,6 +56,17 @@ namespace Pinetime { DirtyValue heartbeatRunning {}; DirtyValue notificationState {}; + lv_point_t line_icons_points[3] {{0, 5}, {117, 5}, {122, 0}}; + lv_point_t line_day_of_week_number_points[4] {{0, 0}, {100, 0}, {95, 95}, {0, 95}}; + lv_point_t line_day_of_year_points[3] {{0, 5}, {130, 5}, {135, 0}}; + lv_point_t line_date_points[3] {{0, 5}, {135, 5}, {140, 0}}; + lv_point_t line_time_points[3] {{0, 0}, {230, 0}, {235, 5}}; + + lv_color_t color_text = lv_color_hex(0x98B69A); + + lv_style_t style_line; + lv_style_t style_border; + lv_obj_t* label_time; lv_obj_t* line_time; lv_obj_t* label_time_ampm; -- cgit v1.2.3-70-g09d2 From cfaafc1fe2e31926343c571bc22a9afa54287f47 Mon Sep 17 00:00:00 2001 From: ITCactus Date: Wed, 25 May 2022 13:44:25 +0200 Subject: fix for week number and days till the end of the year + formating (clang) --- src/displayapp/screens/CheckboxList.cpp | 13 ++++--- .../screens/WatchFaceCasioStyleG7710.cpp | 45 +++++++++++----------- src/displayapp/screens/WatchFaceCasioStyleG7710.h | 16 ++++---- .../screens/settings/SettingWatchFace.cpp | 26 +++++-------- 4 files changed, 48 insertions(+), 52 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/CheckboxList.cpp b/src/displayapp/screens/CheckboxList.cpp index 4da7826c..ee64167d 100644 --- a/src/displayapp/screens/CheckboxList.cpp +++ b/src/displayapp/screens/CheckboxList.cpp @@ -20,10 +20,13 @@ CheckboxList::CheckboxList(const uint8_t screenID, const char* optionsTitle, const char* optionsSymbol, void (Controllers::Settings::*SetOptionIndex)(uint8_t), - uint8_t (Controllers::Settings::*GetOptionIndex )() const, + uint8_t (Controllers::Settings::*GetOptionIndex)() const, std::array options) - : Screen(app), screenID {screenID}, settingsController {settingsController}, - SetOptionIndex {SetOptionIndex}, GetOptionIndex {GetOptionIndex}, + : Screen(app), + screenID {screenID}, + settingsController {settingsController}, + SetOptionIndex {SetOptionIndex}, + GetOptionIndex {GetOptionIndex}, options {options} { settingsController.SetWatchfacesMenu(screenID); @@ -87,7 +90,7 @@ CheckboxList::CheckboxList(const uint8_t screenID, lv_obj_set_event_cb(cbOption[i], event_handler); SetRadioButtonStyle(cbOption[i]); - if (static_cast((settingsController.*GetOptionIndex)() - MAXLISTITEMS*screenID) == i) { + if (static_cast((settingsController.*GetOptionIndex)() - MAXLISTITEMS * screenID) == i) { lv_checkbox_set_checked(cbOption[i], true); } } @@ -105,7 +108,7 @@ void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (strcmp(options[i], "")) { if (object == cbOption[i]) { lv_checkbox_set_checked(cbOption[i], true); - (settingsController.*SetOptionIndex)(MAXLISTITEMS*screenID + i); + (settingsController.*SetOptionIndex)(MAXLISTITEMS * screenID + i); } else { lv_checkbox_set_checked(cbOption[i], false); } diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index 7feaaa6a..f0e6e88e 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -16,13 +16,13 @@ using namespace Pinetime::Applications::Screens; WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, - Controllers::DateTime& dateTimeController, - Controllers::Battery& batteryController, - Controllers::Ble& bleController, - Controllers::NotificationManager& notificatioManager, - Controllers::Settings& settingsController, - Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController) + 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}, @@ -33,7 +33,6 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, heartRateController {heartRateController}, motionController {motionController} { - label_battery_vallue = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_battery_vallue, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); @@ -163,7 +162,7 @@ WatchFaceCasioStyleG7710::~WatchFaceCasioStyleG7710() { lv_style_reset(&style_line); lv_style_reset(&style_border); - + lv_obj_clean(lv_scr_act()); } @@ -240,30 +239,30 @@ void WatchFaceCasioStyleG7710::Refresh() { if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { // 24h mode: ddmmyyyy, first DOW=Monday; - lv_label_set_text_fmt( - label_date, "%3d-%2d", day, month); - weekNumberFormat = "%V"; // Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday] + lv_label_set_text_fmt(label_date, "%3d-%2d", day, month); + weekNumberFormat = "%V"; // Replaced by the week number of the year (Monday as the first day of the week) as a decimal number + // [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered + // week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January + // 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday] } else { // 12h mode: mmddyyyy, first DOW=Sunday; - lv_label_set_text_fmt( - label_date, "%3d-%2d", month, day); - weekNumberFormat = "%U"; // Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday] + lv_label_set_text_fmt(label_date, "%3d-%2d", month, day); + weekNumberFormat = "%U"; // Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the + // first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday] } uint8_t weekNumber; uint16_t dayOfYearNumber, daysTillEndOfYearNumber; - std::tm date = {}; - date.tm_year = year - 1900; - date.tm_mon = static_cast(yearMonthDay.month()) - 1; - date.tm_mday = day + 1; - std::mktime( &date ); + time_t ttTime = + std::chrono::system_clock::to_time_t(std::chrono::time_point_cast(currentDateTime.Get())); + tm* tmTime = std::localtime(&ttTime); - dayOfYearNumber = date.tm_yday; - daysTillEndOfYearNumber = yearMonthDay.year().is_leap() ? 366 : 365 - dayOfYearNumber; + dayOfYearNumber = tmTime->tm_yday + 1; // tm_yday day of year [0,365] => yday+1 + daysTillEndOfYearNumber = (yearMonthDay.year().is_leap() ? 366 : 365) - dayOfYearNumber; char buffer[8]; - strftime(buffer, 8, weekNumberFormat, &date); + strftime(buffer, 8, weekNumberFormat, tmTime); weekNumber = atoi(buffer); lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString()); diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index a8382ff2..9cc909a6 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -25,13 +25,13 @@ namespace Pinetime { class WatchFaceCasioStyleG7710 : public Screen { public: WatchFaceCasioStyleG7710(DisplayApp* app, - Controllers::DateTime& dateTimeController, - Controllers::Battery& batteryController, - Controllers::Ble& bleController, - Controllers::NotificationManager& notificatioManager, - Controllers::Settings& settingsController, - Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController); + Controllers::DateTime& dateTimeController, + Controllers::Battery& batteryController, + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager, + Controllers::Settings& settingsController, + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController); ~WatchFaceCasioStyleG7710() override; void Refresh() override; @@ -62,7 +62,7 @@ namespace Pinetime { lv_point_t line_date_points[3] {{0, 5}, {135, 5}, {140, 0}}; lv_point_t line_time_points[3] {{0, 0}, {230, 0}, {235, 5}}; - lv_color_t color_text = lv_color_hex(0x98B69A); + lv_color_t color_text = lv_color_hex(0x98B69A); lv_style_t style_line; lv_style_t style_border; diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 3c88b936..52ea5d9e 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -17,14 +17,12 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine settingsController {settingsController}, screens {app, settingsController.GetWatchfacesMenu(), - { - [this]() -> std::unique_ptr { - return CreateScreen1(); - }, - [this]() -> std::unique_ptr { - return CreateScreen2(); - } - }, + {[this]() -> std::unique_ptr { + return CreateScreen1(); + }, + [this]() -> std::unique_ptr { + return CreateScreen2(); + }}, Screens::ScreenListModes::UpDown} { } @@ -39,16 +37,12 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) { std::unique_ptr SettingWatchFace::CreateScreen1() { std::array watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; - return std::make_unique(0, 2, app, settingsController, title, - symbol, &Controllers::Settings::SetClockFace, - &Controllers::Settings::GetClockFace, - watchfaces); + return std::make_unique( + 0, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces); } std::unique_ptr SettingWatchFace::CreateScreen2() { std::array watchfaces {" Casio G7710", "", "", ""}; - return std::make_unique(1, 2, app, settingsController, title, - symbol, &Controllers::Settings::SetClockFace, - &Controllers::Settings::GetClockFace, - watchfaces); + return std::make_unique( + 1, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces); } -- cgit v1.2.3-70-g09d2 From b4f4e2f3fed1ce241daaadbcc4b7eb3d4735f14d Mon Sep 17 00:00:00 2001 From: Autoformatter <-> Date: Thu, 2 Jun 2022 06:42:50 +0000 Subject: Apply clang-format to Clock.cpp --- src/displayapp/screens/Clock.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 4e76af18..cd4288a1 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -110,11 +110,11 @@ std::unique_ptr Clock::WatchFaceTerminalScreen() { std::unique_ptr Clock::WatchFaceCasioStyleG7710() { return std::make_unique(app, - dateTimeController, - batteryController, - bleController, - notificatioManager, - settingsController, - heartRateController, - motionController); + dateTimeController, + batteryController, + bleController, + notificatioManager, + settingsController, + heartRateController, + motionController); } -- cgit v1.2.3-70-g09d2 From 26af507e165dc6eab54260570437a8d411aca880 Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Wed, 28 Sep 2022 21:09:00 +0200 Subject: G7710 : free fonts in dtor(). --- .../screens/WatchFaceCasioStyleG7710.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index ad124ea1..4ef2839c 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -102,17 +102,17 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, line_icons = lv_line_create(lv_scr_act(), nullptr); lv_line_set_points(line_icons, line_icons_points, 3); lv_obj_add_style(line_icons, LV_LINE_PART_MAIN, &style_line); - lv_obj_align(line_icons, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 18); + lv_obj_align(line_icons, nullptr, LV_ALIGN_IN_TOP_RIGHT, -10, 18); line_day_of_week_number = lv_line_create(lv_scr_act(), nullptr); lv_line_set_points(line_day_of_week_number, line_day_of_week_number_points, 4); lv_obj_add_style(line_day_of_week_number, LV_LINE_PART_MAIN, &style_border); - lv_obj_align(line_day_of_week_number, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 8); + lv_obj_align(line_day_of_week_number, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 8); line_day_of_year = lv_line_create(lv_scr_act(), nullptr); lv_line_set_points(line_day_of_year, line_day_of_year_points, 3); lv_obj_add_style(line_day_of_year, LV_LINE_PART_MAIN, &style_line); - lv_obj_align(line_day_of_year, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 60); + lv_obj_align(line_day_of_year, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 60); label_date = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 70); @@ -123,7 +123,7 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, line_date = lv_line_create(lv_scr_act(), nullptr); lv_line_set_points(line_date, line_date_points, 3); lv_obj_add_style(line_date, LV_LINE_PART_MAIN, &style_line); - lv_obj_align(line_date, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 100); + lv_obj_align(line_date, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 100); label_time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); @@ -133,7 +133,7 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, line_time = lv_line_create(lv_scr_act(), nullptr); lv_line_set_points(line_time, line_time_points, 3); lv_obj_add_style(line_time, LV_LINE_PART_MAIN, &style_line); - lv_obj_align(line_time, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -25); + lv_obj_align(line_time, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -25); label_time_ampm = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_time_ampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); @@ -177,6 +177,18 @@ WatchFaceCasioStyleG7710::~WatchFaceCasioStyleG7710() { lv_style_reset(&style_line); lv_style_reset(&style_border); + if (font_dot40 != nullptr) { + lv_font_free(font_dot40); + } + + if (font_segment40 != nullptr) { + lv_font_free(font_segment40); + } + + if (font_segment115 != nullptr) { + lv_font_free(font_segment115); + } + lv_obj_clean(lv_scr_act()); } -- cgit v1.2.3-70-g09d2 From d3363baf696968b0ed17478f620774c66bac55f9 Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Wed, 28 Sep 2022 21:45:52 +0200 Subject: Do not save settings in CheckboxList. This will be done by the caller. --- src/displayapp/screens/CheckboxList.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/CheckboxList.cpp b/src/displayapp/screens/CheckboxList.cpp index b89add43..952d86da 100644 --- a/src/displayapp/screens/CheckboxList.cpp +++ b/src/displayapp/screens/CheckboxList.cpp @@ -98,7 +98,6 @@ CheckboxList::CheckboxList(const uint8_t screenID, CheckboxList::~CheckboxList() { lv_obj_clean(lv_scr_act()); - settingsController.SaveSettings(); } void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) { -- cgit v1.2.3-70-g09d2 From d6b4ef38f6c070dc27577ae371d3b0b86d5aec3b Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Sat, 1 Oct 2022 21:03:28 +0200 Subject: Infineat & G7710 : always close files when they are not needed anymore. --- src/displayapp/screens/WatchFaceCasioStyleG7710.cpp | 3 +++ src/displayapp/screens/WatchFaceInfineat.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index 4ef2839c..f9a01abd 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -36,14 +36,17 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, lfs_file f = {}; if (filesystem.FileOpen(&f, "/fonts/lv_font_dots_40.bin", LFS_O_RDONLY) >= 0) { + filesystem.FileClose(&f); font_dot40 = lv_font_load("F:/fonts/lv_font_dots_40.bin"); } if (filesystem.FileOpen(&f, "/fonts/7segments_40.bin", LFS_O_RDONLY) >= 0) { + filesystem.FileClose(&f); font_segment40 = lv_font_load("F:/fonts/7segments_40.bin"); } if (filesystem.FileOpen(&f, "/fonts/7segments_115.bin", LFS_O_RDONLY) >= 0) { + filesystem.FileClose(&f); font_segment115 = lv_font_load("F:/fonts/7segments_115.bin"); } diff --git a/src/displayapp/screens/WatchFaceInfineat.cpp b/src/displayapp/screens/WatchFaceInfineat.cpp index e3ed1bf7..ae3f3dbb 100644 --- a/src/displayapp/screens/WatchFaceInfineat.cpp +++ b/src/displayapp/screens/WatchFaceInfineat.cpp @@ -27,7 +27,7 @@ WatchFaceInfineat::WatchFaceInfineat(DisplayApp* app, Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::MotionController& motionController, - Controllers::FS& fs) + Controllers::FS& filesystem) : Screen(app), currentDateTime {{}}, dateTimeController {dateTimeController}, @@ -37,11 +37,13 @@ WatchFaceInfineat::WatchFaceInfineat(DisplayApp* app, settingsController {settingsController}, motionController {motionController} { lfs_file f = {}; - if (fs.FileOpen(&f, "/fonts/teko.bin", LFS_O_RDONLY) >= 0) { + if (filesystem.FileOpen(&f, "/fonts/teko.bin", LFS_O_RDONLY) >= 0) { + filesystem.FileClose(&f); font_teko = lv_font_load("F:/fonts/teko.bin"); } - if (fs.FileOpen(&f, "/fonts/bebas.bin", LFS_O_RDONLY) >= 0) { + if (filesystem.FileOpen(&f, "/fonts/bebas.bin", LFS_O_RDONLY) >= 0) { + filesystem.FileClose(&f); font_bebas = lv_font_load("F:/fonts/bebas.bin"); } -- cgit v1.2.3-70-g09d2