@@ -20,12 +20,12 @@ WatchFaceNumerals::WatchFaceNumerals(Controllers::DateTime& dateTimeController,
2020 lfs_file f = {};
2121 if (filesystem.FileOpen (&f, " /fonts/rounded_large.bin" , LFS_O_RDONLY ) >= 0 ) {
2222 filesystem.FileClose (&f);
23- font_large = lv_font_load (" F:/fonts/rounded_large.bin" );
23+ fontLarge = lv_font_load (" F:/fonts/rounded_large.bin" );
2424 }
2525
2626 if (filesystem.FileOpen (&f, " /fonts/rounded_small.bin" , LFS_O_RDONLY ) >= 0 ) {
2727 filesystem.FileClose (&f);
28- font_small = lv_font_load (" F:/fonts/rounded_small.bin" );
28+ fontSmall = lv_font_load (" F:/fonts/rounded_small.bin" );
2929 }
3030
3131 notificationIcon = lv_obj_create (lv_scr_act (), nullptr );
@@ -36,37 +36,35 @@ WatchFaceNumerals::WatchFaceNumerals(Controllers::DateTime& dateTimeController,
3636 lv_obj_set_hidden (notificationIcon, true );
3737
3838 labelTimeHour = lv_label_create (lv_scr_act (), nullptr );
39- lv_obj_set_style_local_text_font (labelTimeHour, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , font_large );
39+ lv_obj_set_style_local_text_font (labelTimeHour, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , fontLarge );
4040 lv_obj_set_style_local_text_color (labelTimeHour, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , LV_COLOR_GRAY );
4141 lv_obj_align (labelTimeHour, lv_scr_act (), LV_ALIGN_IN_BOTTOM_RIGHT , -160 , -125 );
4242
4343 labelTimeMinute = lv_label_create (lv_scr_act (), nullptr );
44- lv_obj_set_style_local_text_font (labelTimeMinute, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , font_large );
44+ lv_obj_set_style_local_text_font (labelTimeMinute, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , fontLarge );
4545 lv_obj_set_style_local_text_color (labelTimeMinute, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , LV_COLOR_AQUA );
4646 lv_obj_align (labelTimeMinute, lv_scr_act (), LV_ALIGN_IN_BOTTOM_RIGHT , -160 , 0 );
4747
4848 labelTimeAMPM1 = lv_label_create (lv_scr_act (), nullptr );
4949 lv_label_set_text_static (labelTimeAMPM1, " " );
50- lv_obj_set_style_local_text_font (labelTimeAMPM1, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , font_small );
51- lv_obj_set_style_local_text_color (labelTimeAMPM1, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , lv_color_hex ( 0x999999 ) );
50+ lv_obj_set_style_local_text_font (labelTimeAMPM1, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , fontSmall );
51+ lv_obj_set_style_local_text_color (labelTimeAMPM1, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , ampmColor );
5252 lv_obj_align (labelTimeAMPM1, lv_scr_act (), LV_ALIGN_IN_BOTTOM_LEFT , 2 , -34 );
5353 // We use two labels for more flexibility with alignment
5454 labelTimeAMPM2 = lv_label_create (lv_scr_act (), nullptr );
5555 lv_label_set_text_static (labelTimeAMPM2, " M" );
56- lv_obj_set_style_local_text_font (labelTimeAMPM2, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , font_small );
57- lv_obj_set_style_local_text_color (labelTimeAMPM2, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , lv_color_hex ( 0x999999 ) );
56+ lv_obj_set_style_local_text_font (labelTimeAMPM2, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , fontSmall );
57+ lv_obj_set_style_local_text_color (labelTimeAMPM2, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , ampmColor );
5858 lv_obj_align (labelTimeAMPM2, lv_scr_act (), LV_ALIGN_IN_BOTTOM_LEFT , 0 , 0 );
5959
6060 dateDayOfWeek = lv_label_create (lv_scr_act (), nullptr );
6161 lv_obj_set_style_local_text_color (dateDayOfWeek, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , LV_COLOR_WHITE );
62- lv_label_set_text (dateDayOfWeek, " ---" );
63- lv_obj_set_style_local_text_font (dateDayOfWeek, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , font_small);
62+ lv_obj_set_style_local_text_font (dateDayOfWeek, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , fontSmall);
6463 lv_obj_align (dateDayOfWeek, lv_scr_act (), LV_ALIGN_IN_TOP_LEFT , 0 , 0 );
6564
6665 dateDay = lv_label_create (lv_scr_act (), nullptr );
6766 lv_obj_set_style_local_text_color (dateDay, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , LV_COLOR_WHITE );
68- lv_label_set_text (dateDay, " --" );
69- lv_obj_set_style_local_text_font (dateDay, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , font_small);
67+ lv_obj_set_style_local_text_font (dateDay, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , fontSmall);
7068 lv_obj_align (dateDay, lv_scr_act (), LV_ALIGN_IN_TOP_LEFT , 0 , 36 );
7169
7270 taskRefresh = lv_task_create (RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD , LV_TASK_PRIO_MID , this );
@@ -76,11 +74,11 @@ WatchFaceNumerals::WatchFaceNumerals(Controllers::DateTime& dateTimeController,
7674WatchFaceNumerals::~WatchFaceNumerals () {
7775 lv_task_del (taskRefresh);
7876
79- if (font_large != nullptr ) {
80- lv_font_free (font_large );
77+ if (fontLarge != nullptr ) {
78+ lv_font_free (fontLarge );
8179 }
82- if (font_small != nullptr ) {
83- lv_font_free (font_small );
80+ if (fontSmall != nullptr ) {
81+ lv_font_free (fontSmall );
8482 }
8583
8684 lv_obj_clean (lv_scr_act ());
@@ -92,48 +90,33 @@ void WatchFaceNumerals::Refresh() {
9290 lv_obj_set_hidden (notificationIcon, !notificationState.Get ());
9391 }
9492
95- currentDateTime = dateTimeController.CurrentDateTime ();
93+ currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>( dateTimeController.CurrentDateTime () );
9694 if (currentDateTime.IsUpdated ()) {
97- auto hour = dateTimeController.Hours ();
98- auto minute = dateTimeController.Minutes ();
99- auto year = dateTimeController.Year ();
100- auto month = dateTimeController.Month ();
101- auto dayOfWeek = dateTimeController.DayOfWeek ();
102- auto day = dateTimeController.Day ();
103-
104- if (displayedHour != hour || displayedMinute != minute) {
105- displayedHour = hour;
106- displayedMinute = minute;
107-
108- if (settingsController.GetClockType () == Controllers::Settings::ClockType::H12 ) {
109- char ampmChar[2 ] = " A" ;
110- if (hour == 0 ) {
111- hour = 12 ;
112- } else if (hour == 12 ) {
113- ampmChar[0 ] = ' P' ;
114- } else if (hour > 12 ) {
115- hour = hour - 12 ;
116- ampmChar[0 ] = ' P' ;
117- }
118- lv_label_set_text (labelTimeAMPM1, ampmChar);
119- lv_label_set_text_fmt (labelTimeHour, " %02d" , hour);
120- lv_label_set_text_fmt (labelTimeMinute, " %02d" , minute);
121- } else {
122- lv_obj_set_hidden (labelTimeAMPM2, true );
123- lv_label_set_text_fmt (labelTimeHour, " %02d" , hour);
124- lv_label_set_text_fmt (labelTimeMinute, " %02d" , minute);
95+ uint8_t hour = dateTimeController.Hours ();
96+ uint8_t minute = dateTimeController.Minutes ();
97+
98+ if (settingsController.GetClockType () == Controllers::Settings::ClockType::H12 ) {
99+ char ampmChar[2 ] = " A" ;
100+ if (hour == 0 ) {
101+ hour = 12 ;
102+ } else if (hour == 12 ) {
103+ ampmChar[0 ] = ' P' ;
104+ } else if (hour > 12 ) {
105+ hour = hour - 12 ;
106+ ampmChar[0 ] = ' P' ;
125107 }
108+ lv_label_set_text (labelTimeAMPM1, ampmChar);
109+ } else {
110+ lv_obj_set_hidden (labelTimeAMPM2, true );
126111 }
112+ lv_label_set_text_fmt (labelTimeHour, " %02d" , hour);
113+ lv_label_set_text_fmt (labelTimeMinute, " %02d" , minute);
127114
128- if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
115+ currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get ());
116+ if (currentDate.IsUpdated ()) {
129117 lv_label_set_text_static (dateDayOfWeek, dateTimeController.DayOfWeekShortToString ());
130- lv_label_set_text_fmt (dateDay, " %d" , day );
118+ lv_label_set_text_fmt (dateDay, " %d" , dateTimeController. Day () );
131119 lv_obj_realign (dateDay);
132-
133- currentYear = year;
134- currentMonth = month;
135- currentDayOfWeek = dayOfWeek;
136- currentDay = day;
137120 }
138121 }
139122}
0 commit comments