Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/nyx/nyx_gui/frontend/gui.c
1476 views
1
/*
2
* Copyright (c) 2018-2025 CTCaer
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms and conditions of the GNU General Public License,
6
* version 2, as published by the Free Software Foundation.
7
*
8
* This program is distributed in the hope it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
* more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
17
#include <stdlib.h>
18
19
#include <bdk.h>
20
21
#include "gui.h"
22
#include "gui_emummc_tools.h"
23
#include "gui_tools.h"
24
#include "gui_info.h"
25
#include "gui_options.h"
26
#include <libs/lvgl/lv_themes/lv_theme_hekate.h>
27
#include <libs/lvgl/lvgl.h>
28
#include "../gfx/logos-gui.h"
29
30
#include "../config.h"
31
#include <libs/fatfs/ff.h>
32
33
extern hekate_config h_cfg;
34
extern nyx_config n_cfg;
35
extern volatile boot_cfg_t *b_cfg;
36
extern volatile nyx_storage_t *nyx_str;
37
38
extern lv_res_t launch_payload(lv_obj_t *list);
39
40
static bool disp_init_done = false;
41
static bool do_auto_reload = false;
42
43
lv_style_t hint_small_style;
44
lv_style_t hint_small_style_white;
45
lv_style_t monospace_text;
46
47
lv_obj_t *payload_list;
48
lv_obj_t *autorcm_btn;
49
lv_obj_t *close_btn;
50
51
lv_img_dsc_t *icon_switch;
52
lv_img_dsc_t *icon_payload;
53
lv_img_dsc_t *icon_lakka;
54
55
lv_img_dsc_t *hekate_bg;
56
57
lv_style_t btn_transp_rel, btn_transp_pr, btn_transp_tgl_rel, btn_transp_tgl_pr;
58
lv_style_t ddlist_transp_bg, ddlist_transp_sel;
59
lv_style_t tabview_btn_pr, tabview_btn_tgl_pr;
60
61
lv_style_t mbox_darken;
62
63
char *text_color;
64
65
typedef struct _jc_lv_driver_t
66
{
67
lv_indev_t *indev_jc;
68
lv_indev_t *indev_touch;
69
// LV_INDEV_READ_PERIOD * JC_CAL_MAX_STEPS = 264 ms.
70
#define JC_CAL_MAX_STEPS 8
71
u32 calibration_step;
72
u16 cx_max;
73
u16 cx_min;
74
u16 cy_max;
75
u16 cy_min;
76
s16 pos_x;
77
s16 pos_y;
78
s16 pos_last_x;
79
s16 pos_last_y;
80
lv_obj_t *cursor;
81
u32 cursor_timeout;
82
bool cursor_hidden;
83
u32 console_timeout;
84
} jc_lv_driver_t;
85
86
static jc_lv_driver_t jc_drv_ctx;
87
88
gui_status_bar_ctx status_bar;
89
90
static void _nyx_disp_init()
91
{
92
vic_surface_t vic_sfc;
93
vic_sfc.src_buf = NYX_FB2_ADDRESS;
94
vic_sfc.dst_buf = NYX_FB_ADDRESS;
95
vic_sfc.width = 1280;
96
vic_sfc.height = 720;
97
vic_sfc.pix_fmt = VIC_PIX_FORMAT_X8R8G8B8;
98
vic_sfc.rotation = VIC_ROTATION_270;
99
100
// Set hardware rotation via VIC.
101
vic_init();
102
vic_set_surface(&vic_sfc);
103
104
// Turn off backlight to hide the transition.
105
display_backlight_brightness(0, 1000);
106
107
// Rotate and copy the first frame.
108
vic_compose();
109
110
// Switch to new window configuration.
111
display_init_window_a_pitch_vic();
112
113
// Enable logging on window D.
114
display_init_window_d_console();
115
// Switch back the backlight.
116
display_backlight_brightness(h_cfg.backlight - 20, 1000);
117
}
118
119
static void _save_log_to_bmp(char *fname)
120
{
121
u32 *fb_ptr = (u32 *)LOG_FB_ADDRESS;
122
123
// Check if there's log written.
124
bool log_changed = false;
125
for (u32 i = 0; i < 0xCD000; i++)
126
{
127
if (fb_ptr[i] != 0)
128
{
129
log_changed = true;
130
break;
131
}
132
}
133
134
if (!log_changed)
135
return;
136
137
const u32 file_size = LOG_FB_SZ + 0x36;
138
u8 *bitmap = malloc(file_size);
139
140
// Reconstruct FB for bottom-top, landscape bmp. Rotation: 656x1280 -> 1280x656.
141
u32 *fb = malloc(LOG_FB_SZ);
142
for (int x = 1279; x > - 1; x--)
143
{
144
for (int y = 655; y > -1; y--)
145
fb[y * 1280 + x] = *fb_ptr++;
146
}
147
148
manual_system_maintenance(true);
149
150
memcpy(bitmap + 0x36, fb, LOG_FB_SZ);
151
152
typedef struct _bmp_t
153
{
154
u16 magic;
155
u32 size;
156
u32 rsvd;
157
u32 data_off;
158
u32 hdr_size;
159
u32 width;
160
u32 height;
161
u16 planes;
162
u16 pxl_bits;
163
u32 comp;
164
u32 img_size;
165
u32 res_h;
166
u32 res_v;
167
u64 rsvd2;
168
} __attribute__((packed)) bmp_t;
169
170
bmp_t *bmp = (bmp_t *)bitmap;
171
172
bmp->magic = 0x4D42;
173
bmp->size = file_size;
174
bmp->rsvd = 0;
175
bmp->data_off = 0x36;
176
bmp->hdr_size = 40;
177
bmp->width = 1280;
178
bmp->height = 656;
179
bmp->planes = 1;
180
bmp->pxl_bits = 32;
181
bmp->comp = 0;
182
bmp->img_size = LOG_FB_SZ;
183
bmp->res_h = 2834;
184
bmp->res_v = 2834;
185
bmp->rsvd2 = 0;
186
187
char path[0x80];
188
strcpy(path, "bootloader/screenshots");
189
s_printf(path + strlen(path), "/nyx%s_log.bmp", fname);
190
sd_save_to_file(bitmap, file_size, path);
191
192
free(bitmap);
193
free(fb);
194
}
195
196
static void _save_fb_to_bmp()
197
{
198
// Disallow screenshots if less than 2s passed.
199
static u32 timer = 0;
200
if (get_tmr_ms() < timer)
201
return;
202
203
if (do_auto_reload)
204
goto exit;
205
206
// Invalidate data.
207
bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false);
208
209
const u32 file_size = NYX_FB_SZ + 0x36;
210
u8 *bitmap = malloc(file_size);
211
u32 *fb = malloc(NYX_FB_SZ);
212
u32 *fb_ptr = (u32 *)NYX_FB2_ADDRESS;
213
u32 line_bytes = 1280 * sizeof(u32);
214
215
// Reconstruct FB for bottom-top, landscape bmp. No rotation.
216
for (int y = 719; y > -1; y--)
217
{
218
memcpy(&fb[y * 1280], fb_ptr, line_bytes);
219
fb_ptr += line_bytes / sizeof(u32);
220
}
221
222
// Create notification box.
223
lv_obj_t * mbox = lv_mbox_create(lv_layer_top(), NULL);
224
lv_mbox_set_recolor_text(mbox, true);
225
lv_mbox_set_text(mbox, SYMBOL_CAMERA" #FFDD00 Saving screenshot...#");
226
lv_obj_set_width(mbox, LV_DPI * 4);
227
lv_obj_set_top(mbox, true);
228
lv_obj_align(mbox, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
229
230
// Capture effect.
231
display_backlight_brightness(255, 100);
232
msleep(150);
233
display_backlight_brightness(h_cfg.backlight - 20, 100);
234
235
manual_system_maintenance(true);
236
237
memcpy(bitmap + 0x36, fb, NYX_FB_SZ);
238
239
typedef struct _bmp_t
240
{
241
u16 magic;
242
u32 size;
243
u32 rsvd;
244
u32 data_off;
245
u32 hdr_size;
246
u32 width;
247
u32 height;
248
u16 planes;
249
u16 pxl_bits;
250
u32 comp;
251
u32 img_size;
252
u32 res_h;
253
u32 res_v;
254
u64 rsvd2;
255
} __attribute__((packed)) bmp_t;
256
257
bmp_t *bmp = (bmp_t *)bitmap;
258
259
bmp->magic = 0x4D42;
260
bmp->size = file_size;
261
bmp->rsvd = 0;
262
bmp->data_off = 0x36;
263
bmp->hdr_size = 40;
264
bmp->width = 1280;
265
bmp->height = 720;
266
bmp->planes = 1;
267
bmp->pxl_bits = 32;
268
bmp->comp = 0;
269
bmp->img_size = NYX_FB_SZ;
270
bmp->res_h = 2834;
271
bmp->res_v = 2834;
272
bmp->rsvd2 = 0;
273
274
sd_mount();
275
276
char path[0x80];
277
278
strcpy(path, "bootloader");
279
f_mkdir(path);
280
strcat(path, "/screenshots");
281
f_mkdir(path);
282
283
// Create date/time name.
284
char fname[32];
285
rtc_time_t time;
286
max77620_rtc_get_time_adjusted(&time);
287
s_printf(fname, "%04d%02d%02d_%02d%02d%02d", time.year, time.month, time.day, time.hour, time.min, time.sec);
288
s_printf(path + strlen(path), "/nyx%s.bmp", fname);
289
290
// Save screenshot and log.
291
int res = sd_save_to_file(bitmap, file_size, path);
292
if (!res)
293
_save_log_to_bmp(fname);
294
295
sd_unmount();
296
297
free(bitmap);
298
free(fb);
299
300
if (!res)
301
lv_mbox_set_text(mbox, SYMBOL_CAMERA" #96FF00 Screenshot saved!#");
302
else
303
lv_mbox_set_text(mbox, SYMBOL_WARNING" #FFDD00 Screenshot failed!#");
304
manual_system_maintenance(true);
305
lv_mbox_start_auto_close(mbox, 4000);
306
307
exit:
308
// Set timer to 2s.
309
timer = get_tmr_ms() + 2000;
310
}
311
312
static void _disp_fb_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t *color_p)
313
{
314
// Draw to intermediate non-rotated framebuffer.
315
gfx_set_rect_pitch((u32 *)NYX_FB2_ADDRESS, (u32 *)color_p, 1280, x1, y1, x2, y2);
316
317
// Rotate and copy to visible framebuffer.
318
if (disp_init_done)
319
vic_compose();
320
321
// Check if display init was done. If it's the first big draw, init.
322
if (!disp_init_done && ((x2 - x1 + 1) > 600))
323
{
324
disp_init_done = true;
325
_nyx_disp_init();
326
}
327
328
lv_flush_ready();
329
}
330
331
static touch_event touchpad;
332
static bool touch_enabled;
333
static bool console_enabled = false;
334
335
static bool _fts_touch_read(lv_indev_data_t *data)
336
{
337
if (touch_enabled)
338
touch_poll(&touchpad);
339
else
340
return false;
341
342
// Take a screenshot if 3 fingers.
343
if (touchpad.fingers > 2)
344
{
345
_save_fb_to_bmp();
346
347
data->state = LV_INDEV_STATE_REL;
348
return false;
349
}
350
351
if (console_enabled)
352
{
353
// Print input debugging in console.
354
gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy, &gfx_con.savedcol);
355
gfx_con_setpos(32, 638, GFX_COL_AUTO);
356
gfx_con.fntsz = 8;
357
gfx_printf("x: %4d, y: %4d | z: %3d | ", touchpad.x, touchpad.y, touchpad.z);
358
gfx_printf("1: %02X, 2: %02X, 3: %02X, ", touchpad.raw[1], touchpad.raw[2], touchpad.raw[3]);
359
gfx_printf("4: %02X, 5: %02X, 6: %02X, 7: %02X",
360
touchpad.raw[4], touchpad.raw[5], touchpad.raw[6], touchpad.raw[7]);
361
gfx_con_setpos(gfx_con.savedx, gfx_con.savedy, gfx_con.savedcol);
362
gfx_con.fntsz = 16;
363
364
return false;
365
}
366
367
// Always set touch points.
368
data->point.x = touchpad.x;
369
data->point.y = touchpad.y;
370
371
// Decide touch enable.
372
switch (touchpad.type & STMFTS_MASK_EVENT_ID)
373
{
374
case STMFTS_EV_MULTI_TOUCH_ENTER:
375
case STMFTS_EV_MULTI_TOUCH_MOTION:
376
data->state = LV_INDEV_STATE_PR;
377
break;
378
case STMFTS_EV_MULTI_TOUCH_LEAVE:
379
data->state = LV_INDEV_STATE_REL;
380
break;
381
case STMFTS_EV_NO_EVENT:
382
default:
383
if (touchpad.touch)
384
data->state = LV_INDEV_STATE_PR;
385
else
386
data->state = LV_INDEV_STATE_REL;
387
break;
388
}
389
390
return false; // No buffering so no more data read.
391
}
392
393
static bool _jc_virt_mouse_read(lv_indev_data_t *data)
394
{
395
// Poll Joy-Con.
396
jc_gamepad_rpt_t *jc_pad = joycon_poll();
397
398
if (!jc_pad)
399
{
400
data->state = LV_INDEV_STATE_REL;
401
return false;
402
}
403
404
// Take a screenshot if Capture button is pressed.
405
if (jc_pad->cap)
406
{
407
_save_fb_to_bmp();
408
409
data->state = LV_INDEV_STATE_REL;
410
return false;
411
}
412
413
// Calibrate left stick.
414
if (jc_drv_ctx.calibration_step != JC_CAL_MAX_STEPS)
415
{
416
if (n_cfg.jc_force_right)
417
{
418
if (jc_pad->conn_r
419
&& jc_pad->rstick_x > 0x400 && jc_pad->rstick_y > 0x400
420
&& jc_pad->rstick_x < 0xC00 && jc_pad->rstick_y < 0xC00)
421
{
422
jc_drv_ctx.calibration_step++;
423
jc_drv_ctx.cx_max = jc_pad->rstick_x + 0x96;
424
jc_drv_ctx.cx_min = jc_pad->rstick_x - 0x96;
425
jc_drv_ctx.cy_max = jc_pad->rstick_y + 0x96;
426
jc_drv_ctx.cy_min = jc_pad->rstick_y - 0x96;
427
jc_drv_ctx.cursor_timeout = 0;
428
}
429
}
430
else if (jc_pad->conn_l
431
&& jc_pad->lstick_x > 0x400 && jc_pad->lstick_y > 0x400
432
&& jc_pad->lstick_x < 0xC00 && jc_pad->lstick_y < 0xC00)
433
{
434
jc_drv_ctx.calibration_step++;
435
jc_drv_ctx.cx_max = jc_pad->lstick_x + 0x96;
436
jc_drv_ctx.cx_min = jc_pad->lstick_x - 0x96;
437
jc_drv_ctx.cy_max = jc_pad->lstick_y + 0x96;
438
jc_drv_ctx.cy_min = jc_pad->lstick_y - 0x96;
439
jc_drv_ctx.cursor_timeout = 0;
440
}
441
442
if (jc_drv_ctx.calibration_step != JC_CAL_MAX_STEPS)
443
{
444
data->state = LV_INDEV_STATE_REL;
445
return false;
446
}
447
}
448
449
// Re-calibrate on disconnection.
450
if (n_cfg.jc_force_right && !jc_pad->conn_r)
451
jc_drv_ctx.calibration_step = 0;
452
else if (!n_cfg.jc_force_right && !jc_pad->conn_l)
453
jc_drv_ctx.calibration_step = 0;
454
455
// Set button presses.
456
if (jc_pad->a || jc_pad->zl || jc_pad->zr)
457
data->state = LV_INDEV_STATE_PR;
458
else
459
data->state = LV_INDEV_STATE_REL;
460
461
// Enable console.
462
if (jc_pad->plus || jc_pad->minus)
463
{
464
if (((u32)get_tmr_ms() - jc_drv_ctx.console_timeout) > 1000)
465
{
466
if (!console_enabled)
467
{
468
display_window_d_console_enable();
469
console_enabled = true;
470
gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy, &gfx_con.savedcol);
471
gfx_con_setpos(964, 630, GFX_COL_AUTO);
472
gfx_printf("Press -/+ to close");
473
gfx_con_setpos(gfx_con.savedx, gfx_con.savedy, gfx_con.savedcol);
474
}
475
else
476
{
477
display_window_d_console_disable();
478
console_enabled = false;
479
}
480
481
jc_drv_ctx.console_timeout = get_tmr_ms();
482
}
483
484
data->state = LV_INDEV_STATE_REL;
485
return false;
486
}
487
488
if (console_enabled)
489
{
490
// Print input debugging in console.
491
gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy, &gfx_con.savedcol);
492
gfx_con_setpos(32, 630, GFX_COL_AUTO);
493
gfx_con.fntsz = 8;
494
gfx_printf("x: %4X, y: %4X | rx: %4X, ry: %4X | b: %06X | bt: %d %d",
495
jc_pad->lstick_x, jc_pad->lstick_y, jc_pad->rstick_x, jc_pad->rstick_y,
496
jc_pad->buttons, jc_pad->batt_info_l, jc_pad->batt_info_r);
497
gfx_con_setpos(gfx_con.savedx, gfx_con.savedy, gfx_con.savedcol);
498
gfx_con.fntsz = 16;
499
500
data->state = LV_INDEV_STATE_REL;
501
return false;
502
}
503
504
// Calculate new cursor position.
505
if (!n_cfg.jc_force_right)
506
{
507
// Left stick X.
508
if (jc_pad->lstick_x <= jc_drv_ctx.cx_max && jc_pad->lstick_x >= jc_drv_ctx.cx_min)
509
jc_drv_ctx.pos_x += 0;
510
else if (jc_pad->lstick_x > jc_drv_ctx.cx_max)
511
jc_drv_ctx.pos_x += ((jc_pad->lstick_x - jc_drv_ctx.cx_max) / 30);
512
else
513
jc_drv_ctx.pos_x -= ((jc_drv_ctx.cx_min - jc_pad->lstick_x) / 30);
514
515
// Left stick Y.
516
if (jc_pad->lstick_y <= jc_drv_ctx.cy_max && jc_pad->lstick_y >= jc_drv_ctx.cy_min)
517
jc_drv_ctx.pos_y += 0;
518
else if (jc_pad->lstick_y > jc_drv_ctx.cy_max)
519
{
520
s16 val = (jc_pad->lstick_y - jc_drv_ctx.cy_max) / 30;
521
// Hoag has inverted Y axis.
522
if (jc_pad->sio_mode)
523
val *= -1;
524
jc_drv_ctx.pos_y -= val;
525
}
526
else
527
{
528
s16 val = (jc_drv_ctx.cy_min - jc_pad->lstick_y) / 30;
529
// Hoag has inverted Y axis.
530
if (jc_pad->sio_mode)
531
val *= -1;
532
jc_drv_ctx.pos_y += val;
533
}
534
}
535
else
536
{
537
// Right stick X.
538
if (jc_pad->rstick_x <= jc_drv_ctx.cx_max && jc_pad->rstick_x >= jc_drv_ctx.cx_min)
539
jc_drv_ctx.pos_x += 0;
540
else if (jc_pad->rstick_x > jc_drv_ctx.cx_max)
541
jc_drv_ctx.pos_x += ((jc_pad->rstick_x - jc_drv_ctx.cx_max) / 30);
542
else
543
jc_drv_ctx.pos_x -= ((jc_drv_ctx.cx_min - jc_pad->rstick_x) / 30);
544
545
// Right stick Y.
546
if (jc_pad->rstick_y <= jc_drv_ctx.cy_max && jc_pad->rstick_y >= jc_drv_ctx.cy_min)
547
jc_drv_ctx.pos_y += 0;
548
else if (jc_pad->rstick_y > jc_drv_ctx.cy_max)
549
{
550
s16 val = (jc_pad->rstick_y - jc_drv_ctx.cy_max) / 30;
551
// Hoag has inverted Y axis.
552
if (jc_pad->sio_mode)
553
val *= -1;
554
jc_drv_ctx.pos_y -= val;
555
}
556
else
557
{
558
s16 val = (jc_drv_ctx.cy_min - jc_pad->rstick_y) / 30;
559
// Hoag has inverted Y axis.
560
if (jc_pad->sio_mode)
561
val *= -1;
562
jc_drv_ctx.pos_y += val;
563
}
564
}
565
566
// Ensure value inside screen limits.
567
if (jc_drv_ctx.pos_x < 0)
568
jc_drv_ctx.pos_x = 0;
569
else if (jc_drv_ctx.pos_x > 1279)
570
jc_drv_ctx.pos_x = 1279;
571
572
if (jc_drv_ctx.pos_y < 0)
573
jc_drv_ctx.pos_y = 0;
574
else if (jc_drv_ctx.pos_y > 719)
575
jc_drv_ctx.pos_y = 719;
576
577
// Set cursor position.
578
data->point.x = jc_drv_ctx.pos_x;
579
data->point.y = jc_drv_ctx.pos_y;
580
581
// Auto hide cursor.
582
if (jc_drv_ctx.pos_x != jc_drv_ctx.pos_last_x || jc_drv_ctx.pos_y != jc_drv_ctx.pos_last_y)
583
{
584
jc_drv_ctx.pos_last_x = jc_drv_ctx.pos_x;
585
jc_drv_ctx.pos_last_y = jc_drv_ctx.pos_y;
586
587
jc_drv_ctx.cursor_hidden = false;
588
jc_drv_ctx.cursor_timeout = get_tmr_ms();
589
lv_indev_set_cursor(jc_drv_ctx.indev_jc, jc_drv_ctx.cursor);
590
591
// Un hide cursor.
592
lv_obj_set_opa_scale_enable(jc_drv_ctx.cursor, false);
593
}
594
else
595
{
596
if (!jc_drv_ctx.cursor_hidden)
597
{
598
if (((u32)get_tmr_ms() - jc_drv_ctx.cursor_timeout) > 3000)
599
{
600
// Remove cursor and hide it.
601
lv_indev_set_cursor(jc_drv_ctx.indev_jc, NULL);
602
lv_obj_set_opa_scale_enable(jc_drv_ctx.cursor, true);
603
lv_obj_set_opa_scale(jc_drv_ctx.cursor, LV_OPA_TRANSP);
604
605
jc_drv_ctx.cursor_hidden = true;
606
}
607
}
608
else
609
data->state = LV_INDEV_STATE_REL; // Ensure that no clicks are allowed.
610
}
611
612
if (jc_pad->b && close_btn)
613
{
614
lv_action_t close_btn_action = lv_btn_get_action(close_btn, LV_BTN_ACTION_CLICK);
615
close_btn_action(close_btn);
616
close_btn = NULL;
617
}
618
619
return false; // No buffering so no more data read.
620
}
621
622
typedef struct _system_maintenance_tasks_t
623
{
624
union
625
{
626
lv_task_t *tasks[2];
627
struct
628
{
629
lv_task_t *status_bar;
630
lv_task_t *dram_periodic_comp;
631
} task;
632
};
633
} system_maintenance_tasks_t;
634
635
static system_maintenance_tasks_t system_tasks;
636
637
void manual_system_maintenance(bool refresh)
638
{
639
for (u32 task_idx = 0; task_idx < (sizeof(system_maintenance_tasks_t) / sizeof(lv_task_t *)); task_idx++)
640
{
641
lv_task_t *task = system_tasks.tasks[task_idx];
642
if (task && (lv_tick_elaps(task->last_run) >= task->period))
643
{
644
task->last_run = lv_tick_get();
645
task->task(task->param);
646
}
647
}
648
if (refresh)
649
lv_refr_now();
650
}
651
652
lv_img_dsc_t *bmp_to_lvimg_obj(const char *path)
653
{
654
u32 fsize;
655
u8 *bitmap = sd_file_read(path, &fsize);
656
if (!bitmap)
657
return NULL;
658
659
struct _bmp_data
660
{
661
u32 size;
662
u32 size_x;
663
u32 size_y;
664
u32 offset;
665
};
666
667
struct _bmp_data bmpData;
668
669
// Get values manually to avoid unaligned access.
670
bmpData.size = bitmap[2] | bitmap[3] << 8 |
671
bitmap[4] << 16 | bitmap[5] << 24;
672
bmpData.offset = bitmap[10] | bitmap[11] << 8 |
673
bitmap[12] << 16 | bitmap[13] << 24;
674
bmpData.size_x = bitmap[18] | bitmap[19] << 8 |
675
bitmap[20] << 16 | bitmap[21] << 24;
676
bmpData.size_y = bitmap[22] | bitmap[23] << 8 |
677
bitmap[24] << 16 | bitmap[25] << 24;
678
// Sanity check.
679
if (bitmap[0] == 'B' &&
680
bitmap[1] == 'M' &&
681
bitmap[28] == 32 && // Only 32 bit BMPs allowed.
682
bmpData.size <= fsize)
683
{
684
// Check if non-default Bottom-Top.
685
bool flipped = false;
686
if (bmpData.size_y & 0x80000000)
687
{
688
bmpData.size_y = ~(bmpData.size_y) + 1;
689
flipped = true;
690
}
691
692
lv_img_dsc_t *img_desc = (lv_img_dsc_t *)bitmap;
693
u32 offset_copy = ALIGN((u32)bitmap + sizeof(lv_img_dsc_t), 0x10);
694
695
img_desc->header.always_zero = 0;
696
img_desc->header.w = bmpData.size_x;
697
img_desc->header.h = bmpData.size_y;
698
img_desc->header.cf = (bitmap[28] == 32) ? LV_IMG_CF_TRUE_COLOR_ALPHA : LV_IMG_CF_TRUE_COLOR; // Only LV_IMG_CF_TRUE_COLOR_ALPHA is actually allowed.
699
img_desc->data_size = bmpData.size - bmpData.offset;
700
img_desc->data = (u8 *)offset_copy;
701
702
u32 *tmp = malloc(bmpData.size);
703
u32 *tmp2 = (u32 *)offset_copy;
704
705
// Copy the unaligned data to an aligned buffer.
706
memcpy((u8 *)tmp, bitmap + bmpData.offset, img_desc->data_size);
707
u32 j = 0;
708
709
if (!flipped)
710
{
711
for (u32 y = 0; y < bmpData.size_y; y++)
712
{
713
for (u32 x = 0; x < bmpData.size_x; x++)
714
tmp2[j++] = tmp[(bmpData.size_y - 1 - y ) * bmpData.size_x + x];
715
}
716
}
717
else
718
{
719
for (u32 y = 0; y < bmpData.size_y; y++)
720
{
721
for (u32 x = 0; x < bmpData.size_x; x++)
722
tmp2[j++] = tmp[y * bmpData.size_x + x];
723
}
724
}
725
726
free(tmp);
727
}
728
else
729
{
730
free(bitmap);
731
return NULL;
732
}
733
734
return (lv_img_dsc_t *)bitmap;
735
}
736
737
lv_res_t nyx_generic_onoff_toggle(lv_obj_t *btn)
738
{
739
lv_obj_t *label_btn = lv_obj_get_child(btn, NULL);
740
lv_obj_t *label_btn2 = lv_obj_get_child(btn, label_btn);
741
742
char label_text[64];
743
if (!label_btn2)
744
{
745
strcpy(label_text, lv_label_get_text(label_btn));
746
label_text[strlen(label_text) - 15] = 0;
747
748
if (!(lv_btn_get_state(btn) & LV_BTN_STATE_TGL_REL))
749
{
750
strcat(label_text, "#D0D0D0 OFF#");
751
lv_label_set_text(label_btn, label_text);
752
}
753
else
754
{
755
s_printf(label_text, "%s%s%s", label_text, text_color, " ON #");
756
lv_label_set_text(label_btn, label_text);
757
}
758
}
759
else
760
{
761
if (!(lv_btn_get_state(btn) & LV_BTN_STATE_TGL_REL))
762
lv_label_set_text(label_btn, "#D0D0D0 OFF#");
763
else
764
{
765
s_printf(label_text, "%s%s", text_color, " ON #");
766
lv_label_set_text(label_btn, label_text);
767
}
768
}
769
770
return LV_RES_OK;
771
}
772
773
lv_res_t mbox_action(lv_obj_t *btns, const char *txt)
774
{
775
lv_obj_t *mbox = lv_mbox_get_from_btn(btns);
776
lv_obj_t *dark_bg = lv_obj_get_parent(mbox);
777
778
lv_obj_del(dark_bg); // Deletes children also (mbox).
779
780
return LV_RES_INV;
781
}
782
783
bool nyx_emmc_check_battery_enough()
784
{
785
if (fuse_read_hw_state() == FUSE_NX_HW_STATE_DEV)
786
return true;
787
788
int batt_volt = 0;
789
790
max17050_get_property(MAX17050_VCELL, &batt_volt);
791
792
if (batt_volt && batt_volt < 3650)
793
{
794
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
795
lv_obj_set_style(dark_bg, &mbox_darken);
796
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
797
798
static const char * mbox_btn_map[] = { "\251", "\222OK", "\251", "" };
799
lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL);
800
lv_mbox_set_recolor_text(mbox, true);
801
802
lv_mbox_set_text(mbox,
803
"#FF8000 Battery Check#\n\n"
804
"#FFDD00 Battery is not enough to carry on#\n"
805
"#FFDD00 with selected operation!#\n\n"
806
"Charge to at least #C7EA46 3650 mV#, and try again!");
807
808
lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action);
809
lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5);
810
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
811
lv_obj_set_top(mbox, true);
812
813
return false;
814
}
815
816
return true;
817
}
818
819
static void _nyx_sd_card_issues_warning(void *param)
820
{
821
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
822
lv_obj_set_style(dark_bg, &mbox_darken);
823
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
824
825
static const char * mbox_btn_map[] = { "\251", "\222OK", "\251", "" };
826
lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL);
827
lv_mbox_set_recolor_text(mbox, true);
828
829
lv_mbox_set_text(mbox,
830
"#FF8000 SD Card Issues Warning#\n\n"
831
"#FFDD00 The SD Card is initialized in 1-bit mode!#\n"
832
"#FFDD00 This might mean detached or broken connector!#\n\n"
833
"You might want to check\n#C7EA46 Console Info# -> #C7EA46 microSD#");
834
835
lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action);
836
lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5);
837
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
838
lv_obj_set_top(mbox, true);
839
}
840
841
void nyx_window_toggle_buttons(lv_obj_t *win, bool disable)
842
{
843
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
844
lv_obj_t * hbtn;
845
846
hbtn = lv_obj_get_child_back(ext->header, NULL);
847
hbtn = lv_obj_get_child_back(ext->header, hbtn); // Skip the title.
848
849
if (disable)
850
{
851
while (hbtn != NULL)
852
{
853
lv_obj_set_opa_scale(hbtn, LV_OPA_40);
854
lv_obj_set_opa_scale_enable(hbtn, true);
855
lv_obj_set_click(hbtn, false);
856
hbtn = lv_obj_get_child_back(ext->header, hbtn);
857
}
858
}
859
else
860
{
861
while (hbtn != NULL)
862
{
863
lv_obj_set_opa_scale(hbtn, LV_OPA_COVER);
864
lv_obj_set_click(hbtn, true);
865
hbtn = lv_obj_get_child_back(ext->header, hbtn);
866
}
867
}
868
}
869
870
lv_res_t nyx_win_close_action_custom(lv_obj_t * btn)
871
{
872
close_btn = NULL;
873
874
return lv_win_close_action(btn);
875
}
876
877
lv_obj_t *nyx_create_standard_window(const char *win_title)
878
{
879
static lv_style_t win_bg_style;
880
881
lv_style_copy(&win_bg_style, &lv_style_plain);
882
win_bg_style.body.main_color = lv_theme_get_current()->bg->body.main_color;
883
win_bg_style.body.grad_color = win_bg_style.body.main_color;
884
885
lv_obj_t *win = lv_win_create(lv_scr_act(), NULL);
886
lv_win_set_title(win, win_title);
887
lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style);
888
lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES);
889
890
close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", nyx_win_close_action_custom);
891
892
return win;
893
}
894
895
lv_obj_t *nyx_create_window_custom_close_btn(const char *win_title, lv_action_t rel_action)
896
{
897
static lv_style_t win_bg_style;
898
899
lv_style_copy(&win_bg_style, &lv_style_plain);
900
win_bg_style.body.main_color = lv_theme_get_current()->bg->body.main_color;
901
win_bg_style.body.grad_color = win_bg_style.body.main_color;
902
903
lv_obj_t *win = lv_win_create(lv_scr_act(), NULL);
904
lv_win_set_title(win, win_title);
905
lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style);
906
lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES);
907
908
close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", rel_action);
909
910
return win;
911
}
912
913
static bool launch_logs_enable = false;
914
915
static void _launch_hos(u8 autoboot, u8 autoboot_list)
916
{
917
b_cfg->boot_cfg = BOOT_CFG_AUTOBOOT_EN;
918
if (launch_logs_enable)
919
b_cfg->boot_cfg |= BOOT_CFG_FROM_LAUNCH;
920
b_cfg->autoboot = autoboot;
921
b_cfg->autoboot_list = autoboot_list;
922
923
void (*main_ptr)() = (void *)nyx_str->hekate;
924
925
sd_end();
926
927
hw_deinit(false, 0);
928
929
(*main_ptr)();
930
}
931
932
void reload_nyx(lv_obj_t *obj, bool force)
933
{
934
if (!force)
935
{
936
sd_mount();
937
938
// Check that Nyx still exists.
939
if (f_stat("bootloader/sys/nyx.bin", NULL))
940
{
941
sd_unmount();
942
943
// Remove lvgl object in case of being invoked from a window.
944
if (obj)
945
lv_obj_del(obj);
946
947
do_auto_reload = false;
948
949
return;
950
}
951
}
952
953
b_cfg->boot_cfg = BOOT_CFG_AUTOBOOT_EN;
954
b_cfg->autoboot = 0;
955
b_cfg->autoboot_list = 0;
956
b_cfg->extra_cfg = 0;
957
958
void (*main_ptr)() = (void *)nyx_str->hekate;
959
960
sd_end();
961
962
hw_deinit(false, 0);
963
964
(*main_ptr)();
965
}
966
967
static lv_res_t reload_action(lv_obj_t *btns, const char *txt)
968
{
969
if (!lv_btnm_get_pressed(btns))
970
reload_nyx(NULL, false);
971
972
return mbox_action(btns, txt);
973
}
974
975
static lv_res_t _removed_sd_action(lv_obj_t *btns, const char *txt)
976
{
977
u32 btnidx = lv_btnm_get_pressed(btns);
978
979
switch (btnidx)
980
{
981
case 0:
982
if (h_cfg.rcm_patched)
983
power_set_state(POWER_OFF_REBOOT);
984
else
985
power_set_state(REBOOT_RCM);
986
break;
987
case 1:
988
power_set_state(POWER_OFF_RESET);
989
break;
990
case 2:
991
sd_end();
992
do_auto_reload = false;
993
break;
994
}
995
996
return mbox_action(btns, txt);
997
}
998
999
static void _check_sd_card_removed(void *params)
1000
{
1001
static lv_obj_t *dark_bg = NULL;
1002
1003
// The following checks if SDMMC_1 is initialized.
1004
// If yes and card was removed, shows a message box,
1005
// that will reload Nyx, when the card is inserted again.
1006
if (!do_auto_reload && sd_get_card_removed())
1007
{
1008
dark_bg = lv_obj_create(lv_scr_act(), NULL);
1009
lv_obj_set_style(dark_bg, &mbox_darken);
1010
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
1011
1012
static const char * mbox_btn_map[] = { "\221Reboot (RCM)", "\221Power Off", "\221Do not reload", "" };
1013
static const char * mbox_btn_map_rcm_patched[] = { "\221Reboot", "\221Power Off", "\221Do not reload", "" };
1014
lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL);
1015
lv_mbox_set_recolor_text(mbox, true);
1016
lv_obj_set_width(mbox, LV_HOR_RES * 6 / 9);
1017
1018
lv_mbox_set_text(mbox, "\n#FF8000 SD card was removed!#\n\n#96FF00 Nyx will reload after inserting it.#\n\nReminder that you can use UMS instead of removing it.\n");
1019
lv_mbox_add_btns(mbox, h_cfg.rcm_patched ? mbox_btn_map_rcm_patched : mbox_btn_map, _removed_sd_action);
1020
1021
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
1022
lv_obj_set_top(mbox, true);
1023
1024
do_auto_reload = true;
1025
}
1026
1027
// If in reload state and card was inserted, reload nyx.
1028
if (do_auto_reload && !sd_get_card_removed())
1029
reload_nyx(dark_bg, false);
1030
}
1031
1032
lv_task_t *task_emmc_errors;
1033
static void _nyx_emmc_issues_warning(void *params)
1034
{
1035
if (emmc_get_mode() < EMMC_MMC_HS400)
1036
{
1037
// Remove task.
1038
lv_task_del(task_emmc_errors);
1039
1040
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
1041
lv_obj_set_style(dark_bg, &mbox_darken);
1042
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
1043
1044
static const char * mbox_btn_map[] = { "\251", "\222OK", "\251", "" };
1045
lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL);
1046
lv_mbox_set_recolor_text(mbox, true);
1047
1048
lv_mbox_set_text(mbox,
1049
"#FF8000 eMMC Issues Warning#\n\n"
1050
"#FFDD00 Your eMMC is initialized in a slower mode!#\n"
1051
"#FFDD00 This might mean hardware issues!#\n\n"
1052
"You might want to check\n#C7EA46 Console Info# -> #C7EA46 eMMC#");
1053
1054
lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action);
1055
lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5);
1056
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
1057
lv_obj_set_top(mbox, true);
1058
}
1059
}
1060
1061
static lv_res_t _reboot_action(lv_obj_t *btns, const char *txt)
1062
{
1063
u32 btnidx = lv_btnm_get_pressed(btns);
1064
1065
switch (btnidx)
1066
{
1067
case 0:
1068
power_set_state(REBOOT_BYPASS_FUSES);
1069
break;
1070
case 1:
1071
if (h_cfg.rcm_patched)
1072
power_set_state(POWER_OFF_REBOOT);
1073
else
1074
power_set_state(REBOOT_RCM);
1075
break;
1076
}
1077
1078
return mbox_action(btns, txt);
1079
}
1080
1081
static lv_res_t _poweroff_action(lv_obj_t *btns, const char *txt)
1082
{
1083
if (!lv_btnm_get_pressed(btns))
1084
power_set_state(POWER_OFF_RESET);
1085
1086
return mbox_action(btns, txt);
1087
}
1088
1089
static lv_res_t _create_mbox_reload(lv_obj_t *btn)
1090
{
1091
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
1092
lv_obj_set_style(dark_bg, &mbox_darken);
1093
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
1094
1095
static const char * mbox_btn_map[] = { "\221Reload", "\221Cancel", "" };
1096
lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL);
1097
lv_mbox_set_recolor_text(mbox, true);
1098
lv_obj_set_width(mbox, LV_HOR_RES * 4 / 10);
1099
1100
lv_mbox_set_text(mbox, "#FF8000 Do you really want#\n#FF8000 to reload hekate & Nyx?#\n\n"
1101
"This also checks\n#96FF00 bootloader/update.bin#\nfor hekate updates");
1102
1103
lv_mbox_add_btns(mbox, mbox_btn_map, reload_action);
1104
1105
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
1106
lv_obj_set_top(mbox, true);
1107
1108
return LV_RES_OK;
1109
}
1110
1111
static lv_res_t _create_mbox_reboot(lv_obj_t *btn)
1112
{
1113
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
1114
lv_obj_set_style(dark_bg, &mbox_darken);
1115
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
1116
1117
static const char * mbox_btn_map[] = { "\221OFW", "\221RCM", "\221Cancel", "" };
1118
static const char * mbox_btn_map_autorcm[] = { "\261OFW", "\221RCM", "\221Cancel", "" };
1119
static const char * mbox_btn_map_patched[] = { "\221OFW", "\221Normal", "\221Cancel", "" };
1120
lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL);
1121
lv_mbox_set_recolor_text(mbox, true);
1122
lv_obj_set_width(mbox, LV_HOR_RES / 2);
1123
1124
lv_mbox_set_text(mbox, "#FF8000 Choose where to reboot:#");
1125
1126
if (h_cfg.rcm_patched)
1127
lv_mbox_add_btns(mbox, mbox_btn_map_patched, _reboot_action);
1128
else
1129
lv_mbox_add_btns(mbox, !h_cfg.autorcm_enabled ? mbox_btn_map : mbox_btn_map_autorcm, _reboot_action);
1130
1131
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
1132
lv_obj_set_top(mbox, true);
1133
1134
return LV_RES_OK;
1135
}
1136
1137
static lv_res_t _create_mbox_poweroff(lv_obj_t *btn)
1138
{
1139
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
1140
lv_obj_set_style(dark_bg, &mbox_darken);
1141
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
1142
1143
static const char * mbox_btn_map[] = { "\221Power Off", "\221Cancel", "" };
1144
lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL);
1145
lv_mbox_set_recolor_text(mbox, true);
1146
lv_obj_set_width(mbox, LV_HOR_RES * 4 / 10);
1147
1148
lv_mbox_set_text(mbox, "#FF8000 Do you really want#\n#FF8000 to power off?#");
1149
1150
lv_mbox_add_btns(mbox, mbox_btn_map, _poweroff_action);
1151
1152
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
1153
lv_obj_set_top(mbox, true);
1154
1155
return LV_RES_OK;
1156
}
1157
1158
void nyx_create_onoff_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, const char *btn_name, lv_action_t action, bool transparent)
1159
{
1160
// Create buttons that are flat and text, plus On/Off switch.
1161
static lv_style_t btn_onoff_rel_hos_style, btn_onoff_pr_hos_style;
1162
lv_style_copy(&btn_onoff_rel_hos_style, th->btn.rel);
1163
btn_onoff_rel_hos_style.body.shadow.width = 0;
1164
btn_onoff_rel_hos_style.body.border.width = 0;
1165
btn_onoff_rel_hos_style.body.padding.hor = 0;
1166
btn_onoff_rel_hos_style.body.radius = 0;
1167
btn_onoff_rel_hos_style.body.empty = 1;
1168
1169
lv_style_copy(&btn_onoff_pr_hos_style, &btn_onoff_rel_hos_style);
1170
if (transparent)
1171
{
1172
btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(0xFFFFFF);
1173
btn_onoff_pr_hos_style.body.opa = 35;
1174
}
1175
else
1176
btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x101010) : 0x2D2D2D);
1177
btn_onoff_pr_hos_style.body.grad_color = btn_onoff_pr_hos_style.body.main_color;
1178
btn_onoff_pr_hos_style.text.color = th->btn.pr->text.color;
1179
btn_onoff_pr_hos_style.body.empty = 0;
1180
1181
lv_obj_t *label_btn = lv_label_create(btn, NULL);
1182
lv_obj_t *label_btnsw = NULL;
1183
1184
lv_label_set_recolor(label_btn, true);
1185
label_btnsw = lv_label_create(btn, NULL);
1186
lv_label_set_recolor(label_btnsw, true);
1187
lv_btn_set_layout(btn, LV_LAYOUT_OFF);
1188
1189
lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_onoff_rel_hos_style);
1190
lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_onoff_pr_hos_style);
1191
lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, &btn_onoff_rel_hos_style);
1192
lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, &btn_onoff_pr_hos_style);
1193
1194
lv_btn_set_fit(btn, false, true);
1195
lv_obj_set_width(btn, lv_obj_get_width(parent));
1196
lv_btn_set_toggle(btn, true);
1197
1198
lv_label_set_text(label_btn, btn_name);
1199
1200
lv_label_set_text(label_btnsw, "#D0D0D0 OFF#");
1201
lv_obj_align(label_btn, btn, LV_ALIGN_IN_LEFT_MID, LV_DPI / 4, 0);
1202
lv_obj_align(label_btnsw, btn, LV_ALIGN_IN_RIGHT_MID, -LV_DPI / 4, -LV_DPI / 10);
1203
1204
if (action)
1205
lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, action);
1206
}
1207
1208
static void _create_text_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, const char *btn_name, lv_action_t action)
1209
{
1210
// Create buttons that are flat and only have a text label.
1211
static lv_style_t btn_onoff_rel_hos_style, btn_onoff_pr_hos_style;
1212
lv_style_copy(&btn_onoff_rel_hos_style, th->btn.rel);
1213
btn_onoff_rel_hos_style.body.shadow.width = 0;
1214
btn_onoff_rel_hos_style.body.border.width = 0;
1215
btn_onoff_rel_hos_style.body.radius = 0;
1216
btn_onoff_rel_hos_style.body.padding.hor = LV_DPI / 4;
1217
btn_onoff_rel_hos_style.body.empty = 1;
1218
1219
lv_style_copy(&btn_onoff_pr_hos_style, &btn_onoff_rel_hos_style);
1220
if (hekate_bg)
1221
{
1222
btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(0xFFFFFF);
1223
btn_onoff_pr_hos_style.body.opa = 35;
1224
}
1225
else
1226
btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x101010) : 0x2D2D2D);
1227
btn_onoff_pr_hos_style.body.grad_color = btn_onoff_pr_hos_style.body.main_color;
1228
btn_onoff_pr_hos_style.text.color = th->btn.pr->text.color;
1229
btn_onoff_pr_hos_style.body.empty = 0;
1230
1231
lv_obj_t *label_btn = lv_label_create(btn, NULL);
1232
1233
lv_label_set_recolor(label_btn, true);
1234
1235
lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_onoff_rel_hos_style);
1236
lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_onoff_pr_hos_style);
1237
lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, &btn_onoff_rel_hos_style);
1238
lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, &btn_onoff_pr_hos_style);
1239
1240
lv_btn_set_fit(btn, true, true);
1241
1242
lv_label_set_text(label_btn, btn_name);
1243
1244
if (action)
1245
lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, action);
1246
}
1247
1248
static void _create_tab_about(lv_theme_t * th, lv_obj_t * parent)
1249
{
1250
lv_obj_t * lbl_credits = lv_label_create(parent, NULL);
1251
1252
lv_obj_align(lbl_credits, NULL, LV_ALIGN_IN_TOP_LEFT, LV_DPI / 2, LV_DPI / 2);
1253
lv_label_set_style(lbl_credits, &monospace_text);
1254
lv_label_set_recolor(lbl_credits, true);
1255
lv_label_set_static_text(lbl_credits,
1256
"#C7EA46 hekate# (c) 2018, #C7EA46 naehrwert#, #C7EA46 st4rk#\n"
1257
" (c) 2018-2025, #C7EA46 CTCaer#\n"
1258
"\n"
1259
"#C7EA46 Nyx# (c) 2019-2025, #C7EA46 CTCaer#\n"
1260
"\n"
1261
"Thanks to: #00CCFF derrek, nedwill, plutoo, #\n"
1262
" #00CCFF shuffle2, smea, thexyz, yellows8 #\n"
1263
"\n"
1264
"Greetings to: fincs, hexkyz, SciresM,\n"
1265
" Shiny Quagsire, WinterMute\n"
1266
"\n"
1267
"Open source and free packages used: \n" // Label width alignment padding.
1268
" - Littlev Graphics Library,\n"
1269
" Copyright (c) 2016-2018, Gabor Kiss-Vamosi\n\n"
1270
" - FatFs R0.13c,\n"
1271
" Copyright (c) 2006-2018, ChaN\n"
1272
" Copyright (c) 2018-2022, CTCaer\n\n"
1273
" - bcl-1.2.0,\n"
1274
" Copyright (c) 2003-2006, Marcus Geelnard\n\n"
1275
" - blz,\n"
1276
" Copyright (c) 2018, SciresM\n\n"
1277
" - elfload,\n"
1278
" Copyright (c) 2014, Owen Shepherd\n"
1279
" Copyright (c) 2018, M4xw"
1280
);
1281
1282
lv_obj_t * lbl_octopus = lv_label_create(parent, NULL);
1283
lv_obj_align(lbl_octopus, lbl_credits, LV_ALIGN_OUT_RIGHT_TOP, -LV_DPI / 10, 0);
1284
lv_label_set_style(lbl_octopus, &monospace_text);
1285
lv_label_set_recolor(lbl_octopus, true);
1286
1287
lv_label_set_static_text(lbl_octopus,
1288
"\n#00CCFF ___#\n"
1289
"#00CCFF .-' `'.#\n"
1290
"#00CCFF / \\#\n"
1291
"#00CCFF | ;#\n"
1292
"#00CCFF | | ___.--,#\n"
1293
"#00CCFF _.._ |0) = (0) | _.---'`__.-( (_.#\n"
1294
"#00CCFF __.--'`_.. '.__.\\ '--. \\_.-' ,.--'` `\"\"`#\n"
1295
"#00CCFF ( ,.--'` ',__ /./; ;, '.__.'` __#\n"
1296
"#00CCFF _`) ) .---.__.' / | |\\ \\__..--\"\" \"\"\"--.,_#\n"
1297
"#00CCFF `---' .'.''-._.-'`_./ /\\ '. \\ _.--''````'''--._`-.__.'#\n"
1298
"#00CCFF | | .' _.-' | | \\ \\ '. `----`#\n"
1299
"#00CCFF \\ \\/ .' \\ \\ '. '-._)#\n"
1300
"#00CCFF \\/ / \\ \\ `=.__`'-.#\n"
1301
"#00CCFF / /\\ `) ) / / `\"\".`\\#\n"
1302
"#00CCFF , _.-'.'\\ \\ / / ( ( / /#\n"
1303
"#00CCFF `--'` ) ) .-'.' '.'. | (#\n"
1304
"#00CCFF (/` ( (` ) ) '-; ##00FFCC [switchbrew]#\n"
1305
"#00CCFF ` '-; (-'#"
1306
);
1307
1308
lv_obj_t *hekate_img = lv_img_create(parent, NULL);
1309
lv_img_set_src(hekate_img, &hekate_logo);
1310
lv_obj_align(hekate_img, lbl_octopus, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 2 / 3);
1311
1312
lv_obj_t *ctcaer_img = lv_img_create(parent, NULL);
1313
lv_img_set_src(ctcaer_img, &ctcaer_logo);
1314
lv_obj_align(ctcaer_img, lbl_octopus, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, LV_DPI * 2 / 3);
1315
1316
char version[32];
1317
s_printf(version, "Nyx %s%d.%d.%d%c", NYX_VER_RL ? "v" : "", NYX_VER_MJ, NYX_VER_MN, NYX_VER_HF, NYX_VER_RL > 'A' ? NYX_VER_RL : 0);
1318
lv_obj_t * lbl_ver = lv_label_create(parent, NULL);
1319
lv_obj_align(lbl_ver, ctcaer_img, LV_ALIGN_OUT_BOTTOM_RIGHT, -LV_DPI / 20, LV_DPI / 4);
1320
lv_label_set_style(lbl_ver, &monospace_text);
1321
lv_label_set_text(lbl_ver, version);
1322
}
1323
1324
static void _update_status_bar(void *params)
1325
{
1326
static char *label = NULL;
1327
1328
u16 soc_temp = 0;
1329
u32 batt_percent = 0;
1330
int charge_status = 0;
1331
int batt_volt = 0;
1332
int batt_curr = 0;
1333
rtc_time_t time;
1334
1335
// Get sensor data.
1336
max77620_rtc_get_time_adjusted(&time);
1337
soc_temp = tmp451_get_soc_temp(false);
1338
bq24193_get_property(BQ24193_ChargeStatus, &charge_status);
1339
max17050_get_property(MAX17050_RepSOC, (int *)&batt_percent);
1340
max17050_get_property(MAX17050_VCELL, &batt_volt);
1341
max17050_get_property(MAX17050_Current, &batt_curr);
1342
1343
// Enable fan if more than 41 oC.
1344
u32 soc_temp_dec = soc_temp >> 8;
1345
fan_set_from_temp(soc_temp_dec);
1346
1347
if (!label)
1348
label = (char *)malloc(512);
1349
1350
// Set time and SoC temperature.
1351
s_printf(label, "%02d:%02d "SYMBOL_DOT" "SYMBOL_TEMPERATURE" %02d.%d",
1352
time.hour, time.min, soc_temp_dec, (soc_temp & 0xFF) / 10);
1353
1354
lv_label_set_text(status_bar.time_temp, label);
1355
1356
lv_obj_realign(status_bar.temp_symbol);
1357
lv_obj_realign(status_bar.temp_degrees);
1358
1359
// Set battery percent and charging symbol.
1360
s_printf(label, " "SYMBOL_DOT" %d.%d%% ", (batt_percent >> 8) & 0xFF, (batt_percent & 0xFF) / 26);
1361
1362
u8 batt_level = (batt_percent >> 8) & 0xFF;
1363
if (batt_level > 80)
1364
strcat(label, SYMBOL_BATTERY_FULL);
1365
else if (batt_level > 60)
1366
strcat(label, SYMBOL_BATTERY_3);
1367
else if (batt_level > 40)
1368
strcat(label, SYMBOL_BATTERY_2);
1369
else if (batt_level > 15)
1370
strcat(label, SYMBOL_BATTERY_1);
1371
else
1372
strcat(label, "#FF3C28 "SYMBOL_BATTERY_EMPTY"#");
1373
1374
// Set charging symbol.
1375
if (charge_status)
1376
strcat(label, " #FFDD00 "SYMBOL_CHARGE"#");
1377
1378
lv_label_set_text(status_bar.battery, label);
1379
lv_obj_realign(status_bar.battery);
1380
1381
// Set battery current draw and voltage.
1382
s_printf(label, "#%s%d", batt_curr >= 0 ? "96FF00 +" : "FF3C28 ", batt_curr / 1000);
1383
1384
bool voltage_empty = batt_volt < 3200;
1385
s_printf(label + strlen(label), " mA# (%s%d mV%s)",
1386
voltage_empty ? "#FF8000 " : "", batt_volt, voltage_empty ? " "SYMBOL_WARNING"#" : "");
1387
1388
lv_label_set_text(status_bar.battery_more, label);
1389
lv_obj_realign(status_bar.battery_more);
1390
}
1391
1392
static lv_res_t _create_mbox_payloads(lv_obj_t *btn)
1393
{
1394
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
1395
lv_obj_set_style(dark_bg, &mbox_darken);
1396
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
1397
1398
static const char * mbox_btn_map[] = { "\251", "\222Cancel", "\251", "" };
1399
lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL);
1400
lv_mbox_set_recolor_text(mbox, true);
1401
lv_obj_set_width(mbox, LV_HOR_RES * 5 / 9);
1402
1403
lv_mbox_set_text(mbox, "Select a payload to launch:");
1404
1405
// Create a list with all found payloads.
1406
//! TODO: SHould that be tabs with buttons? + Icon support?
1407
lv_obj_t *list = lv_list_create(mbox, NULL);
1408
payload_list = list;
1409
lv_obj_set_size(list, LV_HOR_RES * 3 / 7, LV_VER_RES * 3 / 7);
1410
lv_list_set_single_mode(list, true);
1411
1412
if (!sd_mount())
1413
{
1414
lv_mbox_set_text(mbox, "#FFDD00 Failed to init SD!#");
1415
1416
goto out_end;
1417
}
1418
1419
dirlist_t *filelist = dirlist("bootloader/payloads", NULL, false, false);
1420
sd_unmount();
1421
1422
u32 i = 0;
1423
if (filelist)
1424
{
1425
while (true)
1426
{
1427
if (!filelist->name[i])
1428
break;
1429
lv_list_add(list, NULL, filelist->name[i], launch_payload);
1430
i++;
1431
}
1432
free(filelist);
1433
}
1434
1435
out_end:
1436
lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action);
1437
1438
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
1439
lv_obj_set_top(mbox, true);
1440
1441
return LV_RES_OK;
1442
}
1443
typedef struct _launch_menu_entries_t
1444
{
1445
lv_obj_t *btn[20];
1446
lv_obj_t *label[20];
1447
} launch_menu_entries_t;
1448
1449
static launch_menu_entries_t launch_ctxt;
1450
static lv_obj_t *launch_bg = NULL;
1451
static bool launch_bg_done = false;
1452
1453
static lv_res_t _launch_more_cfg_action(lv_obj_t *btn)
1454
{
1455
lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn);
1456
1457
_launch_hos(ext->idx, 1);
1458
1459
return LV_RES_OK;
1460
}
1461
1462
static lv_res_t _win_launch_close_action(lv_obj_t * btn)
1463
{
1464
// Cleanup icons.
1465
for (u32 i = 0; i < (n_cfg.entries_5_col ? 10 : 8); i++)
1466
{
1467
lv_obj_t *btns = launch_ctxt.btn[i];
1468
lv_btn_ext_t *ext = lv_obj_get_ext_attr(btns);
1469
if (ext->idx)
1470
{
1471
// This gets latest object, which is the button overlay. So iterate 2 times.
1472
lv_obj_t * img = lv_obj_get_child(btns, NULL);
1473
img = lv_obj_get_child(btns, img);
1474
1475
lv_img_dsc_t *src = (lv_img_dsc_t *)lv_img_get_src(img);
1476
1477
// Avoid freeing base icons.
1478
if ((src != icon_switch) && (src != icon_payload))
1479
free(src);
1480
}
1481
}
1482
1483
lv_obj_t * win = lv_win_get_from_btn(btn);
1484
1485
lv_obj_del(win);
1486
1487
if (n_cfg.home_screen && !launch_bg_done && hekate_bg)
1488
{
1489
lv_obj_set_opa_scale_enable(launch_bg, true);
1490
lv_obj_set_opa_scale(launch_bg, LV_OPA_TRANSP);
1491
//if (launch_bg)
1492
// lv_obj_del(launch_bg); //! TODO: Find why it hangs.
1493
launch_bg_done = true;
1494
}
1495
1496
close_btn = NULL;
1497
1498
return LV_RES_INV;
1499
}
1500
1501
static lv_obj_t *create_window_launch(const char *win_title)
1502
{
1503
static lv_style_t win_bg_style, win_header;
1504
1505
lv_style_copy(&win_bg_style, &lv_style_plain);
1506
win_bg_style.body.main_color = lv_theme_get_current()->bg->body.main_color;
1507
win_bg_style.body.grad_color = win_bg_style.body.main_color;
1508
1509
if (n_cfg.home_screen && !launch_bg_done && hekate_bg)
1510
{
1511
lv_obj_t *img = lv_img_create(lv_scr_act(), NULL);
1512
lv_img_set_src(img, hekate_bg);
1513
1514
launch_bg = img;
1515
}
1516
1517
lv_obj_t *win = lv_win_create(lv_scr_act(), NULL);
1518
lv_win_set_title(win, win_title);
1519
1520
lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES);
1521
1522
if (n_cfg.home_screen && !launch_bg_done && hekate_bg)
1523
{
1524
lv_style_copy(&win_header, lv_theme_get_current()->win.header);
1525
win_header.body.opa = LV_OPA_TRANSP;
1526
1527
win_bg_style.body.opa = LV_OPA_TRANSP;
1528
lv_win_set_style(win, LV_WIN_STYLE_HEADER, &win_header);
1529
}
1530
1531
lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style);
1532
1533
close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", _win_launch_close_action);
1534
1535
return win;
1536
}
1537
1538
static lv_res_t _launch_action(lv_obj_t *btn)
1539
{
1540
lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn);
1541
1542
_launch_hos(ext->idx, 0);
1543
1544
return LV_RES_OK;
1545
}
1546
1547
static lv_res_t logs_onoff_toggle(lv_obj_t *btn)
1548
{
1549
launch_logs_enable = !launch_logs_enable;
1550
1551
lv_obj_t *label_btn = lv_obj_get_child(btn, NULL);
1552
1553
char label_text[64];
1554
strcpy(label_text, lv_label_get_text(label_btn));
1555
label_text[strlen(label_text) - 12] = 0;
1556
1557
if (!launch_logs_enable)
1558
{
1559
strcat(label_text, "#D0D0D0 OFF#");
1560
lv_label_set_text(label_btn, label_text);
1561
}
1562
else
1563
{
1564
s_printf(label_text, "%s%s%s", label_text, text_color, " ON #");
1565
lv_label_set_text(label_btn, label_text);
1566
}
1567
1568
return LV_RES_OK;
1569
}
1570
1571
typedef struct _launch_button_pos_t
1572
{
1573
u16 btn_x;
1574
u16 btn_y;
1575
u16 lbl_x;
1576
u16 lbl_y;
1577
} launch_button_pos_t;
1578
1579
static const launch_button_pos_t launch_button_pos8[8] = {
1580
// First row.
1581
{ 19, 36, 0, 245 },
1582
{ 340, 36, 321, 245 },
1583
{ 661, 36, 642, 245 },
1584
{ 982, 36, 963, 245 },
1585
// Second row.
1586
{ 19, 313, 0, 522 },
1587
{ 340, 313, 321, 522 },
1588
{ 661, 313, 642, 522 },
1589
{ 982, 313, 963, 522 }
1590
};
1591
1592
static const launch_button_pos_t launch_button_pos10[10] = {
1593
// First row.
1594
{ 19, 36, 0, 245},
1595
{260, 36, 241, 245},
1596
{501, 36, 482, 245},
1597
{742, 36, 723, 245},
1598
{983, 36, 964, 245},
1599
// Second row.
1600
{ 19, 313, 0, 522},
1601
{260, 313, 241, 522},
1602
{501, 313, 482, 522},
1603
{742, 313, 723, 522},
1604
{983, 313, 964, 522}
1605
};
1606
1607
static lv_res_t _create_window_home_launch(lv_obj_t *btn)
1608
{
1609
const u32 max_entries = n_cfg.entries_5_col ? 10 : 8;
1610
const launch_button_pos_t *launch_button_pos = n_cfg.entries_5_col ? launch_button_pos10 : launch_button_pos8;
1611
1612
char *icon_path;
1613
1614
static lv_style_t btn_home_noborder_rel;
1615
lv_style_copy(&btn_home_noborder_rel, lv_theme_get_current()->btn.rel);
1616
btn_home_noborder_rel.body.opa = LV_OPA_0;
1617
btn_home_noborder_rel.body.border.width = 4;
1618
btn_home_noborder_rel.body.border.opa = LV_OPA_0;
1619
1620
static lv_style_t btn_home_transp_rel;
1621
lv_style_copy(&btn_home_transp_rel, lv_theme_get_current()->btn.rel);
1622
btn_home_transp_rel.body.opa = LV_OPA_0;
1623
btn_home_transp_rel.body.border.width = 4;
1624
1625
static lv_style_t btn_home_transp_pr;
1626
lv_style_copy(&btn_home_transp_pr, lv_theme_get_current()->btn.pr);
1627
btn_home_transp_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF);
1628
btn_home_transp_pr.body.grad_color = btn_home_transp_pr.body.main_color;
1629
btn_home_transp_pr.body.opa = LV_OPA_30;
1630
1631
static lv_style_t btn_label_home_transp;
1632
lv_style_copy(&btn_label_home_transp, lv_theme_get_current()->cont);
1633
btn_label_home_transp.body.opa = LV_OPA_TRANSP;
1634
1635
lv_obj_t *win;
1636
1637
bool more_cfg = false;
1638
bool combined_cfg = false;
1639
if (btn)
1640
{
1641
if (strcmp(lv_label_get_text(lv_obj_get_child(btn, NULL)) + 8,"Launch#"))
1642
more_cfg = true;
1643
}
1644
else
1645
{
1646
switch (n_cfg.home_screen)
1647
{
1648
case 1: // All configs.
1649
combined_cfg = true;
1650
break;
1651
case 3: // More configs
1652
more_cfg = true;
1653
break;
1654
}
1655
}
1656
1657
if (!btn)
1658
win = create_window_launch(SYMBOL_GPS" hekate - Launch");
1659
else if (!more_cfg)
1660
win = create_window_launch(SYMBOL_GPS" Launch");
1661
else
1662
win = create_window_launch(SYMBOL_GPS" More Configurations");
1663
1664
lv_win_add_btn(win, NULL, SYMBOL_LIST" Logs #D0D0D0 OFF#", logs_onoff_toggle);
1665
launch_logs_enable = false;
1666
1667
lv_cont_set_fit(lv_page_get_scrl(lv_win_get_content(win)), false, false);
1668
lv_page_set_scrl_height(lv_win_get_content(win), 572);
1669
1670
lv_btn_ext_t * ext;
1671
lv_obj_t *btn_boot_entry;
1672
lv_obj_t *boot_entry_lbl_cont;
1673
lv_obj_t *boot_entry_label;
1674
bool no_boot_entries = false;
1675
1676
// Create CFW buttons.
1677
// Buttons are 200 x 200 with 4 pixel borders.
1678
// Icons must be <= 192 x 192.
1679
// Create first Button.
1680
btn_boot_entry = lv_btn_create(win, NULL);
1681
launch_ctxt.btn[0] = btn_boot_entry;
1682
lv_obj_set_size(btn_boot_entry, 200, 200);
1683
lv_obj_set_pos(btn_boot_entry, launch_button_pos[0].btn_x, launch_button_pos[0].btn_y);
1684
lv_obj_set_opa_scale(btn_boot_entry, LV_OPA_0);
1685
lv_obj_set_opa_scale_enable(btn_boot_entry, true);
1686
lv_btn_set_layout(btn_boot_entry, LV_LAYOUT_OFF);
1687
1688
boot_entry_lbl_cont = lv_cont_create(win, NULL);
1689
boot_entry_label = lv_label_create(boot_entry_lbl_cont, NULL);
1690
lv_obj_set_style(boot_entry_label, &hint_small_style_white);
1691
lv_label_set_text(boot_entry_label, "");
1692
launch_ctxt.label[0] = boot_entry_label;
1693
1694
lv_cont_set_fit(boot_entry_lbl_cont, false, false);
1695
lv_cont_set_layout(boot_entry_lbl_cont, LV_LAYOUT_CENTER);
1696
lv_obj_set_size(boot_entry_lbl_cont, 238, 20);
1697
lv_obj_set_pos(boot_entry_lbl_cont, launch_button_pos[0].lbl_x, launch_button_pos[0].lbl_y);
1698
lv_obj_set_style(boot_entry_lbl_cont, &btn_label_home_transp);
1699
1700
// Create the rest of the buttons.
1701
for (u32 btn_idx = 1; btn_idx < (n_cfg.entries_5_col ? 10 : 8); btn_idx++)
1702
{
1703
btn_boot_entry = lv_btn_create(win, btn_boot_entry);
1704
launch_ctxt.btn[btn_idx] = btn_boot_entry;
1705
lv_obj_set_pos(btn_boot_entry, launch_button_pos[btn_idx].btn_x, launch_button_pos[btn_idx].btn_y);
1706
1707
boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont);
1708
boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label);
1709
lv_obj_set_pos(boot_entry_lbl_cont, launch_button_pos[btn_idx].lbl_x, launch_button_pos[btn_idx].lbl_y);
1710
launch_ctxt.label[btn_idx] = boot_entry_label;
1711
}
1712
1713
// Create colorized icon style based on its parent style.
1714
static lv_style_t img_style;
1715
lv_style_copy(&img_style, &lv_style_plain);
1716
img_style.image.color = lv_color_hsv_to_rgb(n_cfg.theme_color, 100, 100);
1717
img_style.image.intense = LV_OPA_COVER;
1718
1719
// Parse ini boot entries and set buttons/icons.
1720
char *tmp_path = malloc(1024);
1721
u32 curr_btn_idx = 0; // Active buttons.
1722
LIST_INIT(ini_sections);
1723
1724
if (!sd_mount())
1725
goto failed_sd_mount;
1726
1727
// Check if we use custom system icons.
1728
bool icon_sw_custom = !f_stat("bootloader/res/icon_switch_custom.bmp", NULL);
1729
bool icon_pl_custom = !f_stat("bootloader/res/icon_payload_custom.bmp", NULL);
1730
1731
// Choose what to parse.
1732
bool ini_parse_success = false;
1733
if (!more_cfg)
1734
ini_parse_success = ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false);
1735
else
1736
ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true);
1737
1738
if (combined_cfg && !ini_parse_success)
1739
{
1740
ini_parsing:
1741
list_init(&ini_sections);
1742
ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true);
1743
more_cfg = true;
1744
}
1745
1746
if (!ini_parse_success)
1747
goto ini_parse_failed;
1748
1749
// Iterate to all boot entries and load icons.
1750
u32 entry_idx = 1;
1751
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
1752
{
1753
if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE))
1754
continue;
1755
1756
icon_path = NULL;
1757
bool payload = false;
1758
bool img_colorize = false;
1759
bool img_noborder = false;
1760
lv_img_dsc_t *bmp = NULL;
1761
lv_obj_t *img = NULL;
1762
1763
// Check for icons.
1764
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
1765
{
1766
if (!strcmp("icon", kv->key))
1767
icon_path = kv->val;
1768
else if (!strcmp("payload", kv->key))
1769
payload = true;
1770
}
1771
1772
// If icon not found, check res folder for section_name.bmp.
1773
// If not, use defaults.
1774
if (!icon_path)
1775
{
1776
s_printf(tmp_path, "bootloader/res/%s.bmp", ini_sec->name);
1777
bmp = bmp_to_lvimg_obj(tmp_path);
1778
if (!bmp)
1779
{
1780
s_printf(tmp_path, "bootloader/res/%s_hue_nobox.bmp", ini_sec->name);
1781
bmp = bmp_to_lvimg_obj(tmp_path);
1782
if (bmp)
1783
{
1784
img_noborder = true;
1785
img_colorize = true;
1786
}
1787
if (!bmp)
1788
{
1789
s_printf(tmp_path, "bootloader/res/%s_hue.bmp", ini_sec->name);
1790
bmp = bmp_to_lvimg_obj(tmp_path);
1791
if (bmp)
1792
img_colorize = true;
1793
}
1794
if (!bmp)
1795
{
1796
s_printf(tmp_path, "bootloader/res/%s_nobox.bmp", ini_sec->name);
1797
bmp = bmp_to_lvimg_obj(tmp_path);
1798
if (bmp)
1799
img_noborder = true;
1800
}
1801
}
1802
1803
if (!bmp && payload)
1804
{
1805
bmp = icon_payload;
1806
1807
if (!icon_pl_custom)
1808
img_colorize = true;
1809
}
1810
}
1811
else
1812
{
1813
bmp = bmp_to_lvimg_obj(icon_path);
1814
1815
// Check if both colorization and border are enabled.
1816
if (bmp && strlen(icon_path) > 14 && !memcmp(icon_path + strlen(icon_path) - 14, "_hue_nobox", 10))
1817
{
1818
img_colorize = true;
1819
img_noborder = true;
1820
}
1821
else
1822
{
1823
// Check if colorization is enabled.
1824
if (bmp && strlen(icon_path) > 8 && !memcmp(icon_path + strlen(icon_path) - 8, "_hue", 4))
1825
img_colorize = true;
1826
1827
// Check if no border is enabled.
1828
if (bmp && strlen(icon_path) > 10 && !memcmp(icon_path + strlen(icon_path) - 10, "_nobox", 6))
1829
img_noborder = true;
1830
}
1831
}
1832
1833
// Enable button.
1834
lv_obj_set_opa_scale(launch_ctxt.btn[curr_btn_idx], LV_OPA_COVER);
1835
1836
// Default to switch logo if no icon found at all.
1837
if (!bmp)
1838
{
1839
bmp = icon_switch;
1840
1841
if (!icon_sw_custom)
1842
img_colorize = true;
1843
}
1844
1845
//Set icon.
1846
if (bmp)
1847
{
1848
img = lv_img_create(launch_ctxt.btn[curr_btn_idx], NULL);
1849
1850
if (img_colorize)
1851
lv_img_set_style(img, &img_style);
1852
1853
lv_img_set_src(img, bmp);
1854
}
1855
1856
// Add button mask/radius and align icon.
1857
lv_obj_t *btns = lv_btn_create(launch_ctxt.btn[curr_btn_idx], NULL);
1858
u32 btn_width = 200;
1859
u32 btn_height = 200;
1860
if (img_noborder)
1861
{
1862
btn_width = bmp->header.w + 4;
1863
btn_height = bmp->header.h + 4;
1864
1865
if (btn_width > 200)
1866
btn_width = 200;
1867
if (btn_height > 200)
1868
btn_height = 200;
1869
1870
lv_btn_set_style(launch_ctxt.btn[curr_btn_idx], LV_BTN_STYLE_REL, &btn_home_noborder_rel);
1871
lv_btn_set_style(launch_ctxt.btn[curr_btn_idx], LV_BTN_STYLE_PR, &btn_home_noborder_rel);
1872
}
1873
lv_obj_set_size(btns, btn_width, btn_height);
1874
lv_btn_set_style(btns, LV_BTN_STYLE_REL, img_noborder ? &btn_home_noborder_rel : &btn_home_transp_rel);
1875
lv_btn_set_style(btns, LV_BTN_STYLE_PR, &btn_home_transp_pr);
1876
if (img)
1877
lv_obj_align(img, NULL, LV_ALIGN_CENTER, 0, 0);
1878
if (img_noborder)
1879
lv_obj_align(btns, NULL, LV_ALIGN_CENTER, 0, 0);
1880
1881
// Set autoboot index.
1882
ext = lv_obj_get_ext_attr(btns);
1883
ext->idx = entry_idx;
1884
ext = lv_obj_get_ext_attr(launch_ctxt.btn[curr_btn_idx]); // Redundancy.
1885
ext->idx = entry_idx;
1886
1887
// Set action.
1888
if (!more_cfg)
1889
lv_btn_set_action(btns, LV_BTN_ACTION_CLICK, _launch_action);
1890
else
1891
lv_btn_set_action(btns, LV_BTN_ACTION_CLICK, _launch_more_cfg_action);
1892
1893
// Set button's label text.
1894
lv_label_set_text(launch_ctxt.label[curr_btn_idx], ini_sec->name);
1895
lv_obj_set_opa_scale(launch_ctxt.label[curr_btn_idx], LV_OPA_COVER);
1896
1897
// Set rolling text if name is big.
1898
if (strlen(ini_sec->name) > 22)
1899
lv_label_set_long_mode(launch_ctxt.label[curr_btn_idx], LV_LABEL_LONG_ROLL);
1900
1901
entry_idx++;
1902
curr_btn_idx++;
1903
1904
// Check if we exceed max buttons.
1905
if (curr_btn_idx >= max_entries)
1906
break;
1907
}
1908
1909
ini_free(&ini_sections);
1910
1911
ini_parse_failed:
1912
// Reiterate the loop with more cfgs if combined.
1913
if (combined_cfg && (curr_btn_idx < (n_cfg.entries_5_col ? 10 : 8)) && !more_cfg)
1914
goto ini_parsing;
1915
1916
failed_sd_mount:
1917
if (curr_btn_idx < 1)
1918
no_boot_entries = true;
1919
1920
sd_unmount();
1921
1922
free(tmp_path);
1923
1924
// No boot entries found.
1925
if (no_boot_entries)
1926
{
1927
lv_obj_t *label_error = lv_label_create(win, NULL);
1928
lv_label_set_recolor(label_error, true);
1929
if (!more_cfg)
1930
{
1931
lv_label_set_static_text(label_error,
1932
"#FFDD00 No main boot entries found...#\n"
1933
"Check that #96FF00 bootloader/hekate_ipl.ini# has boot entries\n"
1934
"or use #C7EA46 More configs# button for more boot entries.");
1935
}
1936
else
1937
{
1938
lv_label_set_static_text(label_error,
1939
"#FFDD00 No .ini or boot entries found...#\n"
1940
"Check that a .ini file exists in #96FF00 bootloader/ini/#\n"
1941
"and that it contains at least one entry.");
1942
}
1943
1944
lv_obj_set_pos(label_error, 19, 0);
1945
}
1946
1947
return LV_RES_OK;
1948
}
1949
1950
static void _create_tab_home(lv_theme_t *th, lv_obj_t *parent)
1951
{
1952
lv_page_set_scrl_layout(parent, LV_LAYOUT_OFF);
1953
lv_page_set_scrl_fit(parent, false, false);
1954
lv_page_set_scrl_height(parent, 592);
1955
1956
char btn_colored_text[64];
1957
1958
// Set brand label.
1959
lv_obj_t *label_brand = lv_label_create(parent, NULL);
1960
lv_label_set_recolor(label_brand, true);
1961
s_printf(btn_colored_text, "%s%s", text_color, " hekate#");
1962
lv_label_set_text(label_brand, btn_colored_text);
1963
lv_obj_set_pos(label_brand, 50, 48);
1964
1965
// Set tagline label.
1966
lv_obj_t *label_tagline = lv_label_create(parent, NULL);
1967
lv_obj_set_style(label_tagline, &hint_small_style_white);
1968
lv_label_set_static_text(label_tagline, "THE ALL IN ONE BOOTLOADER FOR ALL YOUR NEEDS");
1969
lv_obj_set_pos(label_tagline, 50, 82);
1970
1971
static lv_style_t icons;
1972
lv_style_copy(&icons, th->label.prim);
1973
icons.text.font = &hekate_symbol_120;
1974
1975
// Launch button.
1976
lv_obj_t *btn_launch = lv_btn_create(parent, NULL);
1977
if (hekate_bg)
1978
{
1979
lv_btn_set_style(btn_launch, LV_BTN_STYLE_REL, &btn_transp_rel);
1980
lv_btn_set_style(btn_launch, LV_BTN_STYLE_PR, &btn_transp_pr);
1981
}
1982
lv_obj_t *label_btn = lv_label_create(btn_launch, NULL);
1983
lv_label_set_recolor(label_btn, true);
1984
lv_obj_set_style(label_btn, &icons);
1985
s_printf(btn_colored_text, "%s%s", text_color, " "SYMBOL_DOT"#");
1986
lv_label_set_text(label_btn, btn_colored_text);
1987
lv_btn_set_action(btn_launch, LV_BTN_ACTION_CLICK, _create_window_home_launch);
1988
lv_obj_set_size(btn_launch, 256, 256);
1989
lv_obj_set_pos(btn_launch, 50, 160);
1990
lv_btn_set_layout(btn_launch, LV_LAYOUT_OFF);
1991
lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28);
1992
lv_obj_t *label_btn2 = lv_label_create(btn_launch, NULL);
1993
lv_label_set_recolor(label_btn2, true);
1994
s_printf(btn_colored_text, "%s%s", text_color, " Launch#");
1995
lv_label_set_text(label_btn2, btn_colored_text);
1996
lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174);
1997
1998
// More Configs button.
1999
lv_obj_t *btn_more_cfg = lv_btn_create(parent, btn_launch);
2000
label_btn = lv_label_create(btn_more_cfg, label_btn);
2001
s_printf(btn_colored_text, "%s%s", text_color, " "SYMBOL_CLOCK"#");
2002
lv_label_set_text(label_btn, btn_colored_text);
2003
lv_btn_set_action(btn_more_cfg, LV_BTN_ACTION_CLICK, _create_window_home_launch);
2004
lv_btn_set_layout(btn_more_cfg, LV_LAYOUT_OFF);
2005
lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28);
2006
label_btn2 = lv_label_create(btn_more_cfg, label_btn2);
2007
s_printf(btn_colored_text, "%s%s", text_color, " More Configs#");
2008
lv_label_set_text(label_btn2, btn_colored_text);
2009
lv_obj_set_pos(btn_more_cfg, 341, 160);
2010
lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174);
2011
2012
// Quick Launch button.
2013
// lv_obj_t *btn_quick_launch = lv_btn_create(parent, NULL);
2014
// lv_obj_t *label_quick_launch = lv_label_create(btn_quick_launch, NULL);
2015
// lv_label_set_static_text(label_quick_launch, SYMBOL_EDIT" Quick Launch");
2016
// lv_obj_set_width(btn_quick_launch, 256);
2017
// lv_obj_set_pos(btn_quick_launch, 343, 448);
2018
// lv_btn_set_action(btn_quick_launch, LV_BTN_ACTION_CLICK, NULL);
2019
2020
lv_obj_t *btn_nyx_options = lv_btn_create(parent, NULL);
2021
_create_text_button(th, NULL, btn_nyx_options, SYMBOL_SETTINGS" Nyx Settings", NULL);
2022
//lv_obj_set_width(btn_nyx_options, 256);
2023
lv_btn_set_action(btn_nyx_options, LV_BTN_ACTION_CLICK, create_win_nyx_options);
2024
lv_obj_align(btn_nyx_options, NULL, LV_ALIGN_IN_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI / 12);
2025
2026
// Payloads button.
2027
lv_obj_t *btn_payloads = lv_btn_create(parent, btn_launch);
2028
label_btn = lv_label_create(btn_payloads, label_btn);
2029
s_printf(btn_colored_text, "%s%s", text_color, " "SYMBOL_OK"#");
2030
lv_label_set_text(label_btn, btn_colored_text);
2031
lv_btn_set_action(btn_payloads, LV_BTN_ACTION_CLICK, _create_mbox_payloads);
2032
lv_btn_set_layout(btn_payloads, LV_LAYOUT_OFF);
2033
lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28);
2034
label_btn2 = lv_label_create(btn_payloads, label_btn2);
2035
s_printf(btn_colored_text, "%s%s", text_color, " Payloads#");
2036
lv_label_set_text(label_btn2, btn_colored_text);
2037
lv_obj_set_pos(btn_payloads, 632, 160);
2038
lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174);
2039
2040
lv_obj_t *line_sep = lv_line_create(parent, NULL);
2041
static const lv_point_t line_pp[] = { {0, 0}, {0, LV_DPI * 3} };
2042
lv_line_set_points(line_sep, line_pp, 2);
2043
lv_line_set_style(line_sep, th->line.decor);
2044
lv_obj_align(line_sep, btn_payloads, LV_ALIGN_OUT_RIGHT_MID, 35, 0);
2045
2046
// emuMMC manage button.
2047
lv_obj_t *btn_emummc = lv_btn_create(parent, btn_launch);
2048
label_btn = lv_label_create(btn_emummc, label_btn);
2049
s_printf(btn_colored_text, "%s%s", text_color, " "SYMBOL_LIST"#");
2050
lv_label_set_text(label_btn, btn_colored_text);
2051
lv_btn_set_action(btn_emummc, LV_BTN_ACTION_CLICK, create_win_emummc_tools);
2052
lv_btn_set_layout(btn_emummc, LV_LAYOUT_OFF);
2053
lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28);
2054
lv_obj_set_pos(btn_emummc, 959, 160);
2055
label_btn2 = lv_label_create(btn_emummc, label_btn2);
2056
s_printf(btn_colored_text, "%s%s", text_color, " emuMMC#");
2057
lv_label_set_text(label_btn2, btn_colored_text);
2058
lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174);
2059
2060
// Create bottom right power buttons.
2061
lv_obj_t *btn_reboot = lv_btn_create(parent, NULL);
2062
lv_obj_t *btn_power_off = lv_btn_create(parent, NULL);
2063
lv_obj_t *btn_reload = lv_btn_create(parent, NULL);
2064
2065
_create_text_button(th, NULL, btn_power_off, SYMBOL_POWER" Power Off", _create_mbox_poweroff);
2066
lv_obj_align(btn_power_off, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -LV_DPI / 4, -LV_DPI / 12);
2067
2068
_create_text_button(th, NULL, btn_reboot, SYMBOL_REBOOT" Reboot", _create_mbox_reboot);
2069
lv_obj_align(btn_reboot, btn_power_off, LV_ALIGN_OUT_LEFT_MID, 0, 0);
2070
2071
_create_text_button(th, NULL, btn_reload, SYMBOL_REFRESH" Reload", _create_mbox_reload);
2072
lv_obj_align(btn_reload, btn_reboot, LV_ALIGN_OUT_LEFT_MID, 0, 0);
2073
}
2074
2075
static lv_res_t _save_options_action(lv_obj_t *btn)
2076
{
2077
static const char * mbox_btn_map[] = {"\251", "\222OK!", "\251", ""};
2078
lv_obj_t * mbox = lv_mbox_create(lv_scr_act(), NULL);
2079
lv_mbox_set_recolor_text(mbox, true);
2080
2081
int res = 0;
2082
2083
if (sd_mount())
2084
res = !create_config_entry();
2085
2086
if (res)
2087
lv_mbox_set_text(mbox, "#FF8000 hekate Configuration#\n\n#96FF00 The configuration was saved to sd card!#");
2088
else
2089
lv_mbox_set_text(mbox, "#FF8000 hekate Configuration#\n\n#FFDD00 Failed to save the configuration#\n#FFDD00 to sd card!#");
2090
lv_mbox_add_btns(mbox, mbox_btn_map, NULL);
2091
lv_obj_set_top(mbox, true);
2092
2093
nyx_options_clear_ini_changes_made();
2094
2095
sd_unmount();
2096
2097
return LV_RES_OK;
2098
}
2099
2100
static void _create_status_bar(lv_theme_t * th)
2101
{
2102
static lv_obj_t *status_bar_bg;
2103
status_bar_bg = lv_cont_create(lv_layer_top(), NULL);
2104
status_bar.bar_bg = status_bar_bg;
2105
2106
static lv_style_t status_bar_style;
2107
lv_style_copy(&status_bar_style, &lv_style_plain_color);
2108
status_bar_style.body.opa = LV_OPA_0;
2109
status_bar_style.body.shadow.width = 0;
2110
2111
lv_obj_set_style(status_bar_bg, &status_bar_style);
2112
lv_obj_set_size(status_bar_bg, LV_HOR_RES, LV_DPI * 9 / 14);
2113
lv_obj_align(status_bar_bg, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
2114
2115
// Battery percentages.
2116
lv_obj_t *lbl_battery = lv_label_create(status_bar_bg, NULL);
2117
lv_label_set_recolor(lbl_battery, true);
2118
lv_label_set_text(lbl_battery, " "SYMBOL_DOT" 00.0% "SYMBOL_BATTERY_1" #FFDD00 "SYMBOL_CHARGE"#");
2119
lv_obj_align(lbl_battery, NULL, LV_ALIGN_IN_RIGHT_MID, -LV_DPI * 6 / 11, 0);
2120
status_bar.battery = lbl_battery;
2121
2122
// Amperages, voltages.
2123
lbl_battery = lv_label_create(status_bar_bg, lbl_battery);
2124
lv_obj_set_style(lbl_battery, &hint_small_style_white);
2125
lv_label_set_text(lbl_battery, "#96FF00 +0 mA# (0 mV)");
2126
lv_obj_align(lbl_battery, status_bar.battery, LV_ALIGN_OUT_LEFT_MID, -LV_DPI / 25, -1);
2127
status_bar.battery_more = lbl_battery;
2128
2129
lv_obj_t *lbl_left = lv_label_create(status_bar_bg, NULL);
2130
lv_label_set_text(lbl_left, SYMBOL_CLOCK" ");
2131
lv_obj_align(lbl_left, NULL, LV_ALIGN_IN_LEFT_MID, LV_DPI * 6 / 11, 0);
2132
2133
// Time, temperature.
2134
lv_obj_t *lbl_time_temp = lv_label_create(status_bar_bg, NULL);
2135
lv_label_set_text(lbl_time_temp, "00:00 "SYMBOL_DOT" "SYMBOL_TEMPERATURE" 00.0");
2136
lv_obj_align(lbl_time_temp, lbl_left, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
2137
status_bar.time_temp = lbl_time_temp;
2138
2139
lbl_left = lv_label_create(status_bar_bg, NULL);
2140
lv_label_set_text(lbl_left, " "SYMBOL_DOT);
2141
lv_obj_align(lbl_left, lbl_time_temp, LV_ALIGN_OUT_RIGHT_MID, 0, -LV_DPI / 14);
2142
status_bar.temp_symbol = lbl_left;
2143
2144
lv_obj_t *lbl_degrees = lv_label_create(status_bar_bg, NULL);
2145
lv_label_set_text(lbl_degrees, "C");
2146
lv_obj_align(lbl_degrees, lbl_left, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 50, LV_DPI / 14);
2147
status_bar.temp_degrees = lbl_degrees;
2148
2149
// Middle button.
2150
//! TODO: Utilize it for more.
2151
lv_obj_t *btn_mid = lv_btn_create(status_bar_bg, NULL);
2152
lv_obj_t *lbl_mid = lv_label_create(btn_mid, NULL);
2153
lv_label_set_static_text(lbl_mid, "Save Options");
2154
lv_obj_set_size(btn_mid, LV_DPI * 5 / 2, LV_DPI / 2);
2155
lv_obj_align(btn_mid, NULL, LV_ALIGN_CENTER, 0, 0);
2156
status_bar.mid = btn_mid;
2157
lv_obj_set_opa_scale(btn_mid, LV_OPA_0);
2158
lv_obj_set_opa_scale_enable(btn_mid, true);
2159
lv_obj_set_click(btn_mid, false);
2160
lv_btn_set_action(btn_mid, LV_BTN_ACTION_CLICK, _save_options_action);
2161
}
2162
2163
static lv_res_t _create_mbox_save_changes_action(lv_obj_t *btns, const char * txt)
2164
{
2165
int btn_idx = lv_btnm_get_pressed(btns);
2166
2167
mbox_action(btns, txt);
2168
2169
if (!btn_idx)
2170
_save_options_action(NULL);
2171
2172
return LV_RES_INV;
2173
}
2174
2175
void nyx_check_ini_changes()
2176
{
2177
if (nyx_options_get_ini_changes_made())
2178
{
2179
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
2180
lv_obj_set_style(dark_bg, &mbox_darken);
2181
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
2182
2183
static const char * mbox_btn_map[] = { "\222Save", "\222Cancel", "" };
2184
lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL);
2185
lv_mbox_set_recolor_text(mbox, true);
2186
2187
lv_mbox_set_text(mbox,
2188
"#FF8000 Main configuration#\n\n"
2189
"You changed the configuration!\n\n"
2190
"Do you want to save it?");
2191
2192
lv_mbox_add_btns(mbox, mbox_btn_map, _create_mbox_save_changes_action);
2193
lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5);
2194
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
2195
lv_obj_set_top(mbox, true);
2196
2197
nyx_options_clear_ini_changes_made();
2198
}
2199
}
2200
2201
static lv_res_t _show_hide_save_button(lv_obj_t *tv, uint16_t tab_idx)
2202
{
2203
if (tab_idx == 4) // Options.
2204
{
2205
lv_btn_set_action(status_bar.mid, LV_BTN_ACTION_CLICK, _save_options_action);
2206
lv_obj_set_opa_scale(status_bar.mid, LV_OPA_COVER);
2207
lv_obj_set_click(status_bar.mid, true);
2208
}
2209
else
2210
{
2211
lv_obj_set_opa_scale(status_bar.mid, LV_OPA_0);
2212
lv_obj_set_click(status_bar.mid, false);
2213
}
2214
2215
nyx_check_ini_changes();
2216
2217
return LV_RES_OK;
2218
}
2219
2220
static void _nyx_set_default_styles(lv_theme_t * th)
2221
{
2222
lv_style_copy(&mbox_darken, &lv_style_plain);
2223
mbox_darken.body.main_color = LV_COLOR_BLACK;
2224
mbox_darken.body.grad_color = mbox_darken.body.main_color;
2225
mbox_darken.body.opa = LV_OPA_30;
2226
2227
lv_style_copy(&hint_small_style, th->label.hint);
2228
hint_small_style.text.letter_space = 1;
2229
hint_small_style.text.font = &interui_20;
2230
2231
lv_style_copy(&hint_small_style_white, th->label.prim);
2232
hint_small_style_white.text.letter_space = 1;
2233
hint_small_style_white.text.font = &interui_20;
2234
2235
lv_style_copy(&monospace_text, &lv_style_plain);
2236
monospace_text.body.main_color = LV_COLOR_HEX(0x1B1B1B);
2237
monospace_text.body.grad_color = LV_COLOR_HEX(0x1B1B1B);
2238
monospace_text.body.border.color = LV_COLOR_HEX(0x1B1B1B);
2239
monospace_text.body.border.width = 0;
2240
monospace_text.body.opa = LV_OPA_TRANSP;
2241
monospace_text.text.color = LV_COLOR_HEX(0xD8D8D8);
2242
monospace_text.text.font = &ubuntu_mono;
2243
monospace_text.text.letter_space = 0;
2244
monospace_text.text.line_space = 0;
2245
2246
lv_style_copy(&btn_transp_rel, th->btn.rel);
2247
btn_transp_rel.body.main_color = LV_COLOR_HEX(0x444444);
2248
btn_transp_rel.body.grad_color = btn_transp_rel.body.main_color;
2249
btn_transp_rel.body.opa = LV_OPA_50;
2250
2251
lv_style_copy(&btn_transp_pr, th->btn.pr);
2252
btn_transp_pr.body.main_color = LV_COLOR_HEX(0x888888);
2253
btn_transp_pr.body.grad_color = btn_transp_pr.body.main_color;
2254
btn_transp_pr.body.opa = LV_OPA_50;
2255
2256
lv_style_copy(&btn_transp_tgl_rel, th->btn.tgl_rel);
2257
btn_transp_tgl_rel.body.main_color = LV_COLOR_HEX(0x444444);
2258
btn_transp_tgl_rel.body.grad_color = btn_transp_tgl_rel.body.main_color;
2259
btn_transp_tgl_rel.body.opa = LV_OPA_50;
2260
2261
lv_style_copy(&btn_transp_tgl_pr, th->btn.tgl_pr);
2262
btn_transp_tgl_pr.body.main_color = LV_COLOR_HEX(0x888888);
2263
btn_transp_tgl_pr.body.grad_color = btn_transp_tgl_pr.body.main_color;
2264
btn_transp_tgl_pr.body.opa = LV_OPA_50;
2265
2266
lv_style_copy(&ddlist_transp_bg, th->ddlist.bg);
2267
ddlist_transp_bg.body.main_color = LV_COLOR_HEX(0x2D2D2D);
2268
ddlist_transp_bg.body.grad_color = ddlist_transp_bg.body.main_color;
2269
ddlist_transp_bg.body.opa = 180;
2270
2271
lv_style_copy(&ddlist_transp_sel, th->ddlist.sel);
2272
ddlist_transp_sel.body.main_color = LV_COLOR_HEX(0x4D4D4D);
2273
ddlist_transp_sel.body.grad_color = ddlist_transp_sel.body.main_color;
2274
ddlist_transp_sel.body.opa = 180;
2275
2276
lv_style_copy(&tabview_btn_pr, th->tabview.btn.pr);
2277
tabview_btn_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF);
2278
tabview_btn_pr.body.grad_color = tabview_btn_pr.body.main_color;
2279
tabview_btn_pr.body.opa = 35;
2280
2281
lv_style_copy(&tabview_btn_tgl_pr, th->tabview.btn.tgl_pr);
2282
tabview_btn_tgl_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF);
2283
tabview_btn_tgl_pr.body.grad_color = tabview_btn_tgl_pr.body.main_color;
2284
tabview_btn_tgl_pr.body.opa = 35;
2285
2286
lv_color_t tmp_color = lv_color_hsv_to_rgb(n_cfg.theme_color, 100, 100);
2287
text_color = malloc(32);
2288
s_printf(text_color, "#%06X", (u32)(tmp_color.full & 0xFFFFFF));
2289
}
2290
2291
lv_task_t *task_bpmp_clock;
2292
void first_time_bpmp_clock(void *param)
2293
{
2294
// Remove task.
2295
lv_task_del(task_bpmp_clock);
2296
2297
// Max clock seems fine. Save it.
2298
n_cfg.bpmp_clock = 1;
2299
create_nyx_config_entry(false);
2300
}
2301
2302
static void _nyx_main_menu(lv_theme_t * th)
2303
{
2304
static lv_style_t no_padding;
2305
lv_style_copy(&no_padding, &lv_style_transp);
2306
no_padding.body.padding.hor = 0;
2307
2308
// Initialize global styles.
2309
_nyx_set_default_styles(th);
2310
2311
// Create screen container.
2312
lv_obj_t *scr = lv_cont_create(NULL, NULL);
2313
lv_scr_load(scr);
2314
lv_cont_set_style(scr, th->bg);
2315
2316
// Create base background and add a custom one if exists.
2317
lv_obj_t *cnr = lv_cont_create(scr, NULL);
2318
static lv_style_t base_bg_style;
2319
lv_style_copy(&base_bg_style, &lv_style_plain_color);
2320
base_bg_style.body.main_color = th->bg->body.main_color;
2321
base_bg_style.body.grad_color = base_bg_style.body.main_color;
2322
lv_cont_set_style(cnr, &base_bg_style);
2323
lv_obj_set_size(cnr, LV_HOR_RES, LV_VER_RES);
2324
2325
if (hekate_bg)
2326
{
2327
lv_obj_t *img = lv_img_create(cnr, NULL);
2328
lv_img_set_src(img, hekate_bg);
2329
}
2330
2331
// Add tabview page to screen.
2332
lv_obj_t *tv = lv_tabview_create(scr, NULL);
2333
if (hekate_bg)
2334
{
2335
lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_PR, &tabview_btn_pr);
2336
lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_TGL_PR, &tabview_btn_tgl_pr);
2337
}
2338
lv_tabview_set_sliding(tv, false);
2339
lv_obj_set_size(tv, LV_HOR_RES, LV_VER_RES);
2340
2341
// Add all tabs content.
2342
char version[32];
2343
char rel = (nyx_str->version >> 24) & 0xFF;
2344
s_printf(version, "hekate %s%d.%d.%d%c",
2345
rel ? "v" : "", nyx_str->version & 0xFF, (nyx_str->version >> 8) & 0xFF, (nyx_str->version >> 16) & 0xFF, rel > 'A' ? rel : 0);
2346
lv_obj_t *tab_about = lv_tabview_add_tab(tv, version);
2347
2348
lv_obj_t *tab_home = lv_tabview_add_tab(tv, SYMBOL_HOME" Home");
2349
2350
lv_obj_t *tab_tools = lv_tabview_add_tab(tv, SYMBOL_TOOLS" Tools");
2351
lv_page_set_style(tab_tools, LV_PAGE_STYLE_BG, &no_padding);
2352
lv_page_set_style(tab_tools, LV_PAGE_STYLE_SCRL, &no_padding);
2353
2354
lv_obj_t *tab_info = lv_tabview_add_tab(tv, SYMBOL_INFO" Console Info");
2355
lv_page_set_style(tab_info, LV_PAGE_STYLE_BG, &no_padding);
2356
lv_page_set_style(tab_info, LV_PAGE_STYLE_SCRL, &no_padding);
2357
2358
lv_obj_t *tab_options = lv_tabview_add_tab(tv, SYMBOL_SETTINGS" Options");
2359
2360
_create_tab_about(th, tab_about);
2361
_create_tab_home(th, tab_home);
2362
create_tab_tools(th, tab_tools);
2363
create_tab_info(th, tab_info);
2364
create_tab_options(th, tab_options);
2365
2366
lv_tabview_set_tab_act(tv, 1, false);
2367
2368
// Create status bar.
2369
_create_status_bar(th);
2370
2371
// Create tasks.
2372
system_tasks.task.dram_periodic_comp = lv_task_create(minerva_periodic_training, EMC_PERIODIC_TRAIN_MS, LV_TASK_PRIO_HIGHEST, NULL);
2373
lv_task_ready(system_tasks.task.dram_periodic_comp);
2374
2375
system_tasks.task.status_bar = lv_task_create(_update_status_bar, 5000, LV_TASK_PRIO_LOW, NULL);
2376
lv_task_ready(system_tasks.task.status_bar);
2377
2378
lv_task_create(_check_sd_card_removed, 2000, LV_TASK_PRIO_LOWEST, NULL);
2379
2380
task_emmc_errors = lv_task_create(_nyx_emmc_issues_warning, 2000, LV_TASK_PRIO_LOWEST, NULL);
2381
lv_task_ready(task_emmc_errors);
2382
2383
// Create top level global line separators.
2384
lv_obj_t *line = lv_cont_create(lv_layer_top(), NULL);
2385
2386
static lv_style_t line_style;
2387
lv_style_copy(&line_style, &lv_style_plain_color);
2388
2389
line_style.body.main_color = LV_COLOR_HEX(0xDDDDDD); // 0x505050
2390
line_style.body.grad_color = line_style.body.main_color;
2391
line_style.body.shadow.width = 0;
2392
2393
lv_cont_set_style(line, &line_style);
2394
lv_obj_set_size(line, LV_HOR_RES - LV_DPI * 3 / 5, 1);
2395
lv_obj_set_pos(line, LV_DPI * 3 / 10, 63);
2396
2397
lv_obj_set_top(line, true);
2398
2399
line = lv_cont_create(lv_layer_top(), line);
2400
lv_obj_set_pos(line, LV_DPI * 3 / 10, 656);
2401
lv_obj_set_top(line, true);
2402
2403
// Option save button.
2404
lv_tabview_set_tab_load_action(tv, _show_hide_save_button);
2405
2406
// Check if Nyx was launched with a function set.
2407
if (nyx_str->cfg & NYX_CFG_UMS)
2408
{
2409
nyx_str->cfg &= ~(NYX_CFG_UMS);
2410
lv_task_t *task_run_ums = lv_task_create(nyx_run_ums, LV_TASK_ONESHOT, LV_TASK_PRIO_LOWEST, (void *)&nyx_str->cfg);
2411
lv_task_once(task_run_ums);
2412
}
2413
else if (n_cfg.home_screen)
2414
_create_window_home_launch(NULL);
2415
2416
if (!n_cfg.timeoff)
2417
{
2418
lv_task_t *task_run_clock = lv_task_create(first_time_clock_edit, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, NULL);
2419
lv_task_once(task_run_clock);
2420
}
2421
2422
if (!n_cfg.bpmp_clock)
2423
task_bpmp_clock = lv_task_create(first_time_bpmp_clock, 10000, LV_TASK_PRIO_LOWEST, NULL);
2424
}
2425
2426
void nyx_load_and_run()
2427
{
2428
memset(&system_tasks, 0, sizeof(system_maintenance_tasks_t));
2429
2430
lv_init();
2431
gfx_con.fillbg = 1;
2432
2433
// Initialize framebuffer drawing functions.
2434
lv_disp_drv_t disp_drv;
2435
lv_disp_drv_init(&disp_drv);
2436
disp_drv.disp_flush = _disp_fb_flush;
2437
lv_disp_drv_register(&disp_drv);
2438
2439
// Initialize Joy-Con.
2440
if (!n_cfg.jc_disable)
2441
{
2442
lv_task_t *task_jc_init_hw = lv_task_create(jc_init_hw, LV_TASK_ONESHOT, LV_TASK_PRIO_LOWEST, NULL);
2443
lv_task_once(task_jc_init_hw);
2444
}
2445
lv_indev_drv_t indev_drv_jc;
2446
lv_indev_drv_init(&indev_drv_jc);
2447
indev_drv_jc.type = LV_INDEV_TYPE_POINTER;
2448
indev_drv_jc.read = _jc_virt_mouse_read;
2449
memset(&jc_drv_ctx, 0, sizeof(jc_lv_driver_t));
2450
jc_drv_ctx.indev_jc = lv_indev_drv_register(&indev_drv_jc);
2451
close_btn = NULL;
2452
2453
// Initialize touch.
2454
touch_enabled = touch_power_on();
2455
lv_indev_drv_t indev_drv_touch;
2456
lv_indev_drv_init(&indev_drv_touch);
2457
indev_drv_touch.type = LV_INDEV_TYPE_POINTER;
2458
indev_drv_touch.read = _fts_touch_read;
2459
jc_drv_ctx.indev_touch = lv_indev_drv_register(&indev_drv_touch);
2460
touchpad.touch = false;
2461
2462
// Initialize temperature sensor.
2463
tmp451_init();
2464
2465
// Set hekate theme based on chosen hue.
2466
lv_theme_t *th = lv_theme_hekate_init(n_cfg.theme_bg, n_cfg.theme_color, NULL);
2467
lv_theme_set_current(th);
2468
2469
// Create main menu
2470
_nyx_main_menu(th);
2471
2472
jc_drv_ctx.cursor = lv_img_create(lv_scr_act(), NULL);
2473
lv_img_set_src(jc_drv_ctx.cursor, &touch_cursor);
2474
lv_obj_set_opa_scale(jc_drv_ctx.cursor, LV_OPA_TRANSP);
2475
lv_obj_set_opa_scale_enable(jc_drv_ctx.cursor, true);
2476
2477
// Check if sd card issues.
2478
if (sd_get_mode() == SD_1BIT_HS25)
2479
{
2480
lv_task_t *task_run_sd_errors = lv_task_create(_nyx_sd_card_issues_warning, LV_TASK_ONESHOT, LV_TASK_PRIO_LOWEST, NULL);
2481
lv_task_once(task_run_sd_errors);
2482
}
2483
2484
// Gui loop.
2485
if (h_cfg.t210b01)
2486
{
2487
// Minerva not supported on T210B01 yet. Slight power saving via spinlock.
2488
while (true)
2489
{
2490
lv_task_handler();
2491
usleep(400);
2492
}
2493
}
2494
else
2495
{
2496
// Alternate DRAM frequencies. Saves 280 mW.
2497
while (true)
2498
{
2499
minerva_change_freq(FREQ_1600); // Takes 295 us.
2500
2501
lv_task_handler();
2502
2503
minerva_change_freq(FREQ_800); // Takes 80 us.
2504
}
2505
}
2506
}
2507
2508