Skip to content

Commit c086520

Browse files
committed
Code cleaning in Clock, WatchFaceAnalog, WatchFaceDigital and PineTimeStyle, inspired by PR #232 by nscooling.
1 parent 514481e commit c086520

9 files changed

Lines changed: 60 additions & 156 deletions

File tree

src/components/datetime/DateTimeController.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
5555
auto time = date::make_time(currentDateTime - dp);
5656
auto yearMonthDay = date::year_month_day(dp);
5757

58-
year = (int) yearMonthDay.year();
59-
month = static_cast<Months>((unsigned) yearMonthDay.month());
60-
day = (unsigned) yearMonthDay.day();
58+
year = static_cast<int>(yearMonthDay.year());
59+
month = static_cast<Months>(static_cast<unsigned>(yearMonthDay.month()));
60+
day = static_cast<unsigned>(yearMonthDay.day());
6161
dayOfWeek = static_cast<Days>(date::weekday(yearMonthDay).iso_encoding());
6262

6363
hour = time.hours().count();
@@ -75,31 +75,31 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
7575
}
7676

7777
const char* DateTime::MonthShortToString() {
78-
return DateTime::MonthsString[(uint8_t) month];
78+
return DateTime::MonthsString[static_cast<uint8_t>(month)];
7979
}
8080

8181
const char* DateTime::MonthShortToStringLow() {
82-
return DateTime::MonthsStringLow[(uint8_t) month];
82+
return DateTime::MonthsStringLow[static_cast<uint8_t>(month)];
8383
}
8484

8585
const char* DateTime::MonthsToStringLow() {
86-
return DateTime::MonthsLow[(uint8_t) month];
86+
return DateTime::MonthsLow[static_cast<uint8_t>(month)];
8787
}
8888

8989
const char* DateTime::DayOfWeekToString() {
90-
return DateTime::DaysString[(uint8_t) dayOfWeek];
90+
return DateTime::DaysString[static_cast<uint8_t>(dayOfWeek)];
9191
}
9292

9393
const char* DateTime::DayOfWeekShortToString() {
94-
return DateTime::DaysStringShort[(uint8_t) dayOfWeek];
94+
return DateTime::DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
9595
}
9696

9797
const char* DateTime::DayOfWeekToStringLow() {
98-
return DateTime::DaysStringLow[(uint8_t) dayOfWeek];
98+
return DateTime::DaysStringLow[static_cast<uint8_t>(dayOfWeek)];
9999
}
100100

101101
const char* DateTime::DayOfWeekShortToStringLow() {
102-
return DateTime::DaysStringShortLow[(uint8_t) dayOfWeek];
102+
return DateTime::DaysStringShortLow[static_cast<uint8_t>(dayOfWeek)];
103103
}
104104

105105
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {

src/displayapp/screens/Clock.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
#include <date/date.h>
44
#include <lvgl/lvgl.h>
5-
#include <cstdio>
6-
#include "BatteryIcon.h"
7-
#include "BleIcon.h"
8-
#include "NotificationIcon.h"
9-
#include "Symbols.h"
105
#include "components/battery/BatteryController.h"
116
#include "components/motion/MotionController.h"
127
#include "components/ble/BleController.h"
@@ -88,17 +83,4 @@ std::unique_ptr<Screen> Clock::PineTimeStyleScreen() {
8883
notificatioManager,
8984
settingsController,
9085
motionController);
91-
}
92-
93-
/*
94-
// Examples for more watch faces
95-
std::unique_ptr<Screen> Clock::WatchFaceMinimalScreen() {
96-
return std::make_unique<Screens::WatchFaceMinimal>(app, dateTimeController, batteryController, bleController, notificatioManager,
97-
settingsController);
98-
}
99-
100-
std::unique_ptr<Screen> Clock::WatchFaceCustomScreen() {
101-
return std::make_unique<Screens::WatchFaceCustom>(app, dateTimeController, batteryController, bleController, notificatioManager,
102-
settingsController);
103-
}
104-
*/
86+
}

src/displayapp/screens/Clock.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include "components/datetime/DateTimeController.h"
1010

