Skip to content

Commit ea08a6a

Browse files
committed
squash
1 parent 6c119eb commit ea08a6a

8 files changed

Lines changed: 239 additions & 0 deletions

File tree

‎src/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ list(APPEND SOURCE_FILES
429429
displayapp/screens/WatchFaceTerminal.cpp
430430
displayapp/screens/WatchFacePineTimeStyle.cpp
431431
displayapp/screens/WatchFaceCasioStyleG7710.cpp
432+
displayapp/screens/WatchFaceNumerals.cpp
432433
displayapp/screens/WatchFacePrideFlag.cpp
433434

434435
##

‎src/displayapp/UserApps.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "displayapp/screens/WatchFaceInfineat.h"
1515
#include "displayapp/screens/WatchFacePineTimeStyle.h"
1616
#include "displayapp/screens/WatchFaceTerminal.h"
17+
#include "displayapp/screens/WatchFaceNumerals.h"
1718
#include "displayapp/screens/WatchFacePrideFlag.h"
1819

1920
namespace Pinetime {

‎src/displayapp/apps/Apps.h.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace Pinetime {
5555
Terminal,
5656
Infineat,
5757
CasioStyleG7710,
58+
Numerals,
5859
PrideFlag,
5960
};
6061

‎src/displayapp/apps/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ else()
2828
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Terminal")
2929
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Infineat")
3030
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::CasioStyleG7710")
31+
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Numerals")
3132
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::PrideFlag")
3233
set(WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}" CACHE STRING "List of watch faces to build into the firmware")
3334
endif()
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#include "displayapp/screens/WatchFaceNumerals.h"
2+
3+
#include <lvgl/lvgl.h>
4+
#include "components/ble/NotificationManager.h"
5+
#include "components/settings/Settings.h"
6+
7+
using namespace Pinetime::Applications::Screens;
8+
9+
WatchFaceNumerals::WatchFaceNumerals(Controllers::DateTime& dateTimeController,
10+
Controllers::NotificationManager& notificationManager,
11+
Controllers::Settings& settingsController,
12+
Controllers::FS& filesystem)
13+
: currentDateTime {{}},
14+
dateTimeController {dateTimeController},
15+
notificationManager {notificationManager},
16+
settingsController {settingsController} {
17+
18+
lfs_file f = {};
19+
if (filesystem.FileOpen(&f, "/fonts/rounded_large.bin", LFS_O_RDONLY) >= 0) {
20+
filesystem.FileClose(&f);
21+
fontLarge = lv_font_load("F:/fonts/rounded_large.bin");
22+
}
23+
24+
if (filesystem.FileOpen(&f, "/fonts/rounded_small.bin", LFS_O_RDONLY) >= 0) {
25+
filesystem.FileClose(&f);
26+
fontSmall = lv_font_load("F:/fonts/rounded_small.bin");
27+
}
28+
29+
notificationIcon = lv_obj_create(lv_scr_act(), nullptr);
30+
lv_obj_set_style_local_bg_color(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA);
31+
lv_obj_set_style_local_radius(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
32+
lv_obj_set_size(notificationIcon, 16, 16);
33+
lv_obj_align(notificationIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 4, -76);
34+
lv_obj_set_hidden(notificationIcon, true);
35+
36+
labelTimeHour = lv_label_create(lv_scr_act(), nullptr);
37+
lv_obj_set_style_local_text_font(labelTimeHour, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontLarge);
38+
lv_obj_set_style_local_text_color(labelTimeHour, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
39+
lv_obj_align(labelTimeHour, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -160, -125);
40+
41+
labelTimeMinute = lv_label_create(lv_scr_act(), nullptr);
42+
lv_obj_set_style_local_text_font(labelTimeMinute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontLarge);
43+
lv_obj_set_style_local_text_color(labelTimeMinute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA);
44+
lv_obj_align(labelTimeMinute, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -160, 0);
45+
46+
labelTimeAMPM1 = lv_label_create(lv_scr_act(), nullptr);
47+
lv_label_set_text_static(labelTimeAMPM1, "");
48+
lv_obj_set_style_local_text_font(labelTimeAMPM1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall);
49+
lv_obj_set_style_local_text_color(labelTimeAMPM1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, ampmColor);
50+
lv_obj_align(labelTimeAMPM1, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 2, -34);
51+
// We use two labels for more flexibility with alignment
52+
labelTimeAMPM2 = lv_label_create(lv_scr_act(), nullptr);
53+
lv_label_set_text_static(labelTimeAMPM2, "M");
54+
lv_obj_set_style_local_text_font(labelTimeAMPM2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall);
55+
lv_obj_set_style_local_text_color(labelTimeAMPM2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, ampmColor);
56+
lv_obj_align(labelTimeAMPM2, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
57+
58+
dateDayOfWeek = lv_label_create(lv_scr_act(), nullptr);
59+
lv_obj_set_style_local_text_color(dateDayOfWeek, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
60+
lv_obj_set_style_local_text_font(dateDayOfWeek, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall);
61+
lv_obj_align(dateDayOfWeek, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
62+
63+
dateDay = lv_label_create(lv_scr_act(), nullptr);
64+
lv_obj_set_style_local_text_color(dateDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
65+
lv_obj_set_style_local_text_font(dateDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall);
66+
lv_obj_align(dateDay, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 36);
67+
68+
Refresh();
69+
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
70+
}
71+
72+
WatchFaceNumerals::~WatchFaceNumerals() {
73+
lv_task_del(taskRefresh);
74+
75+
if (fontLarge != nullptr) {
76+
lv_font_free(fontLarge);
77+
}
78+
if (fontSmall != nullptr) {
79+
lv_font_free(fontSmall);
80+
}
81+
82+
lv_obj_clean(lv_scr_act());
83+
}
84+
85+
void WatchFaceNumerals::Refresh() {
86+
notificationState = notificationManager.AreNewNotificationsAvailable();
87+
if (notificationState.IsUpdated()) {
88+
lv_obj_set_hidden(notificationIcon, !notificationState.Get());
89+
}
90+
91+
currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
92+
if (currentDateTime.IsUpdated()) {
93+
uint8_t hour = dateTimeController.Hours();
94+
uint8_t minute = dateTimeController.Minutes();
95+
96+
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
97+
char ampmChar[2] = "A";
98+
if (hour == 0) {
99+
hour = 12;
100+
} else if (hour == 12) {
101+
ampmChar[0] = 'P';
102+
} else if (hour > 12) {
103+
hour = hour - 12;
104+
ampmChar[0] = 'P';
105+
}
106+
lv_label_set_text(labelTimeAMPM1, ampmChar);
107+
} else {
108+
lv_obj_set_hidden(labelTimeAMPM2, true);
109+
}
110+
lv_label_set_text_fmt(labelTimeHour, "%02d", hour);
111+
lv_label_set_text_fmt(labelTimeMinute, "%02d", minute);
112+
113+
currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
114+
if (currentDate.IsUpdated()) {
115+
lv_label_set_text_static(dateDayOfWeek, dateTimeController.DayOfWeekShortToString());
116+
lv_label_set_text_fmt(dateDay, "%d", dateTimeController.Day());
117+
lv_obj_realign(dateDay);
118+
}
119+
}
120+
}
121+
122+
bool WatchFaceNumerals::IsAvailable(Pinetime::Controllers::FS& filesystem) {
123+
lfs_file file = {};
124+
125+
if (filesystem.FileOpen(&file, "/fonts/rounded_small.bin", LFS_O_RDONLY) < 0) {
126+
return false;
127+
}
128+
129+
filesystem.FileClose(&file);
130+
if (filesystem.FileOpen(&file, "/fonts/rounded_large.bin", LFS_O_RDONLY) < 0) {
131+
return false;
132+
}
133+
134+
filesystem.FileClose(&file);
135+
return true;
136+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
3+
#include <lvgl/lvgl.h>
4+
#include <chrono>
5+
#include <displayapp/Controllers.h>
6+
#include "displayapp/screens/Screen.h"
7+
#include "components/datetime/DateTimeController.h"
8+
#include "utility/DirtyValue.h"
9+
#include "displayapp/apps/Apps.h"
10+
11+
namespace Pinetime {
12+
namespace Controllers {
13+
class Settings;
14+
class NotificationManager;
15+
}
16+
17+
namespace Applications {
18+
namespace Screens {
19+
20+
class WatchFaceNumerals : public Screen {
21+
public:
22+
WatchFaceNumerals(Controllers::DateTime& dateTimeController,
23+
Controllers::NotificationManager& notificationManager,
24+
Controllers::Settings& settingsController,
25+
Controllers::FS& filesystem);
26+
~WatchFaceNumerals() override;
27+
28+
void Refresh() override;
29+
30+
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
31+
32+
private:
33+
static constexpr lv_color_t ampmColor = LV_COLOR_MAKE(0x99, 0x99, 0x99);
34+
35+
Utility::DirtyValue<bool> notificationState;
36+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime;
37+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
38+
39+
lv_obj_t* labelTimeHour;
40+
lv_obj_t* labelTimeMinute;
41+
lv_obj_t* labelTimeAMPM1;
42+
lv_obj_t* labelTimeAMPM2;
43+
lv_obj_t* notificationIcon;
44+
lv_obj_t* dateDay;
45+
lv_obj_t* dateDayOfWeek;
46+
47+
Controllers::DateTime& dateTimeController;
48+
Controllers::NotificationManager& notificationManager;
49+
Controllers::Settings& settingsController;
50+
51+
lv_font_t* fontLarge = nullptr;
52+
lv_font_t* fontSmall = nullptr;
53+
54+
lv_task_t* taskRefresh;
55+
};
56+
}
57+
58+
template <>
59+
struct WatchFaceTraits<WatchFace::Numerals> {
60+
static constexpr WatchFace watchFace = WatchFace::Numerals;
61+
static constexpr const char* name = "Numerals";
62+
63+
static Screens::Screen* Create(AppControllers& controllers) {
64+
return new Screens::WatchFaceNumerals(controllers.dateTimeController,
65+
controllers.notificationManager,
66+
controllers.settingsController,
67+
controllers.filesystem);
68+
};
69+
70+
static bool IsAvailable(Pinetime::Controllers::FS& filesystem) {
71+
return Screens::WatchFaceNumerals::IsAvailable(filesystem);
72+
}
73+
};
74+
}
75+
}

‎src/resources/fonts.json‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,29 @@
5858
"size": 115,
5959
"format": "bin",
6060
"target_path": "/fonts/"
61+
},
62+
"rounded_large": {
63+
"sources": [
64+
{
65+
"file": "fonts/BloggerSans-Bold.ttf",
66+
"symbols": "0123456789"
67+
}
68+
],
69+
"bpp": 1,
70+
"size": 150,
71+
"format": "bin",
72+
"target_path": "/fonts/"
73+
},
74+
"rounded_small": {
75+
"sources": [
76+
{
77+
"file": "fonts/BloggerSans-Bold.ttf",
78+
"symbols": "0123456789APMONTUEWDHRFIS"
79+
}
80+
],
81+
"bpp": 1,
82+
"size": 30,
83+
"format": "bin",
84+
"target_path": "/fonts/"
6185
}
6286
}
164 KB
Binary file not shown.

0 commit comments

Comments
 (0)