Skip to content

Commit fbbe598

Browse files
committed
Replace watchface
1 parent 2a7e5ed commit fbbe598

6 files changed

Lines changed: 102 additions & 347 deletions

File tree

src/displayapp/screens/Pawn.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
#include <stdio.h>
33
#include <charconv>
44

5-
extern "C" {
6-
#include "pawn/amxpool.h"
7-
}
8-
9-
#include "program.h"
10-
115
using namespace Pinetime::Applications::Screens;
126

137
enum {
@@ -288,7 +282,7 @@ static cell AMX_NATIVE_CALL F_sprintf(AMX* amx, const cell* params) {
288282
return bufc - buf;
289283
}
290284

291-
static cell AMX_NATIVE_CALL F_get_datetime(AMX* amx, const cell* params) {
285+
cell AMX_NATIVE_CALL F_get_datetime(AMX* amx, const cell* params) {
292286
ASSERT_PARAMS(1);
293287

294288
Pawn* pawn = PAWN_INST;
@@ -371,18 +365,16 @@ static int AMXAPI prun_Overlay(AMX* amx, int index) {
371365
if ((amx->code = (unsigned char*) amx_poolalloc(&PAWN_INST->amx_pool, tbl->size, index)) == NULL)
372366
return AMX_ERR_OVERLAY;
373367

374-
memcpy(amx->code, program + hdr->cod + tbl->offset, tbl->size);
368+
memcpy(amx->code, PAWN_INST->file + hdr->cod + tbl->offset, tbl->size);
375369
}
376370

377371
return AMX_ERR_NONE;
378372
}
379373

380374
int Pawn::LoadProgram() {
381-
(void) program_len;
382-
383375
int result;
384376
AMX_HEADER hdr;
385-
memcpy(&hdr, program, sizeof(hdr));
377+
memcpy(&hdr, file, sizeof(hdr));
386378

387379
if (hdr.magic != AMX_MAGIC)
388380
return AMX_ERR_FORMAT;
@@ -394,14 +386,14 @@ int Pawn::LoadProgram() {
394386
if (header == NULL)
395387
return AMX_ERR_MEMORY;
396388

397-
memcpy(header, program, hdr.cod);
389+
memcpy(header, file, hdr.cod);
398390

399391
if (hdr.flags & AMX_FLAG_OVERLAY) {
400392
datablock = malloc(hdr.stp - hdr.dat); // This block contains data, heap and stack
401393
if (datablock == NULL)
402394
return AMX_ERR_MEMORY;
403395

404-
memcpy(datablock, program + hdr.dat, hdr.hea - hdr.dat);
396+
memcpy(datablock, file + hdr.dat, hdr.hea - hdr.dat);
405397

406398
constexpr int overlaypool_overhead = 8;
407399
overlaypool = malloc(max_overlay_size + overlaypool_overhead);
@@ -427,7 +419,7 @@ int Pawn::LoadProgram() {
427419
if (datablock == NULL)
428420
return AMX_ERR_MEMORY;
429421

430-
memcpy(datablock, program, hdr.size);
422+
memcpy(datablock, file, hdr.size);
431423

432424
result = amx_Init(&amx, datablock);
433425
if (result != AMX_ERR_NONE) {
@@ -463,7 +455,12 @@ extern "C" const AMX_NATIVE pawn_natives[] = {
463455
F_raise_error,
464456
};
465457

466-
Pawn::Pawn(AppControllers& controllers) : controllers(controllers) {
458+
#include "program.h"
459+
Pawn::Pawn(AppControllers& controllers) : Pawn(program, controllers) {
460+
(void) program_len;
461+
}
462+
463+
Pawn::Pawn(const uint8_t *file, AppControllers& controllers) : controllers(controllers), file(file) {
467464
int result = LoadProgram();
468465
if (result != AMX_ERR_NONE) {
469466
ShowError(result);

src/displayapp/screens/Pawn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Pinetime {
1818
class Pawn : public Screen {
1919
public:
2020
Pawn(AppControllers& controllers);
21+
Pawn(const uint8_t *file, AppControllers& controllers);
2122
~Pawn() override;
2223

2324
void Refresh() override;
@@ -35,6 +36,7 @@ namespace Pinetime {
3536
Widgets::StatusIcons* statusIcons = nullptr;
3637

3738
amxPool amx_pool;
39+
const uint8_t *file;
3840

3941
private:
4042
AMX amx;
@@ -56,7 +58,6 @@ namespace Pinetime {
5658
static constexpr const char* icon = "P";
5759

5860
static Screens::Screen* Create(AppControllers& controllers) {
59-
// sizeof(Pawn)
6061
return new Screens::Pawn(controllers);
6162
};
6263

Lines changed: 3 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,9 @@
11
#include "displayapp/screens/WatchFaceDigital.h"
22

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"
3+
#include "watchface_digital.h"
4+
#include "WatchFaceDigital.h"
165

176
using namespace Pinetime::Applications::Screens;
187

19-
WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
20-
const Controllers::Battery& batteryController,
21-
const Controllers::Ble& bleController,
22-
const Controllers::AlarmController& alarmController,
23-
Controllers::NotificationManager& notificationManager,
24-
Controllers::Settings& settingsController,
25-
Controllers::HeartRateController& heartRateController,
26-
Controllers::MotionController& motionController,
27-
Controllers::SimpleWeatherService& weatherService)
28-
: currentDateTime {{}},
29-
dateTimeController {dateTimeController},
30-
notificationManager {notificationManager},
31-
settingsController {settingsController},
32-
heartRateController {heartRateController},
33-
motionController {motionController},
34-
weatherService {weatherService},
35-
statusIcons(batteryController, bleController, alarmController) {
36-
37-
statusIcons.Create();
38-
39-
notificationIcon = lv_label_create(lv_scr_act(), nullptr);
40-
lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME);
41-
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
42-
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
43-
44-
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
45-
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
46-
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
47-
lv_label_set_text(weatherIcon, "");
48-
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_MID, -20, 50);
49-
lv_obj_set_auto_realign(weatherIcon, true);
50-
51-
temperature = lv_label_create(lv_scr_act(), nullptr);
52-
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
53-
lv_label_set_text(temperature, "");
54-
lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 50);
55-
56-
label_date = lv_label_create(lv_scr_act(), nullptr);
57-
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
58-
lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
59-
60-
label_time = lv_label_create(lv_scr_act(), nullptr);
61-
lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_extrabold_compressed);
62-
63-
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
64-
65-
label_time_ampm = lv_label_create(lv_scr_act(), nullptr);
66-
lv_label_set_text_static(label_time_ampm, "");
67-
lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55);
68-
69-
heartbeatIcon = lv_label_create(lv_scr_act(), nullptr);
70-
lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat);
71-
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
72-
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
73-
74-
heartbeatValue = lv_label_create(lv_scr_act(), nullptr);
75-
lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
76-
lv_label_set_text_static(heartbeatValue, "");
77-
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
78-
79-
stepValue = lv_label_create(lv_scr_act(), nullptr);
80-
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
81-
lv_label_set_text_static(stepValue, "0");
82-
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
83-
84-
stepIcon = lv_label_create(lv_scr_act(), nullptr);
85-
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
86-
lv_label_set_text_static(stepIcon, Symbols::shoe);
87-
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
88-
89-
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
90-
Refresh();
91-
}
92-
93-
WatchFaceDigital::~WatchFaceDigital() {
94-
lv_task_del(taskRefresh);
95-
lv_obj_clean(lv_scr_act());
96-
}
97-
98-
void WatchFaceDigital::Refresh() {
99-
statusIcons.Update();
100-
101-
notificationState = notificationManager.AreNewNotificationsAvailable();
102-
if (notificationState.IsUpdated()) {
103-
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
104-
}
105-
106-
currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
107-
108-
if (currentDateTime.IsUpdated()) {
109-
uint8_t hour = dateTimeController.Hours();
110-
uint8_t minute = dateTimeController.Minutes();
111-
112-
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
113-
char ampmChar[3] = "AM";
114-
if (hour == 0) {
115-
hour = 12;
116-
} else if (hour == 12) {
117-
ampmChar[0] = 'P';
118-
} else if (hour > 12) {
119-
hour = hour - 12;
120-
ampmChar[0] = 'P';
121-
}
122-
lv_label_set_text(label_time_ampm, ampmChar);
123-
lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
124-
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
125-
} else {
126-
lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
127-
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
128-
}
129-
130-
currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
131-
if (currentDate.IsUpdated()) {
132-
uint16_t year = dateTimeController.Year();
133-
uint8_t day = dateTimeController.Day();
134-
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
135-
lv_label_set_text_fmt(label_date,
136-
"%s %d %s %d",
137-
dateTimeController.DayOfWeekShortToString(),
138-
day,
139-
dateTimeController.MonthShortToString(),
140-
year);
141-
} else {
142-
lv_label_set_text_fmt(label_date,
143-
"%s %s %d %d",
144-
dateTimeController.DayOfWeekShortToString(),
145-
dateTimeController.MonthShortToString(),
146-
day,
147-
year);
148-
}
149-
lv_obj_realign(label_date);
150-
}
151-
}
152-
153-
heartbeat = heartRateController.HeartRate();
154-
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
155-
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
156-
if (heartbeatRunning.Get()) {
157-
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
158-
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
159-
} else {
160-
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B));
161-
lv_label_set_text_static(heartbeatValue, "");
162-
}
163-
164-
lv_obj_realign(heartbeatIcon);
165-
lv_obj_realign(heartbeatValue);
166-
}
167-
168-
stepCount = motionController.NbSteps();
169-
if (stepCount.IsUpdated()) {
170-
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
171-
lv_obj_realign(stepValue);
172-
lv_obj_realign(stepIcon);
173-
}
174-
175-
currentWeather = weatherService.Current();
176-
if (currentWeather.IsUpdated()) {
177-
auto optCurrentWeather = currentWeather.Get();
178-
if (optCurrentWeather) {
179-
int16_t temp = optCurrentWeather->temperature.Celsius();
180-
char tempUnit = 'C';
181-
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
182-
temp = optCurrentWeather->temperature.Fahrenheit();
183-
tempUnit = 'F';
184-
}
185-
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
186-
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
187-
} else {
188-
lv_label_set_text_static(temperature, "");
189-
lv_label_set_text(weatherIcon, "");
190-
}
191-
lv_obj_realign(temperature);
192-
lv_obj_realign(weatherIcon);
193-
}
8+
WatchFaceDigital::WatchFaceDigital(AppControllers& controllers) : Pawn(watchface_digital, controllers) {
1949
}

0 commit comments

Comments
 (0)