Skip to content

Commit 04da4cd

Browse files
committed
Add binary watchface
1 parent 9ad1630 commit 04da4cd

7 files changed

Lines changed: 441 additions & 1 deletion

File tree

‎src/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ list(APPEND SOURCE_FILES
432432
displayapp/screens/WatchFaceNumerals.cpp
433433
displayapp/screens/WatchFacePrideFlag.cpp
434434
displayapp/screens/WatchFaceLegend.cpp
435+
displayapp/screens/WatchFaceBinary.cpp
435436

436437
##
437438

‎src/displayapp/UserApps.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "displayapp/screens/WatchFaceNumerals.h"
1818
#include "displayapp/screens/WatchFacePrideFlag.h"
1919
#include "displayapp/screens/WatchFaceLegend.h"
20+
#include "displayapp/screens/WatchFaceBinary.h"
2021

2122
namespace Pinetime {
2223
namespace Applications {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace Pinetime {
5858
Numerals,
5959
PrideFlag,
6060
Legend,
61+
Binary,
6162
};
6263

6364
template <Apps>

‎src/displayapp/apps/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ else()
3131
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Numerals")
3232
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::PrideFlag")
3333
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Legend")
34+
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Binary")
3435
set(WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}" CACHE STRING "List of watch faces to build into the firmware")
3536
endif()
3637

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
#include "displayapp/screens/WatchFaceBinary.h"
2+
3+
#include <lvgl/lvgl.h>
4+
#include <cstdio>
5+
6+
#include "displayapp/screens/NotificationIcon.h"
7+
#include "displayapp/screens/Symbols.h"
8+
#include "displayapp/screens/WeatherSymbols.h"
9+
#include "components/battery/BatteryController.h"
10+
#include "components/ble/BleController.h"
11+
#include "components/ble/NotificationManager.h"
12+
#include "components/heartrate/HeartRateController.h"
13+
#include "components/motion/MotionController.h"
14+
#include "components/ble/SimpleWeatherService.h"
15+
#include "components/settings/Settings.h"
16+
17+
using namespace Pinetime::Applications::Screens;
18+
19+
lv_obj_t* WatchFaceBinary::CreateLed(
20+
lv_obj_t* parent,
21+
lv_coord_t x,
22+
lv_coord_t y,
23+
lv_coord_t size,
24+
lv_color_t color
25+
) {
26+
lv_obj_t* led = lv_led_create(parent, nullptr);
27+
28+
lv_obj_set_size(led, size, size);
29+
lv_obj_set_pos(led, x, y);
30+
31+
lv_obj_set_style_local_bg_color(
32+
led, LV_LED_PART_MAIN, LV_STATE_DEFAULT, color
33+
);
34+
35+
lv_obj_set_style_local_bg_opa(
36+
led, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER
37+
);
38+
39+
lv_obj_set_style_local_radius(
40+
led, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE
41+
);
42+
43+
lv_led_set_bright(led, LV_LED_BRIGHT_MAX);
44+
lv_led_off(led);
45+
46+
return led;
47+
}
48+
49+
void WatchFaceBinary::CreateTimeLeds() {
50+
lv_obj_t* screen = lv_scr_act();
51+
for (size_t col = 0; col < 6; col++) {
52+
size_t max_rows = MAX_ROWS[col];
53+
54+
for (size_t row = 0; row < max_rows; row++) {
55+
leds[col][row] = CreateLed(
56+
screen,
57+
COL_START_X - col * COL_SPACING,
58+
COL_START_Y - row * ROW_SPACING,
59+
LED_SIZE,
60+
LED_OFF_COLOR
61+
);
62+
}
63+
}
64+
}
65+
66+
WatchFaceBinary::WatchFaceBinary(
67+
Controllers::DateTime& dateTimeController,
68+
Controllers::Settings& settingsController,
69+
const Controllers::Battery& batteryController,
70+
const Controllers::Ble& bleController,
71+
const Controllers::AlarmController& alarmController,
72+
Controllers::NotificationManager& notificationManager,
73+
Controllers::HeartRateController& heartRateController,
74+
Controllers::MotionController& motionController,
75+
Controllers::SimpleWeatherService& weatherService
76+
) :
77+
currentDateTime {{}},
78+
dateTimeController {dateTimeController},
79+
settingsController {settingsController},
80+
notificationManager {notificationManager},
81+
heartRateController {heartRateController},
82+
motionController {motionController},
83+
weatherService {weatherService},
84+
statusIcons(batteryController, bleController, alarmController)
85+
{
86+
statusIcons.Create();
87+
88+
notificationIcon = lv_label_create(lv_scr_act(), nullptr);
89+
lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME);
90+
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
91+
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
92+
93+
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
94+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
95+
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
96+
lv_label_set_text(weatherIcon, "");
97+
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_MID, -20, 50);
98+
lv_obj_set_auto_realign(weatherIcon, true);
99+
100+
temperature = lv_label_create(lv_scr_act(), nullptr);
101+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
102+
lv_label_set_text(temperature, "");
103+
lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 50);
104+
105+
heartbeatIcon = lv_label_create(lv_scr_act(), nullptr);
106+
lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat);
107+
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x990000));
108+
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
109+
110+
heartbeatValue = lv_label_create(lv_scr_act(), nullptr);
111+
lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x990000));
112+
lv_label_set_text_static(heartbeatValue, "");
113+
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
114+
115+
stepValue = lv_label_create(lv_scr_act(), nullptr);
116+
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x990000));
117+
lv_label_set_text_static(stepValue, "0");
118+
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
119+
120+
stepIcon = lv_label_create(lv_scr_act(), nullptr);
121+
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x990000));
122+
lv_label_set_text_static(stepIcon, Symbols::shoe);
123+
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
124+
125+
labelTime = lv_label_create(lv_scr_act(), nullptr);
126+
lv_obj_align(labelTime, lv_scr_act(), LV_ALIGN_CENTER, 0, -84);
127+
lv_obj_set_style_local_text_color(labelTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
128+
129+
labelDate = lv_label_create(lv_scr_act(), nullptr);
130+
lv_obj_align(labelDate, lv_scr_act(), LV_ALIGN_CENTER, 0, 78);
131+
lv_obj_set_style_local_text_color(labelDate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
132+
133+
lv_style_init(&styleLine);
134+
lv_style_set_line_width(&styleLine, LV_STATE_DEFAULT, 2);
135+
lv_style_set_line_color(&styleLine, LV_STATE_DEFAULT, lv_color_hex(0x333333));
136+
137+
hmLine = lv_line_create(lv_scr_act(), NULL);
138+
lv_line_set_points(hmLine, hmLine_points, 2);
139+
lv_obj_add_style(hmLine, LV_LINE_PART_MAIN, &styleLine);
140+
141+
msLine = lv_line_create(lv_scr_act(), NULL);
142+
lv_line_set_points(msLine, msLine_points, 2);
143+
lv_obj_add_style(msLine, LV_LINE_PART_MAIN, &styleLine);
144+
145+
CreateTimeLeds();
146+
147+
pmLed = CreateLed(
148+
lv_scr_act(),
149+
COL_START_X - 5 * COL_SPACING,
150+
COL_START_Y - 3 * ROW_SPACING,
151+
LED_SIZE,
152+
PM_LED_OFF_COLOR
153+
);
154+
155+
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
156+
Refresh();
157+
}
158+
159+
WatchFaceBinary::~WatchFaceBinary() {
160+
if (taskRefresh != nullptr) {
161+
lv_task_del(taskRefresh);
162+
}
163+
164+
lv_obj_clean(lv_scr_act());
165+
}
166+
167+
void WatchFaceBinary::Refresh() {
168+
statusIcons.Update();
169+
170+
currentDateTime = std::chrono::time_point_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime());
171+
172+
if (currentDateTime.IsUpdated()) {
173+
uint8_t hour = dateTimeController.Hours();
174+
uint8_t minute = dateTimeController.Minutes();
175+
uint8_t second = dateTimeController.Seconds();
176+
177+
bool pm = hour >= 12;
178+
bool h12Clock = settingsController.GetClockType() == Controllers::Settings::ClockType::H12;
179+
180+
if (h12Clock) {
181+
if (hour == 0) {
182+
hour = 12;
183+
} else if (hour > 12) {
184+
hour = hour - 12;
185+
}
186+
}
187+
188+
h12Clock
189+
? lv_label_set_text_fmt(labelTime, "%02d:%02d:%02d %s", hour, minute, second, pm ? "PM" : "AM")
190+
: lv_label_set_text_fmt(labelTime, "%02d:%02d:%02d", hour, minute, second);
191+
192+
lv_obj_realign(labelTime);
193+
194+
lv_color_t pmLedColor;
195+
if (pm) {
196+
lv_led_on(pmLed);
197+
pmLedColor = PM_LED_ON_COLOR;
198+
} else {
199+
lv_led_off(pmLed);
200+
pmLedColor = PM_LED_OFF_COLOR;
201+
}
202+
203+
lv_obj_set_style_local_bg_color(
204+
pmLed,
205+
LV_LED_PART_MAIN,
206+
LV_STATE_DEFAULT,
207+
pmLedColor
208+
);
209+
210+
uint8_t timeDigits[6] = {
211+
second % 10,
212+
second / 10,
213+
minute % 10,
214+
minute / 10,
215+
hour % 10,
216+
hour / 10,
217+
};
218+
219+
lv_color_t ledColor;
220+
for (size_t col = 0; col < 6; col++) {
221+
size_t maxRows = MAX_ROWS[col];
222+
for (size_t row = 0; row < maxRows; row++) {
223+
if (((1 << row) & timeDigits[col]) > 0) {
224+
ledColor = LED_ON_COLOR;
225+
lv_led_on(leds[col][row]);
226+
} else {
227+
ledColor = LED_OFF_COLOR;
228+
lv_led_off(leds[col][row]);
229+
}
230+
231+
lv_obj_set_style_local_bg_color(
232+
leds[col][row],
233+
LV_LED_PART_MAIN,
234+
LV_STATE_DEFAULT,
235+
ledColor
236+
);
237+
}
238+
}
239+
240+
currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
241+
if (currentDate.IsUpdated()) {
242+
uint16_t year = dateTimeController.Year();
243+
uint8_t day = dateTimeController.Day();
244+
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
245+
lv_label_set_text_fmt(
246+
labelDate,
247+
"%s %d %s %d",
248+
dateTimeController.DayOfWeekShortToString(),
249+
day,
250+
dateTimeController.MonthShortToString(),
251+
year
252+
);
253+
} else {
254+
lv_label_set_text_fmt(
255+
labelDate,
256+
"%s %s %d %d",
257+
dateTimeController.DayOfWeekShortToString(),
258+
dateTimeController.MonthShortToString(),
259+
day,
260+
year
261+
);
262+
}
263+
lv_obj_realign(labelDate);
264+
}
265+
}
266+
267+
heartbeat = heartRateController.HeartRate();
268+
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
269+
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
270+
if (heartbeatRunning.Get()) {
271+
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
272+
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
273+
} else {
274+
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B));
275+
lv_label_set_text_static(heartbeatValue, "");
276+
}
277+
278+
lv_obj_realign(heartbeatIcon);
279+
lv_obj_realign(heartbeatValue);
280+
}
281+
282+
stepCount = motionController.NbSteps();
283+
if (stepCount.IsUpdated()) {
284+
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
285+
lv_obj_realign(stepValue);
286+
lv_obj_realign(stepIcon);
287+
}
288+
289+
currentWeather = weatherService.Current();
290+
if (currentWeather.IsUpdated()) {
291+
auto optCurrentWeather = currentWeather.Get();
292+
if (optCurrentWeather) {
293+
int16_t temp = optCurrentWeather->temperature.Celsius();
294+
char tempUnit = 'C';
295+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
296+
temp = optCurrentWeather->temperature.Fahrenheit();
297+
tempUnit = 'F';
298+
}
299+
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
300+
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId, weatherService.IsNight()));
301+
} else {
302+
lv_label_set_text_static(temperature, "");
303+
lv_label_set_text(weatherIcon, "");
304+
}
305+
lv_obj_realign(temperature);
306+
lv_obj_realign(weatherIcon);
307+
}
308+
}

0 commit comments

Comments
 (0)