From adc66d78da759836724e127344ae466edbdb76b6 Mon Sep 17 00:00:00 2001 From: Alexander Bays Date: Sat, 1 Mar 2025 22:20:38 -0600 Subject: [PATCH] Clock: 12 hour "midnight format" (#341) * Clock: 12 hour midnight format - References #317 and adds the options `12:XX` and `00:XX` in `Settings > System > Midnight Format` to display the preferred clock format past midnight on all clocks (Desktop, Main Menu MNTM style, Lock screen and Nightstand clock app). "12:30 AM" -> "00:30" OR "12:30". * Fix: Move midnight format setting out of furi_rtc - Also felt like the midnight format setting was too out of place in `MNTM > Interface` with the 5 other submenu entries, so I put it in Misc for now. * clock app external * Moved midnight format setting into new `Interface > General` * Update applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c * Update changelog --------- Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com> --- CHANGELOG.md | 1 + .../scenes/momentum_app_scene_config.h | 1 + .../scenes/momentum_app_scene_interface.c | 8 +++ .../momentum_app_scene_interface_general.c | 61 +++++++++++++++++++ applications/services/desktop/desktop.c | 2 +- .../desktop/views/desktop_view_locked.c | 4 +- applications/services/gui/modules/menu.c | 14 +++-- lib/momentum/settings.c | 2 + lib/momentum/settings.h | 1 + 9 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c diff --git a/CHANGELOG.md b/CHANGELOG.md index aa0b0e7f3..8ecf6c543 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - OFW: Infrared: Universal IR signal selection (by @portasynthinca3) - OFW: NFC: Disney Infinity KDF plugin (by @bettse) - Archive: Add item count to directory info scene (#378 by @956MB) +- Clock: 12 hour "midnight format" in Momentum Settings (#341 by @956MB) - UL: Input: Vibro on Button press option (by @Dmitry422) - Desktop: - UL: Option to prevent Auto Lock when connected to USB/RPC (by @Dmitry422) diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_config.h b/applications/main/momentum_app/scenes/momentum_app_scene_config.h index 2c18840b4..80ba33d71 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_config.h +++ b/applications/main/momentum_app/scenes/momentum_app_scene_config.h @@ -10,6 +10,7 @@ ADD_SCENE(momentum_app, interface_mainmenu_style, InterfaceMainmenuStyle) ADD_SCENE(momentum_app, interface_lockscreen, InterfaceLockscreen) ADD_SCENE(momentum_app, interface_statusbar, InterfaceStatusbar) ADD_SCENE(momentum_app, interface_filebrowser, InterfaceFilebrowser) +ADD_SCENE(momentum_app, interface_general, InterfaceGeneral) ADD_SCENE(momentum_app, protocols, Protocols) ADD_SCENE(momentum_app, protocols_freqs, ProtocolsFreqs) ADD_SCENE(momentum_app, protocols_freqs_static, ProtocolsFreqsStatic) diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_interface.c b/applications/main/momentum_app/scenes/momentum_app_scene_interface.c index c6877ab48..d32ccdd18 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_interface.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_interface.c @@ -6,6 +6,7 @@ enum VarItemListIndex { VarItemListIndexLockscreen, VarItemListIndexStatusbar, VarItemListIndexFileBrowser, + VarItemListIndexGeneral, }; void momentum_app_scene_interface_var_item_list_callback(void* context, uint32_t index) { @@ -33,6 +34,9 @@ void momentum_app_scene_interface_on_enter(void* context) { item = variable_item_list_add(var_item_list, "File Browser", 0, NULL, app); variable_item_set_current_value_text(item, ">"); + item = variable_item_list_add(var_item_list, "General", 0, NULL, app); + variable_item_set_current_value_text(item, ">"); + variable_item_list_set_enter_callback( var_item_list, momentum_app_scene_interface_var_item_list_callback, app); @@ -76,6 +80,10 @@ bool momentum_app_scene_interface_on_event(void* context, SceneManagerEvent even app->scene_manager, MomentumAppSceneInterfaceFilebrowser, 0); scene_manager_next_scene(app->scene_manager, MomentumAppSceneInterfaceFilebrowser); break; + case VarItemListIndexGeneral: + scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneInterfaceGeneral, 0); + scene_manager_next_scene(app->scene_manager, MomentumAppSceneInterfaceGeneral); + break; default: break; } diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c b/applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c new file mode 100644 index 000000000..11a29b4cc --- /dev/null +++ b/applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c @@ -0,0 +1,61 @@ +#include "../momentum_app.h" + +enum VarItemListIndex { + VarItemListIndexMidnightFormat, +}; + +void momentum_app_scene_interface_general_var_item_list_callback(void* context, uint32_t index) { + MomentumApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, index); +} + +static void momentum_app_scene_interface_general_midnight_format_changed(VariableItem* item) { + MomentumApp* app = variable_item_get_context(item); + bool value = variable_item_get_current_value_index(item); + variable_item_set_current_value_text(item, value ? "00:XX" : "12:00"); + momentum_settings.midnight_format_00 = value; + app->save_settings = true; +} + +void momentum_app_scene_interface_general_on_enter(void* context) { + MomentumApp* app = context; + VariableItemList* var_item_list = app->var_item_list; + VariableItem* item; + + item = variable_item_list_add( + var_item_list, + "Clock Midnight Format", + 2, + momentum_app_scene_interface_general_midnight_format_changed, + app); + variable_item_set_current_value_index(item, momentum_settings.midnight_format_00); + variable_item_set_current_value_text( + item, momentum_settings.midnight_format_00 ? "00:XX" : "12:XX"); + + variable_item_list_set_enter_callback( + var_item_list, momentum_app_scene_interface_general_var_item_list_callback, app); + + variable_item_list_set_selected_item( + var_item_list, + scene_manager_get_scene_state(app->scene_manager, MomentumAppSceneInterfaceGeneral)); + + view_dispatcher_switch_to_view(app->view_dispatcher, MomentumAppViewVarItemList); +} + +bool momentum_app_scene_interface_general_on_event(void* context, SceneManagerEvent event) { + MomentumApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + scene_manager_set_scene_state( + app->scene_manager, MomentumAppSceneInterfaceGeneral, event.event); + consumed = true; + } + + return consumed; +} + +void momentum_app_scene_interface_general_on_exit(void* context) { + MomentumApp* app = context; + variable_item_list_reset(app->var_item_list); +} diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index 0d5ac9565..12690df55 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -96,7 +96,7 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) { hour -= 12; } if(hour == 0) { - hour = 12; + hour = momentum_settings.midnight_format_00 ? 0 : 12; } } diff --git a/applications/services/desktop/views/desktop_view_locked.c b/applications/services/desktop/views/desktop_view_locked.c index 2959e2a7b..7281423d4 100644 --- a/applications/services/desktop/views/desktop_view_locked.c +++ b/applications/services/desktop/views/desktop_view_locked.c @@ -8,7 +8,6 @@ #include #include -#include "../desktop_i.h" #include "desktop_view_locked.h" #define COVER_MOVING_INTERVAL_MS (50) @@ -79,6 +78,9 @@ void desktop_view_locked_draw_lockscreen(Canvas* canvas, void* m) { } else { pm = datetime.hour > 12; snprintf(meridian_str, 3, datetime.hour >= 12 ? "PM" : "AM"); + if(datetime.hour == 0) { + datetime.hour = momentum_settings.midnight_format_00 ? 0 : 12; + } } snprintf(time_str, 9, "%.2d:%.2d", pm ? datetime.hour - 12 : datetime.hour, datetime.minute); snprintf(second_str, 5, ":%.2d", datetime.second); diff --git a/applications/services/gui/modules/menu.c b/applications/services/gui/modules/menu.c index e11d38a3a..9e66b9d27 100644 --- a/applications/services/gui/modules/menu.c +++ b/applications/services/gui/modules/menu.c @@ -1,5 +1,6 @@ #include "menu.h" +#include "locale/locale.h" #include #include #include @@ -398,11 +399,14 @@ static void menu_draw_callback(Canvas* canvas, void* _model) { furi_hal_rtc_get_datetime(&curr_dt); uint8_t hour = curr_dt.hour; uint8_t min = curr_dt.minute; - if(hour > 12) { - hour -= 12; - } - if(hour == 0) { - hour = 12; + LocaleTimeFormat time_format = locale_get_time_format(); + if(time_format == LocaleTimeFormat12h) { + if(hour > 12) { + hour -= 12; + } + if(hour == 0) { + hour = (momentum_settings.midnight_format_00 ? 0 : 12); + } } canvas_set_font(canvas, FontSecondary); char clk[20]; diff --git a/lib/momentum/settings.c b/lib/momentum/settings.c index 02cf69f61..72f0f6f95 100644 --- a/lib/momentum/settings.c +++ b/lib/momentum/settings.c @@ -35,6 +35,7 @@ MomentumSettings momentum_settings = { .dark_mode = false, // OFF .rgb_backlight = false, // OFF .butthurt_timer = 21600, // 6 H + .midnight_format_00 = true, // 00:XX .spi_cc1101_handle = SpiDefault, // &furi_hal_spi_bus_handle_external .spi_nrf24_handle = SpiDefault, // &furi_hal_spi_bus_handle_external .uart_esp_channel = FuriHalSerialIdUsart, // pin 13,14 @@ -105,6 +106,7 @@ static const struct { {setting_bool(dark_mode)}, {setting_bool(rgb_backlight)}, {setting_uint(butthurt_timer, 0, 172800)}, + {setting_bool(midnight_format_00)}, {setting_enum(spi_cc1101_handle, SpiCount)}, {setting_enum(spi_nrf24_handle, SpiCount)}, {setting_enum(uart_esp_channel, FuriHalSerialIdMax)}, diff --git a/lib/momentum/settings.h b/lib/momentum/settings.h index eb7014e13..e379dd246 100644 --- a/lib/momentum/settings.h +++ b/lib/momentum/settings.h @@ -92,6 +92,7 @@ typedef struct { bool dark_mode; bool rgb_backlight; uint32_t butthurt_timer; + bool midnight_format_00; SpiHandle spi_cc1101_handle; SpiHandle spi_nrf24_handle; FuriHalSerialId uart_esp_channel;