From 4901cc9fd878ae3034d2aa3a42c284c8d0c9e668 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Sun, 28 Aug 2022 11:57:53 +0000 Subject: [PATCH 01/13] Copied exising watch face to new WatchFaceAccurateWords --- src/displayapp/screens/Clock.cpp | 16 ++ src/displayapp/screens/Clock.h | 1 + .../screens/WatchFaceAccurateWords.cpp | 178 ++++++++++++++++++ .../screens/WatchFaceAccurateWords.h | 79 ++++++++ .../screens/settings/SettingWatchFace.cpp | 2 +- .../screens/settings/SettingWatchFace.h | 2 +- 6 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 src/displayapp/screens/WatchFaceAccurateWords.cpp create mode 100644 src/displayapp/screens/WatchFaceAccurateWords.h diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 1687dccf..178e81a7 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -12,6 +12,8 @@ #include "displayapp/screens/WatchFaceTerminal.h" #include "displayapp/screens/WatchFaceAnalog.h" #include "displayapp/screens/WatchFacePineTimeStyle.h" +#include "displayapp/screens/WatchFaceAccurateWords.h" + using namespace Pinetime::Applications::Screens; @@ -45,6 +47,9 @@ Clock::Clock(DisplayApp* app, case 3: return WatchFaceTerminalScreen(); break; + case 4: + return WatchFaceAccurateWordsScreen(); + break; } return WatchFaceDigitalScreen(); }()} { @@ -103,3 +108,14 @@ std::unique_ptr Clock::WatchFaceTerminalScreen() { heartRateController, motionController); } + +std::unique_ptr Clock::WatchFaceAccurateWordsScreen() { + 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..88bb5b10 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 WatchFaceAccurateWordsScreen(); }; } } diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp new file mode 100644 index 00000000..bcc8e8d7 --- /dev/null +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -0,0 +1,178 @@ +#include "displayapp/screens/WatchFaceAccurateWords.h" + +#include +#include +#include +#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; + +WatchFaceAccurateWords::WatchFaceAccurateWords(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}, + notificatioManager {notificatioManager}, + settingsController {settingsController}, + heartRateController {heartRateController}, + motionController {motionController}, + statusIcons(batteryController, bleController) { + + statusIcons.Create(); + + 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_LIME); + lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); + + label_date = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); + lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + + label_time = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_extrabold_compressed); + + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); + + label_time_ampm = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(label_time_ampm, ""); + lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55); + + 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(0xCE1B1B)); + lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + + heartbeatValue = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); + 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(0x00FFE7)); + lv_label_set_text_static(stepValue, "0"); + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + + stepIcon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7)); + lv_label_set_text_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(); +} + +WatchFaceAccurateWords::~WatchFaceAccurateWords() { + lv_task_del(taskRefresh); + lv_obj_clean(lv_scr_act()); +} + +void WatchFaceAccurateWords::Refresh() { + statusIcons.Update(); + + 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(); + + if (displayedHour != hour || displayedMinute != minute) { + displayedHour = hour; + displayedMinute = minute; + + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { + char ampmChar[3] = "AM"; + if (hour == 0) { + hour = 12; + } else if (hour == 12) { + ampmChar[0] = 'P'; + } else if (hour > 12) { + hour = hour - 12; + ampmChar[0] = 'P'; + } + 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_IN_RIGHT_MID, 0, 0); + } else { + lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + } + } + + if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { + lv_label_set_text_fmt(label_date, + "%s %d %s %d", + dateTimeController.DayOfWeekShortToString(), + day, + dateTimeController.MonthShortToString(), + year); + } else { + lv_label_set_text_fmt(label_date, + "%s %s %d %d", + dateTimeController.DayOfWeekShortToString(), + dateTimeController.MonthShortToString(), + day, + year); + } + 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(0xCE1B1B)); + 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/WatchFaceAccurateWords.h b/src/displayapp/screens/WatchFaceAccurateWords.h new file mode 100644 index 00000000..2689621f --- /dev/null +++ b/src/displayapp/screens/WatchFaceAccurateWords.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include +#include +#include +#include "displayapp/screens/Screen.h" +#include "components/datetime/DateTimeController.h" +#include "components/ble/BleController.h" +#include "displayapp/widgets/StatusIcons.h" + +namespace Pinetime { + namespace Controllers { + class Settings; + class Battery; + class Ble; + class NotificationManager; + class HeartRateController; + class MotionController; + } + + namespace Applications { + namespace Screens { + + class WatchFaceAccurateWords : public Screen { + public: + WatchFaceAccurateWords(DisplayApp* app, + Controllers::DateTime& dateTimeController, + Controllers::Battery& batteryController, + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager, + Controllers::Settings& settingsController, + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController); + ~WatchFaceAccurateWords() 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* label_time_ampm; + lv_obj_t* label_date; + lv_obj_t* heartbeatIcon; + lv_obj_t* heartbeatValue; + lv_obj_t* stepIcon; + lv_obj_t* stepValue; + lv_obj_t* notificationIcon; + + Controllers::DateTime& dateTimeController; + Controllers::NotificationManager& notificatioManager; + Controllers::Settings& settingsController; + Controllers::HeartRateController& heartRateController; + Controllers::MotionController& motionController; + + lv_task_t* taskRefresh; + Widgets::StatusIcons statusIcons; + }; + } + } +} diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index be595a74..bbbdc093 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -14,7 +14,7 @@ namespace { } } -constexpr std::array SettingWatchFace::options; +constexpr std::array SettingWatchFace::options; SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) : Screen(app), settingsController {settingsController} { diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index d65f4a22..19b0ceec 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -20,7 +20,7 @@ namespace Pinetime { void UpdateSelected(lv_obj_t* object, lv_event_t event); private: - static constexpr std::array options = {"Digital face", "Analog face", "PineTimeStyle", "Terminal"}; + static constexpr std::array options = {"Digital face", "Analog face", "PineTimeStyle", "Terminal", "Words"}; Controllers::Settings& settingsController; lv_obj_t* cbOption[options.size()]; From 66f70d8af11e277c0cd87adfc8cb0bd71ce04e2a Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Sun, 28 Aug 2022 12:43:55 +0000 Subject: [PATCH 02/13] WatchFaceAccurateWords - description of current time accurate to a minute --- .../screens/WatchFaceAccurateWords.cpp | 105 ++++++++++++------ 1 file changed, 68 insertions(+), 37 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index bcc8e8d7..02ddde7d 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -43,13 +43,11 @@ WatchFaceAccurateWords::WatchFaceAccurateWords(DisplayApp* app, lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); label_time = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_extrabold_compressed); - - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); - - label_time_ampm = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(label_time_ampm, ""); - lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55); + lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); + lv_label_set_long_mode(label_time, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label_time, LV_HOR_RES - 20); + lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); @@ -105,45 +103,78 @@ void WatchFaceAccurateWords::Refresh() { uint8_t hour = time.hours().count(); uint8_t minute = time.minutes().count(); + uint8_t hour_adjusted = time.hours().count(); + char words[78]; + char part_day[20]; + const char hour_word_array[26][10] = { + "midnight", "one", "two", + "three", "four", "five", + "six", "seven", "eight", + "nine", "ten", "eleven", + "twelve", + "one", "two", + "three", "four", "five", + "six", "seven", "eight", + "nine", "ten", "eleven", + "midnight" + }; + const char part_day_word_array[9][20] = { + " at night", + " in the early hours", + " in the morning", + " in the morning", + " in the afternoon", + " in the afternoon", + " in the evening", + " at night" + }; + const char minutes_rough_array[14][18] = { + "", "five past ", + "ten past ", "quarter past ", + "twenty past ", "twenty-five past ", + "half past ", "twenty-five to ", + "twenty to ", "quarter to ", "ten to ", + "five to " + "" + }; + const char minutes_accurate_array[6][16] = { + "", "just gone ", "a little after ", + "coming up to ", "almost " + }; + if (displayedHour != hour || displayedMinute != minute) { displayedHour = hour; displayedMinute = minute; - - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { - char ampmChar[3] = "AM"; - if (hour == 0) { - hour = 12; - } else if (hour == 12) { - ampmChar[0] = 'P'; - } else if (hour > 12) { - hour = hour - 12; - ampmChar[0] = 'P'; + if(minute>32) { + hour_adjusted = (hour+1) % 24; } - 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_IN_RIGHT_MID, 0, 0); - } else { - lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + + if (hour_adjusted != 0 && hour_adjusted != 12) { + sprintf(part_day, "%s", part_day_word_array[hour_adjusted/3]); } + else { + sprintf(part_day, ""); + } + sprintf(words, "%s%s%s%s", + minutes_accurate_array[(minute)%5], + minutes_rough_array[(minute+2)/5], + hour_word_array[hour_adjusted], + part_day); + // Make first letter Uppercase + words[0]=words[0]-32; + + lv_label_set_text_fmt(label_time, "%s", words); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, -40); } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { - lv_label_set_text_fmt(label_date, - "%s %d %s %d", + lv_label_set_text_fmt(label_date, + "%s %d-%d-%d", dateTimeController.DayOfWeekShortToString(), - day, - dateTimeController.MonthShortToString(), - year); - } else { - lv_label_set_text_fmt(label_date, - "%s %s %d %d", - dateTimeController.DayOfWeekShortToString(), - dateTimeController.MonthShortToString(), - day, - year); - } + year, + month, + day + ); lv_obj_realign(label_date); currentYear = year; From d846cb1b747e15c8d803caac54c84244ddbb8dce Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Sun, 28 Aug 2022 13:04:16 +0000 Subject: [PATCH 03/13] Updateing CMakeLists --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db4a8e2a..a1cce91f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -428,6 +428,7 @@ list(APPEND SOURCE_FILES displayapp/screens/WatchFaceDigital.cpp displayapp/screens/WatchFaceTerminal.cpp displayapp/screens/WatchFacePineTimeStyle.cpp + displayapp/screens/WatchFaceAccurateWords.cpp ## From 0b1bec0ae95d6c466bc69b59d66dc204277f0660 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Sun, 28 Aug 2022 13:31:23 +0000 Subject: [PATCH 04/13] Fixing initial value of hour_adjusted --- src/displayapp/screens/WatchFaceAccurateWords.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index 02ddde7d..dd55ed3c 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -103,7 +103,7 @@ void WatchFaceAccurateWords::Refresh() { uint8_t hour = time.hours().count(); uint8_t minute = time.minutes().count(); - uint8_t hour_adjusted = time.hours().count(); + uint8_t hour_adjusted; char words[78]; char part_day[20]; const char hour_word_array[26][10] = { @@ -145,9 +145,13 @@ void WatchFaceAccurateWords::Refresh() { if (displayedHour != hour || displayedMinute != minute) { displayedHour = hour; displayedMinute = minute; + if(minute>32) { hour_adjusted = (hour+1) % 24; - } + } + else { + hour_adjusted = hour; + } if (hour_adjusted != 0 && hour_adjusted != 12) { sprintf(part_day, "%s", part_day_word_array[hour_adjusted/3]); From 99785b88a33d3966846fe36ab5893e72e5639423 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Sun, 28 Aug 2022 20:08:25 +0000 Subject: [PATCH 05/13] Date in words (exlcuding year) --- .../screens/WatchFaceAccurateWords.cpp | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index dd55ed3c..fd40bc51 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -39,8 +39,11 @@ WatchFaceAccurateWords::WatchFaceAccurateWords(DisplayApp* app, lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); label_date = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + lv_label_set_long_mode(label_date, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label_date, LV_HOR_RES - 20); + lv_label_set_align(label_date, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); label_time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); @@ -140,8 +143,34 @@ void WatchFaceAccurateWords::Refresh() { const char minutes_accurate_array[6][16] = { "", "just gone ", "a little after ", "coming up to ", "almost " - }; - + }; + const char days_array[9][10] = { + "", + "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday", + "Sunday" + }; + const char months_array[13][10] = { + "", + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", + "December" + }; + const char months_numbers_array[32][15] = { + "zero", "first", "second", "third", + "fourth", "fifth", "sixth", "seventh", + "eighth", "ninth", "tenth", "eleventh", + "twelfth", "thirteenth", "fourteenth", + "fifteenth", "sixteenth", "seventeenth", + "eighteenth", "nineteenth", "twentieth", + "twenty-first", "twenty-second", + "twenty-third", "twenty-fourth", + "twenty-fifth", "twenty-sixth", + "twenty-seventh", "twenty-eighth", + "twenty-ninth", "thirtieth", + "thirty-first" + }; if (displayedHour != hour || displayedMinute != minute) { displayedHour = hour; displayedMinute = minute; @@ -169,17 +198,16 @@ void WatchFaceAccurateWords::Refresh() { lv_label_set_text_fmt(label_time, "%s", words); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, -40); - } - if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - lv_label_set_text_fmt(label_date, - "%s %d-%d-%d", - dateTimeController.DayOfWeekShortToString(), - year, - month, - day - ); - lv_obj_realign(label_date); + lv_label_set_text_fmt(label_date,"%s, %s of %s", + days_array[static_cast(dayOfWeek)], + months_numbers_array[static_cast(day)], + months_array[static_cast(month)] + ); + // Maximum lenght of date in words +// lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); + + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); currentYear = year; currentMonth = month; From 1ca2c2ad3490ad0c54b3053c1995e4189c7d5806 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Mon, 5 Sep 2022 19:55:15 +0000 Subject: [PATCH 06/13] Specific dates have specific names --- .../screens/WatchFaceAccurateWords.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index fd40bc51..2f0a94ea 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -204,6 +204,45 @@ void WatchFaceAccurateWords::Refresh() { months_numbers_array[static_cast(day)], months_array[static_cast(month)] ); + + // Specific dates have specific names + if (static_cast(month) == 1 & static_cast(day) == 1) { + lv_label_set_text_fmt(label_date,"%s, New Year's Day", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 3 & static_cast(day) == 15) { + lv_label_set_text_fmt(label_date,"%s on the Ides of March", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 4 & static_cast(day) == 1) { + lv_label_set_text_fmt(label_date,"%s, ERROR C Nonsense in BASIC", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 7 & static_cast(day) == 1) { + lv_label_set_text_fmt(label_date,"%s - O'Canada", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 10 & static_cast(day) == 31) { + lv_label_set_text_fmt(label_date,"%s on Halloween", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 & static_cast(day) == 24) { + lv_label_set_text_fmt(label_date,"%s, Christmas Eve", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 & static_cast(day) == 25) { + lv_label_set_text_fmt(label_date,"%s, Christmas Day", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 & static_cast(day) == 26) { + lv_label_set_text_fmt(label_date,"%s, Boxing Day", + days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 & static_cast(day) == 31) { + lv_label_set_text_fmt(label_date,"%s, New Year's Eve", + days_array[static_cast(dayOfWeek)]); + } + // Maximum lenght of date in words // lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); From 6ae0d47461bb9be20aac23cc9ddd4d8106a01f13 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Thu, 15 Sep 2022 16:55:00 +0000 Subject: [PATCH 07/13] clang-format corrections --- src/displayapp/screens/Clock.cpp | 15 +- .../screens/WatchFaceAccurateWords.cpp | 189 +++++++----------- .../screens/WatchFaceAccurateWords.h | 14 +- 3 files changed, 89 insertions(+), 129 deletions(-) diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 178e81a7..5a54ba9d 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -14,7 +14,6 @@ #include "displayapp/screens/WatchFacePineTimeStyle.h" #include "displayapp/screens/WatchFaceAccurateWords.h" - using namespace Pinetime::Applications::Screens; Clock::Clock(DisplayApp* app, @@ -111,11 +110,11 @@ std::unique_ptr Clock::WatchFaceTerminalScreen() { std::unique_ptr Clock::WatchFaceAccurateWordsScreen() { return std::make_unique(app, - dateTimeController, - batteryController, - bleController, - notificatioManager, - settingsController, - heartRateController, - motionController); + dateTimeController, + batteryController, + bleController, + notificatioManager, + settingsController, + heartRateController, + motionController); } diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index 2f0a94ea..da1b1e51 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -15,13 +15,13 @@ using namespace Pinetime::Applications::Screens; WatchFaceAccurateWords::WatchFaceAccurateWords(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}, @@ -109,142 +109,103 @@ void WatchFaceAccurateWords::Refresh() { uint8_t hour_adjusted; char words[78]; char part_day[20]; - const char hour_word_array[26][10] = { - "midnight", "one", "two", - "three", "four", "five", - "six", "seven", "eight", - "nine", "ten", "eleven", - "twelve", - "one", "two", - "three", "four", "five", - "six", "seven", "eight", - "nine", "ten", "eleven", - "midnight" - }; - const char part_day_word_array[9][20] = { - " at night", - " in the early hours", - " in the morning", - " in the morning", - " in the afternoon", - " in the afternoon", - " in the evening", - " at night" - }; - const char minutes_rough_array[14][18] = { - "", "five past ", - "ten past ", "quarter past ", - "twenty past ", "twenty-five past ", - "half past ", "twenty-five to ", - "twenty to ", "quarter to ", "ten to ", - "five to " - "" - }; - const char minutes_accurate_array[6][16] = { - "", "just gone ", "a little after ", - "coming up to ", "almost " - }; - const char days_array[9][10] = { - "", - "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday", - "Sunday" - }; - const char months_array[13][10] = { - "", - "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", - "December" - }; + const char hour_word_array[26][10] = {"midnight", "one", "two", "three", "four", "five", "six", "seven", "eight", + "nine", "ten", "eleven", "twelve", "one", "two", "three", "four", "five", + "six", "seven", "eight", "nine", "ten", "eleven", "midnight"}; + const char part_day_word_array[9][20] = {" at night", + " in the early hours", + " in the morning", + " in the morning", + " in the afternoon", + " in the afternoon", + " in the evening", + " at night"}; + const char minutes_rough_array[14][18] = {"", + "five past ", + "ten past ", + "quarter past ", + "twenty past ", + "twenty-five past ", + "half past ", + "twenty-five to ", + "twenty to ", + "quarter to ", + "ten to ", + "five to " + ""}; + const char minutes_accurate_array[6][16] = {"", "just gone ", "a little after ", "coming up to ", "almost "}; + const char days_array[9][10] = {"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; + const char months_array[13][10] = + {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; const char months_numbers_array[32][15] = { - "zero", "first", "second", "third", - "fourth", "fifth", "sixth", "seventh", - "eighth", "ninth", "tenth", "eleventh", - "twelfth", "thirteenth", "fourteenth", - "fifteenth", "sixteenth", "seventeenth", - "eighteenth", "nineteenth", "twentieth", - "twenty-first", "twenty-second", - "twenty-third", "twenty-fourth", - "twenty-fifth", "twenty-sixth", - "twenty-seventh", "twenty-eighth", - "twenty-ninth", "thirtieth", - "thirty-first" - }; + "zero", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", + "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", + "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth", "twenty-first", "twenty-second", "twenty-third", + "twenty-fourth", "twenty-fifth", "twenty-sixth", "twenty-seventh", "twenty-eighth", "twenty-ninth", "thirtieth", "thirty-first"}; if (displayedHour != hour || displayedMinute != minute) { displayedHour = hour; displayedMinute = minute; - if(minute>32) { - hour_adjusted = (hour+1) % 24; + if (minute > 32) { + hour_adjusted = (hour + 1) % 24; + } else { + hour_adjusted = hour; } - else { - hour_adjusted = hour; - } if (hour_adjusted != 0 && hour_adjusted != 12) { - sprintf(part_day, "%s", part_day_word_array[hour_adjusted/3]); - } - else { + sprintf(part_day, "%s", part_day_word_array[hour_adjusted / 3]); + } else { sprintf(part_day, ""); } - sprintf(words, "%s%s%s%s", - minutes_accurate_array[(minute)%5], - minutes_rough_array[(minute+2)/5], - hour_word_array[hour_adjusted], - part_day); + sprintf(words, + "%s%s%s%s", + minutes_accurate_array[(minute) % 5], + minutes_rough_array[(minute + 2) / 5], + hour_word_array[hour_adjusted], + part_day); // Make first letter Uppercase - words[0]=words[0]-32; + words[0] = words[0] - 32; lv_label_set_text_fmt(label_time, "%s", words); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, -40); - lv_label_set_text_fmt(label_date,"%s, %s of %s", + lv_label_set_text_fmt(label_date, + "%s, %s of %s", days_array[static_cast(dayOfWeek)], months_numbers_array[static_cast(day)], - months_array[static_cast(month)] - ); - + months_array[static_cast(month)]); + // Specific dates have specific names if (static_cast(month) == 1 & static_cast(day) == 1) { - lv_label_set_text_fmt(label_date,"%s, New Year's Day", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s, New Year's Day", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 3 & static_cast(day) == 15) { - lv_label_set_text_fmt(label_date,"%s on the Ides of March", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s on the Ides of March", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 4 & static_cast(day) == 1) { - lv_label_set_text_fmt(label_date,"%s, ERROR C Nonsense in BASIC", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s, ERROR C Nonsense in BASIC", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 7 & static_cast(day) == 1) { - lv_label_set_text_fmt(label_date,"%s - O'Canada", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s - O'Canada", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 10 & static_cast(day) == 31) { - lv_label_set_text_fmt(label_date,"%s on Halloween", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s on Halloween", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 12 & static_cast(day) == 24) { - lv_label_set_text_fmt(label_date,"%s, Christmas Eve", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s, Christmas Eve", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 12 & static_cast(day) == 25) { - lv_label_set_text_fmt(label_date,"%s, Christmas Day", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s, Christmas Day", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 12 & static_cast(day) == 26) { - lv_label_set_text_fmt(label_date,"%s, Boxing Day", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s, Boxing Day", days_array[static_cast(dayOfWeek)]); + } if (static_cast(month) == 12 & static_cast(day) == 31) { - lv_label_set_text_fmt(label_date,"%s, New Year's Eve", - days_array[static_cast(dayOfWeek)]); - } + lv_label_set_text_fmt(label_date, "%s, New Year's Eve", days_array[static_cast(dayOfWeek)]); + } // Maximum lenght of date in words -// lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); + // lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); diff --git a/src/displayapp/screens/WatchFaceAccurateWords.h b/src/displayapp/screens/WatchFaceAccurateWords.h index 2689621f..c3eee38c 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.h +++ b/src/displayapp/screens/WatchFaceAccurateWords.h @@ -25,13 +25,13 @@ namespace Pinetime { class WatchFaceAccurateWords : public Screen { public: WatchFaceAccurateWords(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); ~WatchFaceAccurateWords() override; void Refresh() override; From 4bc27cd59348f86b791d99afb832763c37d1ee39 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Thu, 15 Sep 2022 19:16:47 +0000 Subject: [PATCH 08/13] Use pointers in const char arrays --- .../screens/WatchFaceAccurateWords.cpp | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index da1b1e51..8e97e0fe 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -109,35 +109,35 @@ void WatchFaceAccurateWords::Refresh() { uint8_t hour_adjusted; char words[78]; char part_day[20]; - const char hour_word_array[26][10] = {"midnight", "one", "two", "three", "four", "five", "six", "seven", "eight", - "nine", "ten", "eleven", "twelve", "one", "two", "three", "four", "five", - "six", "seven", "eight", "nine", "ten", "eleven", "midnight"}; - const char part_day_word_array[9][20] = {" at night", - " in the early hours", - " in the morning", - " in the morning", - " in the afternoon", - " in the afternoon", - " in the evening", - " at night"}; - const char minutes_rough_array[14][18] = {"", - "five past ", - "ten past ", - "quarter past ", - "twenty past ", - "twenty-five past ", - "half past ", - "twenty-five to ", - "twenty to ", - "quarter to ", - "ten to ", - "five to " - ""}; - const char minutes_accurate_array[6][16] = {"", "just gone ", "a little after ", "coming up to ", "almost "}; - const char days_array[9][10] = {"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; - const char months_array[13][10] = + const char* hour_word_array[26] = {"midnight", "one", "two", "three", "four", "five", "six", "seven", "eight", + "nine", "ten", "eleven", "twelve", "one", "two", "three", "four", "five", + "six", "seven", "eight", "nine", "ten", "eleven", "midnight"}; + const char* part_day_word_array[9] = {" at night", + " in the early hours", + " in the morning", + " in the morning", + " in the afternoon", + " in the afternoon", + " in the evening", + " at night"}; + const char* minutes_rough_array[14] = {"", + "five past ", + "ten past ", + "quarter past ", + "twenty past ", + "twenty-five past ", + "half past ", + "twenty-five to ", + "twenty to ", + "quarter to ", + "ten to ", + "five to " + ""}; + const char* minutes_accurate_array[6] = {"", "just gone ", "a little after ", "coming up to ", "almost "}; + const char* days_array[9] = {"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; + const char* months_array[13] = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; - const char months_numbers_array[32][15] = { + const char* months_numbers_array[32] = { "zero", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth", "twenty-first", "twenty-second", "twenty-third", From ac93d51090fe6b4cacb987f1ed3acf193ef60cf1 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Thu, 15 Sep 2022 19:27:55 +0000 Subject: [PATCH 09/13] Correcting ampersand. Update date only on date change --- .../screens/WatchFaceAccurateWords.cpp | 88 ++++++++++--------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index 8e97e0fe..2ec0e2b3 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -169,50 +169,52 @@ void WatchFaceAccurateWords::Refresh() { lv_label_set_text_fmt(label_time, "%s", words); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, -40); - lv_label_set_text_fmt(label_date, - "%s, %s of %s", - days_array[static_cast(dayOfWeek)], - months_numbers_array[static_cast(day)], - months_array[static_cast(month)]); - - // Specific dates have specific names - if (static_cast(month) == 1 & static_cast(day) == 1) { - lv_label_set_text_fmt(label_date, "%s, New Year's Day", days_array[static_cast(dayOfWeek)]); + if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { + lv_label_set_text_fmt(label_date, + "%s, %s of %s", + days_array[static_cast(dayOfWeek)], + months_numbers_array[static_cast(day)], + months_array[static_cast(month)]); + + // Specific dates have specific names + if (static_cast(month) == 1 && static_cast(day) == 1) { + lv_label_set_text_fmt(label_date, "%s, New Year's Day", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 3 && static_cast(day) == 15) { + lv_label_set_text_fmt(label_date, "%s on the Ides of March", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 4 && static_cast(day) == 1) { + lv_label_set_text_fmt(label_date, "%s, ERROR C Nonsense in BASIC", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 7 && static_cast(day) == 1) { + lv_label_set_text_fmt(label_date, "%s - O'Canada", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 10 && static_cast(day) == 31) { + lv_label_set_text_fmt(label_date, "%s on Halloween", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 && static_cast(day) == 24) { + lv_label_set_text_fmt(label_date, "%s, Christmas Eve", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 && static_cast(day) == 25) { + lv_label_set_text_fmt(label_date, "%s, Christmas Day", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 && static_cast(day) == 26) { + lv_label_set_text_fmt(label_date, "%s, Boxing Day", days_array[static_cast(dayOfWeek)]); + } + if (static_cast(month) == 12 && static_cast(day) == 31) { + lv_label_set_text_fmt(label_date, "%s, New Year's Eve", days_array[static_cast(dayOfWeek)]); + } + + // Maximum lenght of date in words + // lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); + + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); + + currentYear = year; + currentMonth = month; + currentDayOfWeek = dayOfWeek; + currentDay = day; } - if (static_cast(month) == 3 & static_cast(day) == 15) { - lv_label_set_text_fmt(label_date, "%s on the Ides of March", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 4 & static_cast(day) == 1) { - lv_label_set_text_fmt(label_date, "%s, ERROR C Nonsense in BASIC", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 7 & static_cast(day) == 1) { - lv_label_set_text_fmt(label_date, "%s - O'Canada", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 10 & static_cast(day) == 31) { - lv_label_set_text_fmt(label_date, "%s on Halloween", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 & static_cast(day) == 24) { - lv_label_set_text_fmt(label_date, "%s, Christmas Eve", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 & static_cast(day) == 25) { - lv_label_set_text_fmt(label_date, "%s, Christmas Day", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 & static_cast(day) == 26) { - lv_label_set_text_fmt(label_date, "%s, Boxing Day", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 & static_cast(day) == 31) { - lv_label_set_text_fmt(label_date, "%s, New Year's Eve", days_array[static_cast(dayOfWeek)]); - } - - // Maximum lenght of date in words - // lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); - - lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); - - currentYear = year; - currentMonth = month; - currentDayOfWeek = dayOfWeek; - currentDay = day; } } From 866295676d39364a11ff1997f7cfca25162c6ccb Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Thu, 15 Sep 2022 19:29:31 +0000 Subject: [PATCH 10/13] Clang-format --- src/displayapp/screens/WatchFaceAccurateWords.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index 2ec0e2b3..26b1ca4a 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -175,7 +175,7 @@ void WatchFaceAccurateWords::Refresh() { days_array[static_cast(dayOfWeek)], months_numbers_array[static_cast(day)], months_array[static_cast(month)]); - + // Specific dates have specific names if (static_cast(month) == 1 && static_cast(day) == 1) { lv_label_set_text_fmt(label_date, "%s, New Year's Day", days_array[static_cast(dayOfWeek)]); @@ -204,12 +204,12 @@ void WatchFaceAccurateWords::Refresh() { if (static_cast(month) == 12 && static_cast(day) == 31) { lv_label_set_text_fmt(label_date, "%s, New Year's Eve", days_array[static_cast(dayOfWeek)]); } - + // Maximum lenght of date in words // lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); - + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); - + currentYear = year; currentMonth = month; currentDayOfWeek = dayOfWeek; From bea1d3814fae76adec8a0c7a3f9d92c38aa7c0e1 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Sat, 17 Sep 2022 20:32:38 +0000 Subject: [PATCH 11/13] Eliminating null length strings - c++ is harder than python --- .../screens/WatchFaceAccurateWords.cpp | 103 +++++++++++------- 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index 26b1ca4a..d276965f 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -105,10 +105,11 @@ void WatchFaceAccurateWords::Refresh() { uint8_t hour = time.hours().count(); uint8_t minute = time.minutes().count(); + uint8_t monthInt = static_cast(month); + uint8_t dayInt = static_cast(day); uint8_t hour_adjusted; char words[78]; - char part_day[20]; const char* hour_word_array[26] = {"midnight", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "midnight"}; @@ -120,7 +121,7 @@ void WatchFaceAccurateWords::Refresh() { " in the afternoon", " in the evening", " at night"}; - const char* minutes_rough_array[14] = {"", + const char* minutes_rough_array[14] = {"--", "five past ", "ten past ", "quarter past ", @@ -132,11 +133,11 @@ void WatchFaceAccurateWords::Refresh() { "quarter to ", "ten to ", "five to " - ""}; - const char* minutes_accurate_array[6] = {"", "just gone ", "a little after ", "coming up to ", "almost "}; - const char* days_array[9] = {"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; + "--"}; + const char* minutes_accurate_array[6] = {"--", "just gone ", "a little after ", "coming up to ", "almost "}; + const char* days_array[9] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; const char* months_array[13] = - {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; + {"--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; const char* months_numbers_array[32] = { "zero", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", @@ -146,23 +147,51 @@ void WatchFaceAccurateWords::Refresh() { displayedHour = hour; displayedMinute = minute; + // At 33 past the hours we start referign to the next hour if (minute > 32) { hour_adjusted = (hour + 1) % 24; } else { hour_adjusted = hour; } - if (hour_adjusted != 0 && hour_adjusted != 12) { - sprintf(part_day, "%s", part_day_word_array[hour_adjusted / 3]); + if ((hour_adjusted == 0 || hour_adjusted == 12) && minute == 0) { + // Example 12:00 = Twelve + sprintf(words, "%s", hour_word_array[hour_adjusted]); + } else if ((hour_adjusted == 0 || hour_adjusted == 12) && (((minute + 2) % 60) / 5 == 0)) { + // Example 23:59 = Almost midnight + sprintf(words, "%s%s", minutes_accurate_array[minute % 5], hour_word_array[hour_adjusted]); + } else if ((hour_adjusted == 0 || hour_adjusted == 12) && (minute % 5 == 0)) { + // Example 12:15 = Quarter past twelve + sprintf(words, "%s%s", minutes_rough_array[(minute + 2) / 5], hour_word_array[hour_adjusted]); + } else if (hour_adjusted == 0 || hour_adjusted == 12) { + // Example 00:16 = Just gone quarter past twelve + sprintf(words, "%s%s%s", minutes_accurate_array[minute % 5], minutes_rough_array[(minute + 2) / 5], hour_word_array[hour_adjusted]); + } else if (minute == 0) { + // Example 01:00 = One at night + sprintf(words, "%s%s", hour_word_array[hour_adjusted], part_day_word_array[hour_adjusted / 3]); + } else if (((minute + 2) % 60) / 5 == 0) { + // Example 17:01 = Just gone five in the afternoon + sprintf(words, + "%s%s%s", + minutes_accurate_array[minute % 5], + hour_word_array[hour_adjusted], + part_day_word_array[hour_adjusted / 3]); + } else if (minute % 5 == 0) { + // Example 05:25 = Twenty-five past five in the early hours + sprintf(words, + "%s%s%s", + minutes_rough_array[(minute + 2) / 5], + hour_word_array[hour_adjusted], + part_day_word_array[hour_adjusted / 3]); } else { - sprintf(part_day, ""); + // Example 22:33 = coming up to eleven at night + sprintf(words, + "%s%s%s%s", + minutes_accurate_array[minute % 5], + minutes_rough_array[(minute + 2) / 5], + hour_word_array[hour_adjusted], + part_day_word_array[hour_adjusted / 3]); } - sprintf(words, - "%s%s%s%s", - minutes_accurate_array[(minute) % 5], - minutes_rough_array[(minute + 2) / 5], - hour_word_array[hour_adjusted], - part_day); // Make first letter Uppercase words[0] = words[0] - 32; @@ -170,44 +199,34 @@ void WatchFaceAccurateWords::Refresh() { lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, -40); if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - lv_label_set_text_fmt(label_date, - "%s, %s of %s", - days_array[static_cast(dayOfWeek)], - months_numbers_array[static_cast(day)], - months_array[static_cast(month)]); - // Specific dates have specific names - if (static_cast(month) == 1 && static_cast(day) == 1) { + if (year == 1970) { + lv_label_set_text_fmt(label_date, "New Firmware"); + } else if (monthInt == 1 && dayInt == 1) { lv_label_set_text_fmt(label_date, "%s, New Year's Day", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 3 && static_cast(day) == 15) { + } else if (monthInt == 3 && dayInt == 15) { lv_label_set_text_fmt(label_date, "%s on the Ides of March", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 4 && static_cast(day) == 1) { + } else if (monthInt == 4 && dayInt == 1) { lv_label_set_text_fmt(label_date, "%s, ERROR C Nonsense in BASIC", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 7 && static_cast(day) == 1) { + } else if (monthInt == 7 && dayInt == 1) { lv_label_set_text_fmt(label_date, "%s - O'Canada", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 10 && static_cast(day) == 31) { + } else if (monthInt == 10 && dayInt == 31) { lv_label_set_text_fmt(label_date, "%s on Halloween", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 && static_cast(day) == 24) { + } else if (monthInt == 12 && dayInt == 24) { lv_label_set_text_fmt(label_date, "%s, Christmas Eve", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 && static_cast(day) == 25) { + } else if (monthInt == 12 && dayInt == 25) { lv_label_set_text_fmt(label_date, "%s, Christmas Day", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 && static_cast(day) == 26) { + } else if (monthInt == 12 && dayInt == 26) { lv_label_set_text_fmt(label_date, "%s, Boxing Day", days_array[static_cast(dayOfWeek)]); - } - if (static_cast(month) == 12 && static_cast(day) == 31) { + } else if (monthInt == 12 && dayInt == 31) { lv_label_set_text_fmt(label_date, "%s, New Year's Eve", days_array[static_cast(dayOfWeek)]); + } else { + lv_label_set_text_fmt(label_date, + "%s, %s of %s", + days_array[static_cast(dayOfWeek)], + months_numbers_array[dayInt], + months_array[monthInt]); } - - // Maximum lenght of date in words - // lv_label_set_text_fmt(label_date,"Wednesday, twenty-seventh of September"); - lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); currentYear = year; From 64cd0a6c7a616dff959ea180947f570ee87fa854 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Sat, 17 Sep 2022 20:50:27 +0000 Subject: [PATCH 12/13] Array[33] --- src/displayapp/screens/WatchFaceAccurateWords.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index d276965f..04092355 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -138,7 +138,7 @@ void WatchFaceAccurateWords::Refresh() { const char* days_array[9] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; const char* months_array[13] = {"--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; - const char* months_numbers_array[32] = { + const char* months_numbers_array[33] = { "zero", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth", "twenty-first", "twenty-second", "twenty-third", From 8084d8784baa0e73ecfe61b1fb71d9e5ac8d9405 Mon Sep 17 00:00:00 2001 From: "Brendan M. Sleight" Date: Fri, 7 Oct 2022 11:54:48 +0000 Subject: [PATCH 13/13] Missing comma at five to --- src/displayapp/screens/WatchFaceAccurateWords.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/WatchFaceAccurateWords.cpp b/src/displayapp/screens/WatchFaceAccurateWords.cpp index 04092355..a7319301 100644 --- a/src/displayapp/screens/WatchFaceAccurateWords.cpp +++ b/src/displayapp/screens/WatchFaceAccurateWords.cpp @@ -132,7 +132,7 @@ void WatchFaceAccurateWords::Refresh() { "twenty to ", "quarter to ", "ten to ", - "five to " + "five to ", "--"}; const char* minutes_accurate_array[6] = {"--", "just gone ", "a little after ", "coming up to ", "almost "}; const char* days_array[9] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};