Skip to content

Commit 0b9d14a

Browse files
committed
squash
1 parent 6c119eb commit 0b9d14a

8 files changed

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

‎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)