1111
namespace Pinetime {
12-
namespace Drivers {
13-
class BMA421;
14-
}
1512
namespace Controllers {
1613
class Settings;
1714
class Battery;
@@ -51,10 +48,6 @@ namespace Pinetime {
5148
std::unique_ptr<Screen> WatchFaceDigitalScreen();
5249
std::unique_ptr<Screen> WatchFaceAnalogScreen();
5350
std::unique_ptr<Screen> PineTimeStyleScreen();
54-
55-
// Examples for more watch faces
56-
// std::unique_ptr<Screen> WatchFaceMinimalScreen();
57-
// std::unique_ptr<Screen> WatchFaceCustomScreen();
5851
};
5952
}
6053
}

src/displayapp/screens/PineTimeStyle.cpp

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
5151
notificatioManager {notificatioManager},
5252
settingsController {settingsController},
5353
motionController {motionController} {
54-
5554
/* This sets the watchface number to return to after leaving the menu */
5655
settingsController.SetClockFace(2);
5756

@@ -62,15 +61,13 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
6261
displayedChar[4] = 0;
6362

6463
/* Create a 200px wide background rectangle */
65-
6664
timebar = lv_obj_create(lv_scr_act(), nullptr);
6765
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
6866
lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
6967
lv_obj_set_size(timebar, 200, 240);
7068
lv_obj_align(timebar, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 0);
7169

7270
/* Display the time */
73-
7471
timeDD1 = lv_label_create(lv_scr_act(), nullptr);
7572
lv_obj_set_style_local_text_font(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light);
7673
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080));
@@ -90,15 +87,13 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
9087
lv_obj_align(timeAMPM, timebar, LV_ALIGN_IN_BOTTOM_LEFT, 2, -20);
9188

