From c77634ce320cdb9bbd9de136e409bd9a0ca64153 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:11:20 +0200 Subject: [PATCH 01/13] Added new screen: SettingSetTime --- .../screens/settings/SettingSetTime.cpp | 174 ++++++++++++++++++ .../screens/settings/SettingSetTime.h | 38 ++++ 2 files changed, 212 insertions(+) create mode 100644 src/displayapp/screens/settings/SettingSetTime.cpp create mode 100644 src/displayapp/screens/settings/SettingSetTime.h diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp new file mode 100644 index 00000000..22d1c011 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -0,0 +1,174 @@ +#include "SettingSetTime.h" +#include +#include +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t * obj, lv_event_t event) { + SettingSetTime* screen = static_cast(obj->user_data); + screen->HandleButtonPress(obj, event); + } +} + +SettingSetTime::SettingSetTime( + Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : + Screen(app), + dateTimeController {dateTimeController} +{ + + 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, 30, 60); + lv_obj_set_width(container1, LV_HOR_RES - 50); + lv_obj_set_height(container1, LV_VER_RES - 60); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(title, "Set current time"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + + lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + 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::clock); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + hoursValue = static_cast(dateTimeController.Hours()); + lblHours = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + + lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblColon1, ":"); + lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, -36, -8); + + minutesValue = static_cast(dateTimeController.Minutes()); + lblMinutes = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + + lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblColon2, ":"); + lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, 36, -8); + + lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblSeconds, "00"); + lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, 72, -6); + + btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); + btnHoursPlus->user_data = this; + lv_obj_set_size(btnHoursPlus, 50, 40); + lv_obj_align(btnHoursPlus, lv_scr_act(), LV_ALIGN_CENTER, -72, -50); + lv_obj_set_style_local_value_str(btnHoursPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnHoursPlus, event_handler); + + btnHoursMinus = lv_btn_create(lv_scr_act(), NULL); + btnHoursMinus->user_data = this; + lv_obj_set_size(btnHoursMinus, 50, 40); + lv_obj_align(btnHoursMinus, lv_scr_act(), LV_ALIGN_CENTER, -72, 40); + lv_obj_set_style_local_value_str(btnHoursMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnHoursMinus, event_handler); + + btnMinutesPlus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesPlus->user_data = this; + lv_obj_set_size(btnMinutesPlus, 50, 40); + lv_obj_align(btnMinutesPlus, lv_scr_act(), LV_ALIGN_CENTER, 0, -50); + lv_obj_set_style_local_value_str(btnMinutesPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnMinutesPlus, event_handler); + + btnMinutesMinus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesMinus->user_data = this; + lv_obj_set_size(btnMinutesMinus, 50, 40); + lv_obj_align(btnMinutesMinus, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); + lv_obj_set_style_local_value_str(btnMinutesMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnMinutesMinus, event_handler); + + btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime->user_data = this; + lv_obj_set_size(btnSetTime, 70, 40); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); + lv_obj_set_event_cb(btnSetTime, event_handler); +} + +SettingSetTime::~SettingSetTime() { + lv_obj_clean(lv_scr_act()); +} + +bool SettingSetTime::Refresh() { + return running; +} + + +void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { + + if(object == btnHoursPlus && (event == LV_EVENT_PRESSED)) { + hoursValue++; + if (hoursValue > 23) + hoursValue = 0; + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnHoursMinus && (event == LV_EVENT_PRESSED)) { + hoursValue--; + if (hoursValue < 0) + hoursValue = 23; + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMinutesPlus && (event == LV_EVENT_PRESSED)) { + minutesValue++; + if (minutesValue > 59) + minutesValue = 0; + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMinutesMinus && (event == LV_EVENT_PRESSED)) { + minutesValue--; + if (minutesValue < 0) + minutesValue = 59; + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); + dateTimeController.SetTime(dateTimeController.Year(), + static_cast(dateTimeController.Month()), + dateTimeController.Day(), + static_cast(dateTimeController.DayOfWeek()), + static_cast(hoursValue), + static_cast(minutesValue), + 0, + nrf_rtc_counter_get(portNRF_RTC_REG)); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED); + } +} diff --git a/src/displayapp/screens/settings/SettingSetTime.h b/src/displayapp/screens/settings/SettingSetTime.h new file mode 100644 index 00000000..da92d6e4 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetTime.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include "components/datetime/DateTimeController.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingSetTime : public Screen{ + public: + SettingSetTime(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); + ~SettingSetTime() override; + + bool Refresh() override; + void HandleButtonPress(lv_obj_t *object, lv_event_t event); + + private: + + Controllers::DateTime& dateTimeController; + + int hoursValue; + int minutesValue; + lv_obj_t * lblHours; + lv_obj_t * lblMinutes; + lv_obj_t * btnHoursPlus; + lv_obj_t * btnHoursMinus; + lv_obj_t * btnMinutesPlus; + lv_obj_t * btnMinutesMinus; + lv_obj_t * btnSetTime; + + }; + } + } +} From c396925766ebfd05f3f345bf426a4fa59305ec74 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:12:26 +0200 Subject: [PATCH 02/13] Added new screen: SettingSetDate --- .../screens/settings/SettingSetDate.cpp | 272 ++++++++++++++++++ .../screens/settings/SettingSetDate.h | 45 +++ 2 files changed, 317 insertions(+) create mode 100644 src/displayapp/screens/settings/SettingSetDate.cpp create mode 100644 src/displayapp/screens/settings/SettingSetDate.h diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp new file mode 100644 index 00000000..5c1aec54 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -0,0 +1,272 @@ +#include "SettingSetDate.h" +#include +#include +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" + +#define POS_X_DAY -72 +#define POS_X_MONTH 0 +#define POS_X_YEAR 72 +#define POS_Y_PLUS -50 +#define POS_Y_TEXT -6 +#define POS_Y_MINUS 40 + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t * obj, lv_event_t event) { + SettingSetDate* screen = static_cast(obj->user_data); + screen->HandleButtonPress(obj, event); + } +} + +SettingSetDate::SettingSetDate( + Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : + Screen(app), + dateTimeController {dateTimeController} +{ + + 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, 30, 60); + lv_obj_set_width(container1, LV_HOR_RES - 50); + lv_obj_set_height(container1, LV_VER_RES - 60); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(title, "Set current date"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + + lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + 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::clock); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + dayValue = static_cast(dateTimeController.Day()); + lblDay = lv_label_create(lv_scr_act(), NULL); + //lv_obj_set_style_local_text_font(lblDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + + monthValue = static_cast(dateTimeController.Month()); + lblMonth = lv_label_create(lv_scr_act(), NULL); + //lv_obj_set_style_local_text_font(lblMonth, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + UpdateMonthLabel(); + + yearValue = static_cast(dateTimeController.Year()); + if (yearValue < 2021) + yearValue = 2021; + lblYear = lv_label_create(lv_scr_act(), NULL); + //lv_obj_set_style_local_text_font(lblYear, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblYear, "%d", yearValue); + lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + + btnDayPlus = lv_btn_create(lv_scr_act(), NULL); + btnDayPlus->user_data = this; + lv_obj_set_size(btnDayPlus, 50, 40); + lv_obj_align(btnDayPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_PLUS); + lv_obj_set_style_local_value_str(btnDayPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnDayPlus, event_handler); + + btnDayMinus = lv_btn_create(lv_scr_act(), NULL); + btnDayMinus->user_data = this; + lv_obj_set_size(btnDayMinus, 50, 40); + lv_obj_align(btnDayMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_MINUS); + lv_obj_set_style_local_value_str(btnDayMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnDayMinus, event_handler); + + btnMonthPlus = lv_btn_create(lv_scr_act(), NULL); + btnMonthPlus->user_data = this; + lv_obj_set_size(btnMonthPlus, 50, 40); + lv_obj_align(btnMonthPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_PLUS); + lv_obj_set_style_local_value_str(btnMonthPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnMonthPlus, event_handler); + + btnMonthMinus = lv_btn_create(lv_scr_act(), NULL); + btnMonthMinus->user_data = this; + lv_obj_set_size(btnMonthMinus, 50, 40); + lv_obj_align(btnMonthMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_MINUS); + lv_obj_set_style_local_value_str(btnMonthMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnMonthMinus, event_handler); + + btnYearPlus = lv_btn_create(lv_scr_act(), NULL); + btnYearPlus->user_data = this; + lv_obj_set_size(btnYearPlus, 50, 40); + lv_obj_align(btnYearPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_PLUS); + lv_obj_set_style_local_value_str(btnYearPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnYearPlus, event_handler); + + btnYearMinus = lv_btn_create(lv_scr_act(), NULL); + btnYearMinus->user_data = this; + lv_obj_set_size(btnYearMinus, 50, 40); + lv_obj_align(btnYearMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_MINUS); + lv_obj_set_style_local_value_str(btnYearMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnYearMinus, event_handler); + + btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime->user_data = this; + lv_obj_set_size(btnSetTime, 70, 40); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); + lv_obj_set_event_cb(btnSetTime, event_handler); +} + +SettingSetDate::~SettingSetDate() { + lv_obj_clean(lv_scr_act()); +} + +bool SettingSetDate::Refresh() { + return running; +} + + +void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { + + if(object == btnDayPlus && (event == LV_EVENT_PRESSED)) { + dayValue++; + if (dayValue > MaximumDayOfMonth()) + dayValue = 1; + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnDayMinus && (event == LV_EVENT_PRESSED)) { + dayValue--; + if (dayValue < 1) + dayValue = MaximumDayOfMonth(); + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMonthPlus && (event == LV_EVENT_PRESSED)) { + monthValue++; + if (monthValue > 12) + monthValue = 1; + UpdateMonthLabel(); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnMonthMinus && (event == LV_EVENT_PRESSED)) { + monthValue--; + if (monthValue < 1) + monthValue = 12; + UpdateMonthLabel(); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnYearPlus && (event == LV_EVENT_PRESSED)) { + yearValue++; + lv_label_set_text_fmt(lblYear, "%d", yearValue); + lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnYearMinus && (event == LV_EVENT_PRESSED)) { + yearValue--; + lv_label_set_text_fmt(lblYear, "%d", yearValue); + lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue); + dateTimeController.SetTime(static_cast(yearValue), + static_cast(monthValue), + static_cast(dayValue), + 0, + dateTimeController.Hours(), + dateTimeController.Minutes(), + dateTimeController.Seconds(), + nrf_rtc_counter_get(portNRF_RTC_REG)); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED); + } +} + +int SettingSetDate::MaximumDayOfMonth() const { + switch (monthValue) { + case 2: + if ((((yearValue % 4) == 0) && ((yearValue % 100) != 0)) || ((yearValue % 400) == 0)) + return 29; + return 28; + case 4: + case 6: + case 9: + case 11: + return 30; + default: + return 31; + } +} + +void SettingSetDate::CheckDay() { + int maxDay = MaximumDayOfMonth(); + if (dayValue > maxDay) { + dayValue = maxDay; + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + } +} + +void SettingSetDate::UpdateMonthLabel() { + switch (monthValue) { + case 1: + lv_label_set_text_static(lblMonth, "Jan"); + break; + case 2: + lv_label_set_text_static(lblMonth, "Feb"); + break; + case 3: + lv_label_set_text_static(lblMonth, "Mar"); + break; + case 4: + lv_label_set_text_static(lblMonth, "Apr"); + break; + case 5: + lv_label_set_text_static(lblMonth, "May"); + break; + case 6: + lv_label_set_text_static(lblMonth, "Jun"); + break; + case 7: + lv_label_set_text_static(lblMonth, "Jul"); + break; + case 8: + lv_label_set_text_static(lblMonth, "Aug"); + break; + case 9: + lv_label_set_text_static(lblMonth, "Sep"); + break; + case 10: + lv_label_set_text_static(lblMonth, "Oct"); + break; + case 11: + lv_label_set_text_static(lblMonth, "Nov"); + break; + case 12: + lv_label_set_text_static(lblMonth, "Dec"); + break; + default: + lv_label_set_text_static(lblMonth, "---"); + break; + } + lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); +} + diff --git a/src/displayapp/screens/settings/SettingSetDate.h b/src/displayapp/screens/settings/SettingSetDate.h new file mode 100644 index 00000000..0944e986 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetDate.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include "components/datetime/DateTimeController.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingSetDate : public Screen{ + public: + SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); + ~SettingSetDate() override; + + bool Refresh() override; + void HandleButtonPress(lv_obj_t *object, lv_event_t event); + + private: + + Controllers::DateTime& dateTimeController; + + int dayValue; + int monthValue; + int yearValue; + lv_obj_t * lblDay; + lv_obj_t * lblMonth; + lv_obj_t * lblYear; + lv_obj_t * btnDayPlus; + lv_obj_t * btnDayMinus; + lv_obj_t * btnMonthPlus; + lv_obj_t * btnMonthMinus; + lv_obj_t * btnYearPlus; + lv_obj_t * btnYearMinus; + lv_obj_t * btnSetTime; + + int MaximumDayOfMonth() const; + void CheckDay(); + void UpdateMonthLabel(); + }; + } + } +} From 07b3a507b4c685d54d21eb858f84aac23fa8ac1a Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:14:17 +0200 Subject: [PATCH 03/13] Include new screens in CMakeLists.txt --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aca86543..8c6f964e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -420,6 +420,8 @@ list(APPEND SOURCE_FILES displayapp/screens/settings/SettingWakeUp.cpp displayapp/screens/settings/SettingDisplay.cpp displayapp/screens/settings/SettingSteps.cpp + displayapp/screens/settings/SettingSetDate.cpp + displayapp/screens/settings/SettingSetTime.cpp ## Watch faces displayapp/icons/bg_clock.c From 6b3be0f5a1c2793c24d00fc1c4473ca411b3f2e4 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:15:50 +0200 Subject: [PATCH 04/13] Added new screens to the list of applications --- src/displayapp/Apps.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 684e3a46..c65a1d7b 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -30,7 +30,9 @@ namespace Pinetime { SettingTimeFormat, SettingDisplay, SettingWakeUp, - SettingSteps + SettingSteps, + SettingSetDate, + SettingSetTime }; } } From f3f5eb5739e1294e2953394a8744efd64ee58a28 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:19:38 +0200 Subject: [PATCH 05/13] Added new screens to DisplayApp.cpp --- src/displayapp/DisplayApp.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 04ebd2d3..5b78899b 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -42,6 +42,8 @@ #include "displayapp/screens/settings/SettingWakeUp.h" #include "displayapp/screens/settings/SettingDisplay.h" #include "displayapp/screens/settings/SettingSteps.h" +#include "displayapp/screens/settings/SettingSetDate.h" +#include "displayapp/screens/settings/SettingSetTime.h" using namespace Pinetime::Applications; using namespace Pinetime::Applications::Display; @@ -323,6 +325,14 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, settingsController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; + case Apps::SettingSetDate: + currentScreen = std::make_unique(this, dateTimeController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; + case Apps::SettingSetTime: + currentScreen = std::make_unique(this, dateTimeController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; case Apps::BatteryInfo: currentScreen = std::make_unique(this, batteryController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); From 5ae4192d8d729c36b1a6713165913c7c40a23703 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:22:45 +0200 Subject: [PATCH 06/13] Added new menu entries to Settings page --- src/displayapp/screens/settings/Settings.cpp | 17 +++++++++++++++-- src/displayapp/screens/settings/Settings.h | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index e63a3584..be8fb4bb 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -18,6 +18,9 @@ Settings::Settings(Pinetime::Applications::DisplayApp* app, Pinetime::Controller }, [this]() -> std::unique_ptr { return CreateScreen2(); + }, + [this]() -> std::unique_ptr { + return CreateScreen3(); }}, Screens::ScreenListModes::UpDown} { } @@ -46,7 +49,7 @@ std::unique_ptr Settings::CreateScreen1() { {Symbols::clock, "Watch face", Apps::SettingWatchFace}, }}; - return std::make_unique(0, 2, app, settingsController, applications); + return std::make_unique(0, 3, app, settingsController, applications); } std::unique_ptr Settings::CreateScreen2() { @@ -58,5 +61,15 @@ std::unique_ptr Settings::CreateScreen2() { {Symbols::list, "About", Apps::SysInfo}, }}; - return std::make_unique(1, 2, app, settingsController, applications); + return std::make_unique(1, 3, app, settingsController, applications); +} + +std::unique_ptr Settings::CreateScreen3() { + + std::array applications {{ + {Symbols::clock, "Set date", Apps::SettingSetDate}, + {Symbols::clock, "Set time", Apps::SettingSetTime}, + }}; + + return std::make_unique(2, 3, app, settingsController, applications); } diff --git a/src/displayapp/screens/settings/Settings.h b/src/displayapp/screens/settings/Settings.h index 711a6be6..12dd0514 100644 --- a/src/displayapp/screens/settings/Settings.h +++ b/src/displayapp/screens/settings/Settings.h @@ -21,10 +21,11 @@ namespace Pinetime { private: Controllers::Settings& settingsController; - ScreenList<2> screens; + ScreenList<3> screens; std::unique_ptr CreateScreen1(); std::unique_ptr CreateScreen2(); + std::unique_ptr CreateScreen3(); }; } } From f78c9bfcab798b08491b15fe02d65211b824cfc8 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 16:57:59 +0200 Subject: [PATCH 07/13] Code optimizations in SettingSetDate --- .../screens/settings/SettingSetDate.cpp | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index 5c1aec54..7fe0022e 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -26,19 +26,6 @@ SettingSetDate::SettingSetDate( Screen(app), dateTimeController {dateTimeController} { - - 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, 30, 60); - lv_obj_set_width(container1, LV_HOR_RES - 50); - lv_obj_set_height(container1, LV_VER_RES - 60); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); lv_label_set_text_static(title, "Set current date"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); @@ -116,8 +103,8 @@ SettingSetDate::SettingSetDate( btnSetTime = lv_btn_create(lv_scr_act(), NULL); btnSetTime->user_data = this; - lv_obj_set_size(btnSetTime, 70, 40); - lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_size(btnSetTime, 120, 48); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); lv_obj_set_event_cb(btnSetTime, event_handler); } @@ -133,7 +120,10 @@ bool SettingSetDate::Refresh() { void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if(object == btnDayPlus && (event == LV_EVENT_PRESSED)) { + if (event != LV_EVENT_CLICKED) + return; + + if (object == btnDayPlus) { dayValue++; if (dayValue > MaximumDayOfMonth()) dayValue = 1; @@ -141,8 +131,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnDayMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnDayMinus) { dayValue--; if (dayValue < 1) dayValue = MaximumDayOfMonth(); @@ -150,8 +139,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMonthPlus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMonthPlus) { monthValue++; if (monthValue > 12) monthValue = 1; @@ -159,8 +147,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnMonthMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMonthMinus) { monthValue--; if (monthValue < 1) monthValue = 12; @@ -168,24 +155,21 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnYearPlus && (event == LV_EVENT_PRESSED)) { + else if (object == btnYearPlus) { yearValue++; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnYearMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnYearMinus) { yearValue--; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + else if (object == btnSetTime) { NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue); dateTimeController.SetTime(static_cast(yearValue), static_cast(monthValue), From 06dfe1425173ffae81294cdce0fd271f1881f7ef Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:13:29 +0200 Subject: [PATCH 08/13] Code optimizations in SettingSetTime --- .../screens/settings/SettingSetTime.cpp | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 22d1c011..e8bc81ed 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -19,19 +19,6 @@ SettingSetTime::SettingSetTime( Screen(app), dateTimeController {dateTimeController} { - - 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, 30, 60); - lv_obj_set_width(container1, LV_HOR_RES - 50); - lv_obj_set_height(container1, LV_VER_RES - 60); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); lv_label_set_text_static(title, "Set current time"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); @@ -106,8 +93,8 @@ SettingSetTime::SettingSetTime( btnSetTime = lv_btn_create(lv_scr_act(), NULL); btnSetTime->user_data = this; - lv_obj_set_size(btnSetTime, 70, 40); - lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_size(btnSetTime, 120, 48); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); lv_obj_set_event_cb(btnSetTime, event_handler); } @@ -123,7 +110,10 @@ bool SettingSetTime::Refresh() { void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if(object == btnHoursPlus && (event == LV_EVENT_PRESSED)) { + if (event != LV_EVENT_CLICKED) + return; + + if (object == btnHoursPlus) { hoursValue++; if (hoursValue > 23) hoursValue = 0; @@ -131,8 +121,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnHoursMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnHoursMinus) { hoursValue--; if (hoursValue < 0) hoursValue = 23; @@ -140,8 +129,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMinutesPlus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMinutesPlus) { minutesValue++; if (minutesValue > 59) minutesValue = 0; @@ -149,8 +137,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMinutesMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMinutesMinus) { minutesValue--; if (minutesValue < 0) minutesValue = 59; @@ -158,8 +145,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + else if (object == btnSetTime) { NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); dateTimeController.SetTime(dateTimeController.Year(), static_cast(dateTimeController.Month()), From 899bee2cf57b658186806dfe0a834efb921b7fc5 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:32:48 +0200 Subject: [PATCH 09/13] Exposed Month and DayOfWeek texts in DateTimeController Added static methods to return the text of a given month or dayOfWeek. --- .../datetime/DateTimeController.cpp | 44 +++++++++++++++---- src/components/datetime/DateTimeController.h | 10 ++++- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 28a70abc..0682f8f3 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -75,31 +75,59 @@ void DateTime::UpdateTime(uint32_t systickCounter) { } const char* DateTime::MonthShortToString() { - return DateTime::MonthsString[(uint8_t) month]; + return DateTime::MonthsString[static_cast(month)]; } const char* DateTime::MonthShortToStringLow() { - return DateTime::MonthsStringLow[(uint8_t) month]; + return DateTime::MonthsStringLow[static_cast(month)]; } const char* DateTime::MonthsToStringLow() { - return DateTime::MonthsLow[(uint8_t) month]; + return DateTime::MonthsLow[static_cast(month)]; } const char* DateTime::DayOfWeekToString() { - return DateTime::DaysString[(uint8_t) dayOfWeek]; + return DateTime::DaysString[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToString() { - return DateTime::DaysStringShort[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShort[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekToStringLow() { - return DateTime::DaysStringLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringLow[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToStringLow() { - return DateTime::DaysStringShortLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; +} + +const char* DateTime::MonthShortToString(Months month) { + return DateTime::MonthsString[static_cast(month)]; +} + +const char* DateTime::MonthShortToStringLow(Months month) { + return DateTime::MonthsStringLow[static_cast(month)]; +} + +const char* DateTime::MonthsToStringLow(Months month) { + return DateTime::MonthsLow[static_cast(month)]; +} + +const char* DateTime::DayOfWeekToString(Days dayOfWeek) { + return DateTime::DaysString[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekShortToString(Days dayOfWeek) { + return DateTime::DaysStringShort[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekToStringLow(Days dayOfWeek) { + return DateTime::DaysStringLow[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekShortToStringLow(Days dayOfWeek) { + return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; } void DateTime::Register(Pinetime::System::SystemTask* systemTask) { @@ -119,4 +147,4 @@ char const* DateTime::MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", char const* DateTime::MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; char const* DateTime::MonthsLow[] = { - "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; \ No newline at end of file + "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index 265d6e9d..66ccaa94 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -66,6 +66,14 @@ namespace Pinetime { const char* DayOfWeekToStringLow(); const char* DayOfWeekShortToStringLow(); + static const char* MonthShortToString(Months month); + static const char* MonthShortToStringLow(Months month); + static const char* MonthsToStringLow(Months month); + static const char* DayOfWeekToString(Days dayOfWeek); + static const char* DayOfWeekShortToString(Days dayOfWeek); + static const char* DayOfWeekToStringLow(Days dayOfWeek); + static const char* DayOfWeekShortToStringLow(Days dayOfWeek); + std::chrono::time_point CurrentDateTime() const { return currentDateTime; } @@ -100,4 +108,4 @@ namespace Pinetime { static char const* MonthsLow[]; }; } -} \ No newline at end of file +} From 3e5ad49e3a27e0238dc8cd473f8743bf2e8d73b0 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:46:17 +0200 Subject: [PATCH 10/13] Code optimizations in SettingSetDate Using static method of DateTimeController for retrieving month texts instead of implementing it in SettingSetDate again. --- .../screens/settings/SettingSetDate.cpp | 43 +------------------ 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index 7fe0022e..fe71cd85 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -209,47 +209,8 @@ void SettingSetDate::CheckDay() { } void SettingSetDate::UpdateMonthLabel() { - switch (monthValue) { - case 1: - lv_label_set_text_static(lblMonth, "Jan"); - break; - case 2: - lv_label_set_text_static(lblMonth, "Feb"); - break; - case 3: - lv_label_set_text_static(lblMonth, "Mar"); - break; - case 4: - lv_label_set_text_static(lblMonth, "Apr"); - break; - case 5: - lv_label_set_text_static(lblMonth, "May"); - break; - case 6: - lv_label_set_text_static(lblMonth, "Jun"); - break; - case 7: - lv_label_set_text_static(lblMonth, "Jul"); - break; - case 8: - lv_label_set_text_static(lblMonth, "Aug"); - break; - case 9: - lv_label_set_text_static(lblMonth, "Sep"); - break; - case 10: - lv_label_set_text_static(lblMonth, "Oct"); - break; - case 11: - lv_label_set_text_static(lblMonth, "Nov"); - break; - case 12: - lv_label_set_text_static(lblMonth, "Dec"); - break; - default: - lv_label_set_text_static(lblMonth, "---"); - break; - } + lv_label_set_text_static(lblMonth, + Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); } From 0842a1333966863b0a043b45c629b1f7b1d6c511 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:49:35 +0200 Subject: [PATCH 11/13] Modified Settings menu as per suggestion Moved "Set date" and "Set time" to the second page of the Settings menu. --- src/displayapp/screens/settings/Settings.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index be8fb4bb..f4240ae1 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -56,9 +56,9 @@ std::unique_ptr Settings::CreateScreen2() { std::array applications {{ {Symbols::shoe, "Steps", Apps::SettingSteps}, + {Symbols::clock, "Set date", Apps::SettingSetDate}, + {Symbols::clock, "Set time", Apps::SettingSetTime}, {Symbols::batteryHalf, "Battery", Apps::BatteryInfo}, - {Symbols::check, "Firmware", Apps::FirmwareValidation}, - {Symbols::list, "About", Apps::SysInfo}, }}; return std::make_unique(1, 3, app, settingsController, applications); @@ -67,8 +67,8 @@ std::unique_ptr Settings::CreateScreen2() { std::unique_ptr Settings::CreateScreen3() { std::array applications {{ - {Symbols::clock, "Set date", Apps::SettingSetDate}, - {Symbols::clock, "Set time", Apps::SettingSetTime}, + {Symbols::check, "Firmware", Apps::FirmwareValidation}, + {Symbols::list, "About", Apps::SysInfo}, }}; return std::make_unique(2, 3, app, settingsController, applications); From da36d4a5a1322dd7699dbe445bb25962b0819f0a Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 20:17:47 +0200 Subject: [PATCH 12/13] Code optimizations in SettingSetTime The positions of the labels are controlled by #define's, just like in SettingSetDate. --- .../screens/settings/SettingSetTime.cpp | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index e8bc81ed..122a537a 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -5,6 +5,14 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" +#define POS_X_HOURS -72 +#define POS_X_MINUTES 0 +#define POS_X_SECONDS 72 +#define POS_Y_PLUS -50 +#define POS_Y_TEXT -6 +#define POS_Y_MINUS 40 +#define OFS_Y_COLON -2 + using namespace Pinetime::Applications::Screens; namespace { @@ -36,32 +44,32 @@ SettingSetTime::SettingSetTime( lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon1, ":"); lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, -36, -8); + lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_HOURS + POS_X_MINUTES) / 2, POS_Y_TEXT + OFS_Y_COLON); minutesValue = static_cast(dateTimeController.Minutes()); lblMinutes = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon2, ":"); lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, 36, -8); + lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON); lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblSeconds, "00"); lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, 72, -6); + lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT); btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); btnHoursPlus->user_data = this; @@ -118,7 +126,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue > 23) hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnHoursMinus) { @@ -126,7 +134,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesPlus) { @@ -134,7 +142,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesMinus) { @@ -142,7 +150,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnSetTime) { From ffa51612fc6884ccfeb4f23453acc451692c18b3 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 20:35:48 +0200 Subject: [PATCH 13/13] Code optimizations in SettingSetDate and SettingSetTime Instead of calling lv_obj_align after each button click, the labels have their auto_realign property set. --- src/displayapp/screens/settings/SettingSetDate.cpp | 14 +++++--------- src/displayapp/screens/settings/SettingSetTime.cpp | 6 ++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index fe71cd85..69766a4e 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -40,24 +40,26 @@ SettingSetDate::SettingSetDate( dayValue = static_cast(dateTimeController.Day()); lblDay = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + lv_obj_set_auto_realign(lblDay, true); monthValue = static_cast(dateTimeController.Month()); lblMonth = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblMonth, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); UpdateMonthLabel(); + lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); + lv_obj_set_auto_realign(lblMonth, true); yearValue = static_cast(dateTimeController.Year()); if (yearValue < 2021) yearValue = 2021; lblYear = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblYear, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + lv_obj_set_auto_realign(lblYear, true); btnDayPlus = lv_btn_create(lv_scr_act(), NULL); btnDayPlus->user_data = this; @@ -128,7 +130,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (dayValue > MaximumDayOfMonth()) dayValue = 1; lv_label_set_text_fmt(lblDay, "%d", dayValue); - lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnDayMinus) { @@ -136,7 +137,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (dayValue < 1) dayValue = MaximumDayOfMonth(); lv_label_set_text_fmt(lblDay, "%d", dayValue); - lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMonthPlus) { @@ -158,14 +158,12 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { else if (object == btnYearPlus) { yearValue++; lv_label_set_text_fmt(lblYear, "%d", yearValue); - lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } else if (object == btnYearMinus) { yearValue--; lv_label_set_text_fmt(lblYear, "%d", yearValue); - lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } @@ -211,7 +209,5 @@ void SettingSetDate::CheckDay() { void SettingSetDate::UpdateMonthLabel() { lv_label_set_text_static(lblMonth, Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); - lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); } diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 122a537a..eae11f5e 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -45,6 +45,7 @@ SettingSetTime::SettingSetTime( lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); + lv_obj_set_auto_realign(lblHours, true); lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); @@ -58,6 +59,7 @@ SettingSetTime::SettingSetTime( lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); + lv_obj_set_auto_realign(lblMinutes, true); lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); @@ -126,7 +128,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue > 23) hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnHoursMinus) { @@ -134,7 +135,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesPlus) { @@ -142,7 +142,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesMinus) { @@ -150,7 +149,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnSetTime) {