Skip to content

Commit dc0923c

Browse files
committed
Show status icons
1 parent 8cdc948 commit dc0923c

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

src/displayapp/screens/Pawn.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ using namespace Pinetime::Applications::Screens;
2020

2121
#define PARAMS_OBJ(i) ((lv_obj_t*) params[i])
2222

23+
#define PAWN_INST ((Pawn*) amx->userdata[0])
24+
2325
static void event_handler(lv_obj_t* obj, lv_event_t event) {
2426
AMX* amx = (AMX*) lv_obj_get_user_data(lv_scr_act());
2527
int handler_index = (int) lv_obj_get_user_data(obj);
@@ -271,42 +273,62 @@ static cell AMX_NATIVE_CALL F_sprintf(AMX* amx, const cell* params) {
271273
static cell AMX_NATIVE_CALL F_get_datetime(AMX* amx, const cell* params) {
272274
ASSERT_PARAMS(1);
273275

274-
Pawn* pawn = (Pawn*) amx->userdata[0];
276+
Pawn* pawn = PAWN_INST;
275277

276-
pawn->currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(pawn->dateTimeController.CurrentDateTime());
278+
pawn->currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(pawn->controllers.dateTimeController.CurrentDateTime());
277279

278280
cell* ret = amx_Address(amx, params[1]);
279281

280282
ret[0] = pawn->currentDateTime.IsUpdated();
281-
ret[1] = pawn->dateTimeController.Seconds();
282-
ret[2] = pawn->dateTimeController.Minutes();
283-
ret[3] = pawn->dateTimeController.Hours();
284-
ret[4] = pawn->dateTimeController.Day();
285-
ret[5] = pawn->dateTimeController.Year();
283+
ret[1] = pawn->controllers.dateTimeController.Seconds();
284+
ret[2] = pawn->controllers.dateTimeController.Minutes();
285+
ret[3] = pawn->controllers.dateTimeController.Hours();
286+
ret[4] = pawn->controllers.dateTimeController.Day();
287+
ret[5] = pawn->controllers.dateTimeController.Year();
286288

287289
return 0;
288290
}
289291

290292
static cell AMX_NATIVE_CALL F_get_datetime_short_str(AMX* amx, const cell* params) {
291293
ASSERT_PARAMS(2);
292294

293-
Pawn* pawn = (Pawn*) amx->userdata[0];
295+
Pawn* pawn = PAWN_INST;
294296

295297
cell* ret_day = amx_Address(amx, params[1]);
296298
cell* ret_month = amx_Address(amx, params[2]);
297299

298300
if (ret_day != NULL) {
299-
const char* day = pawn->dateTimeController.DayOfWeekShortToString();
301+
const char* day = pawn->controllers.dateTimeController.DayOfWeekShortToString();
300302
amx_SetString(ret_day, day, true, false, 4);
301303
}
302304
if (ret_month != NULL) {
303-
const char* month = pawn->dateTimeController.MonthShortToString();
305+
const char* month = pawn->controllers.dateTimeController.MonthShortToString();
304306
amx_SetString(ret_month, month, true, false, 4);
305307
}
306308

307309
return 0;
308310
}
309311

312+
static cell AMX_NATIVE_CALL F_status_icons_create(AMX* amx, const cell*) {
313+
Pawn* pawn = PAWN_INST;
314+
315+
if (pawn->statusIcons == nullptr) {
316+
pawn->statusIcons = new Pinetime::Applications::Widgets::StatusIcons(pawn->controllers.batteryController, pawn->controllers.bleController, pawn->controllers.alarmController);
317+
pawn->statusIcons->Create();
318+
}
319+
320+
return 0;
321+
}
322+
323+
static cell AMX_NATIVE_CALL F_status_icons_update(AMX* amx, const cell*) {
324+
Pawn* pawn = PAWN_INST;
325+
326+
if (pawn->statusIcons != nullptr)
327+
pawn->statusIcons->Update();
328+
329+
return 0;
330+
}
331+
310332
static int AMXAPI prun_Overlay(AMX* amx, int index) {
311333
AMX_HEADER* hdr;
312334
AMX_OVERLAYINFO* tbl;
@@ -407,9 +429,11 @@ extern "C" const AMX_NATIVE pawn_natives[] = {
407429
F_lv_obj_set_style_local_ptr,
408430
F_get_datetime,
409431
F_get_datetime_short_str,
432+
F_status_icons_create,
433+
F_status_icons_update,
410434
};
411435

412-
Pawn::Pawn(Controllers::DateTime& dateTimeController) : dateTimeController(dateTimeController) {
436+
Pawn::Pawn(AppControllers& controllers) : controllers(controllers) {
413437
LoadProgram();
414438

415439
amx.userdata[0] = this;
@@ -432,6 +456,9 @@ Pawn::~Pawn() {
432456
if (taskRefresh)
433457
lv_task_del(taskRefresh);
434458

459+
if (statusIcons)
460+
delete statusIcons;
461+
435462
lv_obj_clean(lv_scr_act());
436463

437464
amx_Cleanup(&amx);

src/displayapp/screens/Pawn.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "displayapp/Controllers.h"
66
#include "components/datetime/DateTimeController.h"
77
#include "utility/DirtyValue.h"
8+
#include "displayapp/widgets/StatusIcons.h"
89
#include <chrono>
910

1011
#include "pawn/amx.h"
@@ -15,13 +16,15 @@ namespace Pinetime {
1516

1617
class Pawn : public Screen {
1718
public:
18-
Pawn(Controllers::DateTime& dateTimeController);
19+
Pawn(AppControllers& controllers);
1920
~Pawn() override;
2021

2122
void Refresh() override;
2223

2324
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
24-
Controllers::DateTime& dateTimeController;
25+
AppControllers& controllers;
26+
27+
Widgets::StatusIcons* statusIcons = nullptr;
2528

2629
private:
2730
AMX amx;
@@ -40,7 +43,8 @@ namespace Pinetime {
4043
static constexpr const char* icon = "P";
4144

4245
static Screens::Screen* Create(AppControllers& controllers) {
43-
return new Screens::Pawn(controllers.dateTimeController);
46+
// sizeof(Pawn)
47+
return new Screens::Pawn(controllers);
4448
};
4549

4650
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {

src/displayapp/screens/program.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
const unsigned char program[] = {
2-
0xd4, 0x02, 0x00, 0x00, 0xe0, 0xf1, 0x0b, 0x0b, 0x05, 0x00, 0x08, 0x00,
3-
0x7c, 0x00, 0x00, 0x00, 0x64, 0x02, 0x00, 0x00, 0xd4, 0x02, 0x00, 0x00,
4-
0x9c, 0x03, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
2+
0xc8, 0x02, 0x00, 0x00, 0xe0, 0xf1, 0x0b, 0x0b, 0x04, 0x00, 0x08, 0x00,
3+
0x64, 0x00, 0x00, 0x00, 0x64, 0x02, 0x00, 0x00, 0xc8, 0x02, 0x00, 0x00,
4+
0x90, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
55
0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00,
6-
0x4c, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00,
7-
0x01, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8-
0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
9-
0x08, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
10-
0x04, 0x01, 0x00, 0x00, 0x1f, 0x00, 0x40, 0x72, 0x65, 0x66, 0x72, 0x65,
6+
0x4c, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00,
7+
0x14, 0x01, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8+
0x57, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x40, 0x72, 0x65, 0x66, 0x72, 0x65,
119
0x73, 0x68, 0x00, 0x66, 0x6f, 0x6e, 0x74, 0x5f, 0x6a, 0x6d, 0x65, 0x63,
1210
0x00, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
11+
0x70, 0x00, 0x00, 0x00, 0xef, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
1312
0x8e, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
1413
0xfd, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x87, 0x00, 0x08, 0x00,
1514
0x92, 0x00, 0x0c, 0x00, 0x8f, 0x00, 0x08, 0x00, 0x70, 0x00, 0x00, 0x00,
@@ -31,34 +30,34 @@ const unsigned char program[] = {
3130
0x70, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3231
0x16, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x04, 0x00, 0x70, 0x00, 0x00, 0x00,
3332
0xf8, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00,
34-
0x4e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x92, 0x00, 0x18, 0x00,
33+
0x20, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
34+
0xee, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x92, 0x00, 0x18, 0x00,
3535
0x70, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
3636
0x83, 0x00, 0x18, 0x00, 0x07, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00,
3737
0xbc, 0x00, 0x00, 0x00, 0x83, 0x00, 0x18, 0x00, 0xa0, 0x00, 0x08, 0x00,
3838
0x18, 0x00, 0x00, 0x00, 0x83, 0x00, 0x18, 0x00, 0xa0, 0x00, 0x0c, 0x00,
39-
0x18, 0x00, 0x00, 0x00, 0x92, 0x00, 0x50, 0x00, 0x8e, 0x00, 0x08, 0x00,
39+
0x18, 0x00, 0x00, 0x00, 0x92, 0x00, 0x44, 0x00, 0x8e, 0x00, 0x05, 0x00,
4040
0x92, 0x00, 0x30, 0x00, 0x70, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
4141
0x14, 0x00, 0x00, 0x00, 0x92, 0x00, 0x30, 0x00, 0x8f, 0x00, 0x04, 0x00,
4242
0x70, 0x00, 0x00, 0x00, 0xf6, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00,
43-
0x92, 0x00, 0x60, 0x00, 0x92, 0x00, 0x5c, 0x00, 0x70, 0x00, 0x00, 0x00,
43+
0x92, 0x00, 0x54, 0x00, 0x92, 0x00, 0x50, 0x00, 0x70, 0x00, 0x00, 0x00,
4444
0xf0, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x83, 0x00, 0x18, 0x00,
45-
0xa0, 0x00, 0x14, 0x00, 0x18, 0x00, 0x00, 0x00, 0x92, 0x00, 0x60, 0x00,
45+
0xa0, 0x00, 0x14, 0x00, 0x18, 0x00, 0x00, 0x00, 0x92, 0x00, 0x54, 0x00,
4646
0x83, 0x00, 0x18, 0x00, 0xa0, 0x00, 0x10, 0x00, 0x18, 0x00, 0x00, 0x00,
47-
0x92, 0x00, 0x5c, 0x00, 0x92, 0x00, 0x64, 0x00, 0x8e, 0x00, 0x08, 0x00,
47+
0x92, 0x00, 0x50, 0x00, 0x92, 0x00, 0x58, 0x00, 0x8e, 0x00, 0x05, 0x00,
4848
0x92, 0x00, 0x30, 0x00, 0x70, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
4949
0x1c, 0x00, 0x00, 0x00, 0x92, 0x00, 0x30, 0x00, 0x8f, 0x00, 0x08, 0x00,
5050
0x70, 0x00, 0x00, 0x00, 0xf6, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00,
5151
0x8f, 0x00, 0x08, 0x00, 0x70, 0x00, 0x00, 0x00, 0xf7, 0xff, 0xff, 0xff,
52-
0x04, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00,
52+
0x04, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
5353
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5454
0x00, 0x00, 0x3f, 0x3f, 0x30, 0x3a, 0x30, 0x30, 0x00, 0x00, 0x00, 0x30,
5555
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5656
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5757
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5958
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x32, 0x30, 0x25,
6059
0x32, 0x30, 0x25, 0x3a, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00,
6160
0x00, 0x00, 0x00, 0x00, 0x25, 0x20, 0x73, 0x25, 0x73, 0x25, 0x20, 0x64,
6261
0x00, 0x64, 0x25, 0x20
6362
};
64-
unsigned int program_len = 724;
63+
unsigned int program_len = 712;

0 commit comments

Comments
 (0)