9289
/* Create a 40px wide bar down the right side of the screen */
93-
9490
sidebar = lv_obj_create(lv_scr_act(), nullptr);
9591
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080));
9692
lv_obj_set_style_local_radius(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
9793
lv_obj_set_size(sidebar, 40, 240);
9894
lv_obj_align(sidebar, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
9995

10096
/* Display icons */
101-
10297
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
10398
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
10499
lv_label_set_text(batteryIcon, Symbols::batteryFull);
@@ -117,7 +112,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
117112
lv_obj_align(notificationIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 40);
118113

119114
/* Calendar icon */
120-
121115
calendarOuter = lv_obj_create(lv_scr_act(), nullptr);
122116
lv_obj_set_style_local_bg_color(calendarOuter, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
123117
lv_obj_set_style_local_radius(calendarOuter, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
@@ -155,7 +149,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
155149
lv_obj_align(calendarCrossBar2, calendarBar2, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
156150

157151
/* Display date */
158-
159152
dateDayOfWeek = lv_label_create(lv_scr_act(), nullptr);
160153
lv_obj_set_style_local_text_color(dateDayOfWeek, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
161154
lv_label_set_text(dateDayOfWeek, "THU");
@@ -223,36 +216,27 @@ bool PineTimeStyle::Refresh() {
223216

224217
bleState = bleController.IsConnected();
225218
if (bleState.IsUpdated()) {
226-
if (bleState.Get() == true) {
227-
lv_label_set_text(bleIcon, BleIcon::GetIcon(true));
228-
lv_obj_realign(bleIcon);
229-
} else {
230-
lv_label_set_text(bleIcon, BleIcon::GetIcon(false));
231-
}
219+
lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get()));
220+
lv_obj_realign(bleIcon);
232221
}
233222

234223
notificationState = notificatioManager.AreNewNotificationsAvailable();
235224
if (notificationState.IsUpdated()) {
236-
if (notificationState.Get() == true) {
237-
lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true));
238-
lv_obj_realign(notificationIcon);
239-
} else {
240-
lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false));
241-
}
225+
lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
226+
lv_obj_realign(notificationIcon);
242227
}
243228

244229
currentDateTime = dateTimeController.CurrentDateTime();
245-
246230
if (currentDateTime.IsUpdated()) {
247231
auto newDateTime = currentDateTime.Get();
248232

249233
auto dp = date::floor<date::days>(newDateTime);
250234
auto time = date::make_time(newDateTime - dp);
251235
auto yearMonthDay = date::year_month_day(dp);
252236

253-
auto year = (int) yearMonthDay.year();
254-
auto month = static_cast<Pinetime::Controllers::DateTime::Months>((unsigned) yearMonthDay.month());
255-
auto day = (unsigned) yearMonthDay.day();
237+
auto year = static_cast<int>(yearMonthDay.year());
238+
auto month = static_cast<Pinetime::Controllers::DateTime::Months>(static_cast<unsigned>(yearMonthDay.month()));
239+
auto day = static_cast<unsigned>(yearMonthDay.day());
256240
auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding());
257241

258242
int hour = time.hours().count();
@@ -263,9 +247,8 @@ bool PineTimeStyle::Refresh() {
263247

264248
char hoursChar[3];
265249
char ampmChar[5];
266-
267250
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
268-
sprintf(hoursChar, "%02d", hour);
251+
sprintf(hoursChar, "%02d", hour);
269252
} else {
270253
if (hour == 0 && hour != 12) {
271254
hour = 12;
@@ -282,41 +265,26 @@ bool PineTimeStyle::Refresh() {
282265
sprintf(hoursChar, "%02d", hour);
283266
}
284267

285-
if (hoursChar[0] != displayedChar[0] || hoursChar[1] != displayedChar[1] || minutesChar[0] != displayedChar[2] ||
268+
if (hoursChar[0] != displayedChar[0] or hoursChar[1] != displayedChar[1] or minutesChar[0] != displayedChar[2] or
286269
minutesChar[1] != displayedChar[3]) {
287270
displayedChar[0] = hoursChar[0];
288271
displayedChar[1] = hoursChar[1];
289272
displayedChar[2] = minutesChar[0];
290273
displayedChar[3] = minutesChar[1];
291274

292-
char hourStr[3];
293-
char minStr[3];
294-
295275
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
296276
lv_label_set_text(timeAMPM, ampmChar);
297277
}
298278

299-
/* Display the time as 2 pairs of digits */
300-
sprintf(hourStr, "%c%c", hoursChar[0], hoursChar[1]);
301-
lv_label_set_text(timeDD1, hourStr);
302-
303-
sprintf(minStr, "%c%c", minutesChar[0], minutesChar[1]);
304-
lv_label_set_text(timeDD2, minStr);
279+
lv_label_set_text_fmt(timeDD1, "%s", hoursChar);
280+
lv_label_set_text_fmt(timeDD2, "%s", minutesChar);
305281
}
306282

307283
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
308-
char dayOfWeekStr[4];
309-
char dayStr[3];
310-
char monthStr[4];
311-
312-
sprintf(dayOfWeekStr, "%s", dateTimeController.DayOfWeekShortToString());
313-
sprintf(dayStr, "%d", day);
314-
sprintf(monthStr, "%s", dateTimeController.MonthShortToString());
315-
316-
lv_label_set_text(dateDayOfWeek, dayOfWeekStr);
317-
lv_label_set_text(dateDay, dayStr);
284+
lv_label_set_text_fmt(dateDayOfWeek, "%s", dateTimeController.DayOfWeekShortToString());
285+
lv_label_set_text_fmt(dateDay, "%d", day);
318286
lv_obj_realign(dateDay);
319-
lv_label_set_text(dateMonth, monthStr);
287+
lv_label_set_text_fmt(dateMonth, "%s", dateTimeController.MonthShortToString());
320288

321289
currentYear = year;
322290
currentMonth = month;

src/displayapp/screens/PineTimeStyle.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace Pinetime {
3232

3333
bool Refresh() override;
3434

35-
void OnObjectEvent(lv_obj_t* pObj, lv_event_t i);
36-
3735
private:
3836
char displayedChar[5];
3937

@@ -67,9 +65,6 @@ namespace Pinetime {
6765
lv_obj_t* calendarBar2;
6866
lv_obj_t* calendarCrossBar1;
6967
lv_obj_t* calendarCrossBar2;
70-
lv_obj_t* heartbeatIcon;
71-
lv_obj_t* heartbeatValue;
72-
lv_obj_t* heartbeatBpm;
7368
lv_obj_t* notificationIcon;
7469
lv_obj_t* stepGauge;
7570
lv_color_t needle_colors[1];

0 commit comments

Comments
 (0)