From 75993938d0d2da8cb5608760fbed5d5cdb20cc60 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Fri, 8 Aug 2025 14:54:58 +0300 Subject: [PATCH] nyx: invalidate time and add dst support The invalidation is needed for dst to work as we don't know when user set the clock. --- nyx/nyx_gui/config.c | 15 ++++++--- nyx/nyx_gui/config.h | 5 +-- nyx/nyx_gui/frontend/gui.c | 3 +- nyx/nyx_gui/frontend/gui_options.c | 52 +++++++++++++++++++++++++++--- nyx/nyx_gui/nyx.c | 23 ++++++++++--- 5 files changed, 81 insertions(+), 17 deletions(-) diff --git a/nyx/nyx_gui/config.c b/nyx/nyx_gui/config.c index b70d4375..b4e6f27a 100644 --- a/nyx/nyx_gui/config.c +++ b/nyx/nyx_gui/config.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023 CTCaer + * Copyright (c) 2018-2025 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -32,7 +32,7 @@ void set_default_configuration() h_cfg.autoboot = 0; h_cfg.autoboot_list = 0; h_cfg.bootwait = 3; - h_cfg.noticker = 0; + h_cfg.noticker = 0; //! TODO: Add GUI option. h_cfg.backlight = 100; h_cfg.autohosoff = h_cfg.t210b01 ? 1 : 0; h_cfg.autonogc = 1; @@ -53,7 +53,8 @@ void set_nyx_default_configuration() n_cfg.theme_bg = 0x2D2D2D; n_cfg.theme_color = 167; n_cfg.entries_5_col = 0; - n_cfg.timeoff = 0; + n_cfg.timeoffset = 0; + n_cfg.timedst = 1; n_cfg.home_screen = 0; n_cfg.verification = 1; n_cfg.ums_emmc_rw = 0; @@ -214,8 +215,12 @@ int create_nyx_config_entry(bool force_unmount) itoa(n_cfg.entries_5_col, lbuf, 10); f_puts(lbuf, &fp); - f_puts("\ntimeoff=", &fp); - itoa(n_cfg.timeoff, lbuf, 16); + f_puts("\ntimeoffset=", &fp); + itoa(n_cfg.timeoffset, lbuf, 16); + f_puts(lbuf, &fp); + + f_puts("\ntimedst=", &fp); + itoa(n_cfg.timedst, lbuf, 10); f_puts(lbuf, &fp); f_puts("\nhomescreen=", &fp); diff --git a/nyx/nyx_gui/config.h b/nyx/nyx_gui/config.h index d2076e87..77ee3c54 100644 --- a/nyx/nyx_gui/config.h +++ b/nyx/nyx_gui/config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023 CTCaer + * Copyright (c) 2018-2025 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -47,7 +47,8 @@ typedef struct _nyx_config u32 theme_bg; u32 theme_color; u32 entries_5_col; - u32 timeoff; + u32 timeoffset; + u32 timedst; u32 home_screen; u32 verification; u32 ums_emmc_rw; diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 47bef3bd..d714643d 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -112,6 +112,7 @@ static void _nyx_disp_init() // Enable logging on window D. display_init_window_d_console(); + // Switch back the backlight. display_backlight_brightness(h_cfg.backlight - 20, 1000); } @@ -2413,7 +2414,7 @@ static void _nyx_main_menu(lv_theme_t * th) else if (n_cfg.home_screen) _create_window_home_launch(NULL); - if (!n_cfg.timeoff) + if (!n_cfg.timeoffset) { lv_task_t *task_run_clock = lv_task_create(first_time_clock_edit, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, NULL); lv_task_once(task_run_clock); diff --git a/nyx/nyx_gui/frontend/gui_options.c b/nyx/nyx_gui/frontend/gui_options.c index 15feeacf..58269d34 100644 --- a/nyx/nyx_gui/frontend/gui_options.c +++ b/nyx/nyx_gui/frontend/gui_options.c @@ -707,13 +707,20 @@ static lv_res_t _action_clock_edit(lv_obj_t *btns, const char * txt) u32 new_epoch = max77620_rtc_date_to_epoch(&time); // Stored in u32 and allow overflow for integer offset casting. - n_cfg.timeoff = new_epoch - epoch; + n_cfg.timeoffset = new_epoch - epoch; // If canceled set 1 for invalidating first boot clock edit. - if (!n_cfg.timeoff) - n_cfg.timeoff = 1; + if (!n_cfg.timeoffset) + n_cfg.timeoffset = 1; else - max77620_rtc_set_epoch_offset((int)n_cfg.timeoff); + { + // Adjust for DST between 28 march and 28 october. + // Good enough to cover all years as week info is not valid. + u16 md = (time.month << 8) | time.day; + if (n_cfg.timedst && md >= 0x31C && md < 0xA1C) + n_cfg.timeoffset -= 3600; // Store time in non DST. + max77620_rtc_set_epoch_offset((int)n_cfg.timeoffset); + } nyx_changes_made = true; } @@ -734,18 +741,46 @@ static lv_res_t _action_clock_edit_save(lv_obj_t *btns, const char * txt) return LV_RES_INV; } +static lv_res_t _action_auto_dst_toggle(lv_obj_t *btn) +{ + n_cfg.timedst = !n_cfg.timedst; + max77620_rtc_set_auto_dst(n_cfg.timedst); + + if (!n_cfg.timedst) + lv_btn_set_state(btn, LV_BTN_STATE_REL); + else + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + + nyx_generic_onoff_toggle(btn); + + return LV_RES_OK; +} + static lv_res_t _create_mbox_clock_edit(lv_obj_t *btn) { + static lv_style_t mbox_style; + lv_theme_t *th = lv_theme_get_current(); + lv_style_copy(&mbox_style, th->mbox.bg); + mbox_style.body.padding.inner = LV_DPI / 10; + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); static const char *mbox_btn_map[] = { "\251", "\222Done", "\222Cancel", "\251", "" }; lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BG, &mbox_style); lv_mbox_set_recolor_text(mbox, true); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 6); - lv_mbox_set_text(mbox, "Enter #C7EA46 Date# and #C7EA46 Time# for Nyx\nThis will not alter the actual HW clock!"); + lv_mbox_set_text(mbox, "Enter #C7EA46 Date# and #C7EA46 Time# for Nyx\n" + "Used in all file operations and menu.\n" + "This doesn't alter the actual HW clock!"); + + lv_obj_t *padding = lv_cont_create(mbox, NULL); + lv_cont_set_fit(padding, true, false); + lv_cont_set_style(padding, &lv_style_transp); + lv_obj_set_height(padding, LV_DPI / 10); // Get current time. rtc_time_t time; @@ -824,6 +859,13 @@ static lv_res_t _create_mbox_clock_edit(lv_obj_t *btn) lv_obj_align(roller_minute, roller_hour, LV_ALIGN_OUT_RIGHT_MID, 0, 0); clock_ctxt.min = roller_minute; + // Add DST option. + lv_obj_t *btn_dst = lv_btn_create(mbox, NULL); + nyx_create_onoff_button(th, h1, btn_dst, SYMBOL_BRIGHTNESS" Auto Daylight Saving Time", _action_auto_dst_toggle, true); + if (n_cfg.timedst) + lv_btn_set_state(btn_dst, LV_BTN_STATE_TGL_REL); + nyx_generic_onoff_toggle(btn_dst); + // If btn is empty, save options also because it was launched from boot. lv_mbox_add_btns(mbox, mbox_btn_map, btn ? _action_clock_edit : _action_clock_edit_save); diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index 05275a2d..40c732f9 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018 naehrwert * - * Copyright (c) 2018-2023 CTCaer + * Copyright (c) 2018-2025 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -260,6 +260,7 @@ skip_main_cfg_parse: // Only parse config section. if (ini_sec->type == INI_CHOICE && !strcmp(ini_sec->name, "config")) { + bool time_old_raw = false; LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) { if (!strcmp("themebg", kv->key)) @@ -268,12 +269,19 @@ skip_main_cfg_parse: n_cfg.theme_color = atoi(kv->val); else if (!strcmp("entries5col", kv->key)) n_cfg.entries_5_col = atoi(kv->val) == 1; + else if (!strcmp("timeoffset", kv->key)) + { + n_cfg.timeoffset = strtol(kv->val, NULL, 16); + if (n_cfg.timeoffset != 1) + max77620_rtc_set_epoch_offset((int)n_cfg.timeoffset); + } else if (!strcmp("timeoff", kv->key)) { - n_cfg.timeoff = strtol(kv->val, NULL, 16); - if (n_cfg.timeoff != 1) - max77620_rtc_set_epoch_offset((int)n_cfg.timeoff); + if (strtol(kv->val, NULL, 16) == 1) + time_old_raw = true; } + else if (!strcmp("timedst", kv->key)) + n_cfg.timedst = atoi(kv->val); else if (!strcmp("homescreen", kv->key)) n_cfg.home_screen = atoi(kv->val); else if (!strcmp("verification", kv->key)) @@ -288,10 +296,17 @@ skip_main_cfg_parse: n_cfg.bpmp_clock = atoi(kv->val); } + // Check if user canceled time setting before. + if (time_old_raw && !n_cfg.timeoffset) + n_cfg.timeoffset = 1; + break; } } + // Set auto DST here in case it's missing. + max77620_rtc_set_auto_dst(n_cfg.timedst); + ini_free(&ini_nyx_sections); }