From ee3d35267c824bf1defe7cbd7544aaf082238bfe Mon Sep 17 00:00:00 2001 From: 956MB Date: Tue, 21 Jan 2025 18:54:09 -0600 Subject: [PATCH] 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. --- .../scenes/momentum_app_scene_misc.c | 19 ++++++++++++ applications/services/desktop/desktop.c | 7 ++--- applications/services/desktop/desktop_i.h | 2 -- .../desktop/views/desktop_view_locked.c | 5 +--- applications/services/gui/modules/menu.c | 16 +++++----- applications/services/locale/locale.c | 8 ----- applications/services/locale/locale.h | 17 ----------- .../settings/system/system_settings.c | 27 ----------------- lib/momentum/settings.c | 2 ++ lib/momentum/settings.h | 1 + targets/f7/api_symbols.csv | 4 --- targets/f7/furi_hal/furi_hal_rtc.c | 29 +++++-------------- targets/f7/furi_hal/furi_hal_rtc.h | 17 ----------- 13 files changed, 41 insertions(+), 113 deletions(-) diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_misc.c b/applications/main/momentum_app/scenes/momentum_app_scene_misc.c index ca66861f8..c09395781 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_misc.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_misc.c @@ -6,6 +6,7 @@ enum VarItemListIndex { VarItemListIndexSpoof, VarItemListIndexVgm, VarItemListIndexChargeCap, + VarItemListIndexMidnightFormat, VarItemListIndexShowMomentumIntro, }; @@ -25,6 +26,14 @@ static void momentum_app_scene_misc_charge_cap_changed(VariableItem* item) { app->save_settings = true; } +static void momentum_app_scene_interface_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:XX"); + momentum_settings.midnight_format_00 = value; + app->save_settings = true; +} + void momentum_app_scene_misc_on_enter(void* context) { MomentumApp* app = context; VariableItemList* var_item_list = app->var_item_list; @@ -55,6 +64,16 @@ void momentum_app_scene_misc_on_enter(void* context) { variable_item_set_current_value_index(item, value_index - 1); variable_item_set_current_value_text(item, cap_str); + item = variable_item_list_add( + var_item_list, + "Clock Midnight Format", + 2, + momentum_app_scene_interface_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_add(var_item_list, "Show Momentum Intro", 0, NULL, app); variable_item_list_set_enter_callback( diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index aa58ae224..ca48fa7bd 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -58,13 +58,10 @@ static void desktop_clock_update(Desktop* desktop) { DateTime curr_dt; furi_hal_rtc_get_datetime(&curr_dt); bool time_format_12 = locale_get_time_format() == LocaleTimeFormat12h; - LocaleMidnightFormat midnight_format = locale_get_midnight_format(); if(desktop->clock.hour != curr_dt.hour || desktop->clock.minute != curr_dt.minute || - desktop->clock.format_12 != time_format_12 || - desktop->clock.midnight_format != midnight_format) { + desktop->clock.format_12 != time_format_12) { desktop->clock.format_12 = time_format_12; - desktop->clock.midnight_format = midnight_format; desktop->clock.hour = curr_dt.hour; desktop->clock.minute = curr_dt.minute; view_port_update(desktop->clock_viewport); @@ -99,7 +96,7 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) { hour -= 12; } if(hour == 0) { - hour = (desktop->clock.midnight_format == LocaleMidnightFormatZero) ? 0 : 12; + hour = momentum_settings.midnight_format_00 ? 0 : 12; } } diff --git a/applications/services/desktop/desktop_i.h b/applications/services/desktop/desktop_i.h index 12586a5e5..10badcc07 100644 --- a/applications/services/desktop/desktop_i.h +++ b/applications/services/desktop/desktop_i.h @@ -5,7 +5,6 @@ #include "desktop_keybinds.h" #include "animations/animation_manager.h" -#include "locale/locale.h" #include "views/desktop_view_pin_timeout.h" #include "views/desktop_view_pin_input.h" #include "views/desktop_view_locked.h" @@ -41,7 +40,6 @@ typedef struct { uint8_t hour; uint8_t minute; bool format_12; // 1 - 12 hour, 0 - 24H - LocaleMidnightFormat midnight_format; } DesktopClock; struct Desktop { diff --git a/applications/services/desktop/views/desktop_view_locked.c b/applications/services/desktop/views/desktop_view_locked.c index 93c7ccfde..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) @@ -44,7 +43,6 @@ typedef struct { bool pin_locked; int8_t cover_offset; DesktopViewLockedState view_state; - LocaleMidnightFormat midnight_format; } DesktopViewLockedModel; void desktop_view_locked_set_callback( @@ -81,7 +79,7 @@ void desktop_view_locked_draw_lockscreen(Canvas* canvas, void* m) { pm = datetime.hour > 12; snprintf(meridian_str, 3, datetime.hour >= 12 ? "PM" : "AM"); if(datetime.hour == 0) { - datetime.hour = (model->midnight_format == LocaleMidnightFormatZero) ? 0 : 12; + datetime.hour = momentum_settings.midnight_format_00 ? 0 : 12; } } snprintf(time_str, 9, "%.2d:%.2d", pm ? datetime.hour - 12 : datetime.hour, datetime.minute); @@ -301,7 +299,6 @@ void desktop_view_locked_lock(DesktopViewLocked* locked_view, bool pin_locked) { furi_assert(model->view_state == DesktopViewLockedStateUnlocked); model->view_state = DesktopViewLockedStateLocked; model->pin_locked = pin_locked; - model->midnight_format = locale_get_midnight_format(); view_commit_model(locked_view->view, true); } diff --git a/applications/services/gui/modules/menu.c b/applications/services/gui/modules/menu.c index c9f71effa..d6c5689ee 100644 --- a/applications/services/gui/modules/menu.c +++ b/applications/services/gui/modules/menu.c @@ -381,14 +381,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 = (locale_get_midnight_format() == LocaleMidnightFormatTwelve && - locale_get_time_format() == LocaleTimeFormat12h) ? - 12 : - 0; + 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/applications/services/locale/locale.c b/applications/services/locale/locale.c index b26864243..6acf2eea9 100644 --- a/applications/services/locale/locale.c +++ b/applications/services/locale/locale.c @@ -18,14 +18,6 @@ void locale_set_time_format(LocaleTimeFormat format) { furi_hal_rtc_set_locale_timeformat((FuriHalRtcLocaleTimeFormat)format); } -LocaleMidnightFormat locale_get_midnight_format(void) { - return (LocaleMidnightFormat)furi_hal_rtc_get_locale_midnightformat(); -} - -void locale_set_midnight_format(LocaleMidnightFormat format) { - furi_hal_rtc_set_locale_midnightformat((FuriHalRtcLocaleMidnightFormat)format); -} - LocaleDateFormat locale_get_date_format(void) { return (LocaleDateFormat)furi_hal_rtc_get_locale_dateformat(); } diff --git a/applications/services/locale/locale.h b/applications/services/locale/locale.h index e9c8dc06a..0046302df 100644 --- a/applications/services/locale/locale.h +++ b/applications/services/locale/locale.h @@ -18,11 +18,6 @@ typedef enum { LocaleTimeFormat12h = 1, /**< 12-hour format */ } LocaleTimeFormat; -typedef enum { - LocaleMidnightFormatTwelve = 0, /**< 12:XX format */ - LocaleMidnightFormatZero = 1, /**< 00:XX format */ -} LocaleMidnightFormat; - typedef enum { LocaleDateFormatDMY = 0, /**< Day/Month/Year */ LocaleDateFormatMDY = 1, /**< Month/Day/Year */ @@ -69,18 +64,6 @@ LocaleTimeFormat locale_get_time_format(void); */ void locale_set_time_format(LocaleTimeFormat format); -/** Get Locale midnight format - * - * @return The locale midnight format. - */ -LocaleMidnightFormat locale_get_midnight_format(void); - -/** Set Locale midnight format - * - * @param[in] format The locale midnight format - */ -void locale_set_midnight_format(LocaleMidnightFormat format); - /** Format time to furi string * * @param[out] out_str The FuriString to store formatted time diff --git a/applications/settings/system/system_settings.c b/applications/settings/system/system_settings.c index 7055d90a9..43163dc17 100644 --- a/applications/settings/system/system_settings.c +++ b/applications/settings/system/system_settings.c @@ -165,22 +165,6 @@ static void time_format_changed(VariableItem* item) { locale_set_time_format(time_format_value[index]); } -const char* const midnight_format_text[] = { - "12:XX", - "00:XX", -}; - -const uint32_t midnight_format_value[] = { - LocaleMidnightFormatTwelve, - LocaleMidnightFormatZero, -}; - -static void midnight_format_changed(VariableItem* item) { - uint8_t index = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, midnight_format_text[index]); - locale_set_midnight_format(midnight_format_value[index]); -} - const char* const date_format_text[] = { "D/M/Y", "M/D/Y", @@ -366,17 +350,6 @@ SystemSettings* system_settings_alloc(void) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, time_format_text[value_index]); - item = variable_item_list_add( - app->var_item_list, - "Midnight Format", - COUNT_OF(midnight_format_text), - midnight_format_changed, - app); - value_index = value_index_uint32( - locale_get_midnight_format(), midnight_format_value, COUNT_OF(midnight_format_value)); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, midnight_format_text[value_index]); - item = variable_item_list_add( app->var_item_list, "Date Format", COUNT_OF(date_format_text), date_format_changed, app); value_index = value_index_uint32( diff --git a/lib/momentum/settings.c b/lib/momentum/settings.c index 315124c7c..770ca337e 100644 --- a/lib/momentum/settings.c +++ b/lib/momentum/settings.c @@ -34,6 +34,7 @@ MomentumSettings momentum_settings = { .rgb_backlight = false, // OFF .butthurt_timer = 21600, // 6 H .charge_cap = 100, // 100% + .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 @@ -103,6 +104,7 @@ static const struct { {setting_bool(rgb_backlight)}, {setting_uint(butthurt_timer, 0, 172800)}, {setting_uint(charge_cap, 5, 100)}, + {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 ee1341131..3e02d4405 100644 --- a/lib/momentum/settings.h +++ b/lib/momentum/settings.h @@ -82,6 +82,7 @@ typedef struct { bool rgb_backlight; uint32_t butthurt_timer; uint32_t charge_cap; + bool midnight_format_00; SpiHandle spi_cc1101_handle; SpiHandle spi_nrf24_handle; FuriHalSerialId uart_esp_channel; diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 136d85d93..f5e79d7ee 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1628,7 +1628,6 @@ Function,+,furi_hal_rtc_get_datetime,void,DateTime* Function,+,furi_hal_rtc_get_fault_data,uint32_t, Function,+,furi_hal_rtc_get_heap_track_mode,FuriHalRtcHeapTrackMode, Function,+,furi_hal_rtc_get_locale_dateformat,FuriHalRtcLocaleDateFormat, -Function,+,furi_hal_rtc_get_locale_midnightformat,FuriHalRtcLocaleMidnightFormat, Function,+,furi_hal_rtc_get_locale_timeformat,FuriHalRtcLocaleTimeFormat, Function,+,furi_hal_rtc_get_locale_units,FuriHalRtcLocaleUnits, Function,+,furi_hal_rtc_get_log_baud_rate,FuriHalRtcLogBaudRate, @@ -1652,7 +1651,6 @@ Function,+,furi_hal_rtc_set_fault_data,void,uint32_t Function,+,furi_hal_rtc_set_flag,void,FuriHalRtcFlag Function,+,furi_hal_rtc_set_heap_track_mode,void,FuriHalRtcHeapTrackMode Function,+,furi_hal_rtc_set_locale_dateformat,void,FuriHalRtcLocaleDateFormat -Function,+,furi_hal_rtc_set_locale_midnightformat,void,FuriHalRtcLocaleMidnightFormat Function,+,furi_hal_rtc_set_locale_timeformat,void,FuriHalRtcLocaleTimeFormat Function,+,furi_hal_rtc_set_locale_units,void,FuriHalRtcLocaleUnits Function,+,furi_hal_rtc_set_log_baud_rate,void,FuriHalRtcLogBaudRate @@ -2349,11 +2347,9 @@ Function,+,locale_format_date,void,"FuriString*, const DateTime*, const LocaleDa Function,+,locale_format_time,void,"FuriString*, const DateTime*, const LocaleTimeFormat, const _Bool" Function,+,locale_get_date_format,LocaleDateFormat, Function,+,locale_get_measurement_unit,LocaleMeasurementUnits, -Function,+,locale_get_midnight_format,LocaleMidnightFormat, Function,+,locale_get_time_format,LocaleTimeFormat, Function,+,locale_set_date_format,void,LocaleDateFormat Function,+,locale_set_measurement_unit,void,LocaleMeasurementUnits -Function,+,locale_set_midnight_format,void,LocaleMidnightFormat Function,+,locale_set_time_format,void,LocaleTimeFormat Function,-,log,double,double Function,-,log10,double,double diff --git a/targets/f7/furi_hal/furi_hal_rtc.c b/targets/f7/furi_hal/furi_hal_rtc.c index 74b978f6e..ab592fb78 100644 --- a/targets/f7/furi_hal/furi_hal_rtc.c +++ b/targets/f7/furi_hal/furi_hal_rtc.c @@ -31,14 +31,14 @@ typedef struct { uint8_t log_level : 4; uint8_t log_reserved : 4; uint8_t flags; - FuriHalRtcBootMode boot_mode : 4; - FuriHalRtcHeapTrackMode heap_track_mode : 2; - FuriHalRtcLocaleUnits locale_units : 1; - FuriHalRtcLocaleTimeFormat locale_timeformat : 1; - FuriHalRtcLocaleMidnightFormat locale_midnightformat : 1; - FuriHalRtcLocaleDateFormat locale_dateformat : 2; - FuriHalRtcLogDevice log_device : 2; - FuriHalRtcLogBaudRate log_baud_rate : 3; + FuriHalRtcBootMode boot_mode : 4; + FuriHalRtcHeapTrackMode heap_track_mode : 2; + FuriHalRtcLocaleUnits locale_units : 1; + FuriHalRtcLocaleTimeFormat locale_timeformat : 1; + FuriHalRtcLocaleDateFormat locale_dateformat : 2; + FuriHalRtcLogDevice log_device : 2; + FuriHalRtcLogBaudRate log_baud_rate : 3; + uint8_t reserved : 1; } SystemReg; _Static_assert(sizeof(SystemReg) == 4, "SystemReg size mismatch"); @@ -379,19 +379,6 @@ FuriHalRtcLocaleTimeFormat furi_hal_rtc_get_locale_timeformat(void) { return data->locale_timeformat; } -void furi_hal_rtc_set_locale_midnightformat(FuriHalRtcLocaleMidnightFormat value) { - uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem); - SystemReg* data = (SystemReg*)&data_reg; - data->locale_midnightformat = value; - furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg); -} - -FuriHalRtcLocaleMidnightFormat furi_hal_rtc_get_locale_midnightformat(void) { - uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem); - SystemReg* data = (SystemReg*)&data_reg; - return data->locale_midnightformat; -} - void furi_hal_rtc_set_locale_dateformat(FuriHalRtcLocaleDateFormat value) { uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem); SystemReg* data = (SystemReg*)&data_reg; diff --git a/targets/f7/furi_hal/furi_hal_rtc.h b/targets/f7/furi_hal/furi_hal_rtc.h index 8f212bf18..49d35eeb9 100644 --- a/targets/f7/furi_hal/furi_hal_rtc.h +++ b/targets/f7/furi_hal/furi_hal_rtc.h @@ -65,11 +65,6 @@ typedef enum { FuriHalRtcLocaleTimeFormat12h = 0x1, /**< 12-hour format */ } FuriHalRtcLocaleTimeFormat; -typedef enum { - FuriHalRtcLocaleMidnightFormatTwelve = 0x0, /**< 12:XX format */ - FuriHalRtcLocaleMidnightFormatZero = 0x1, /**< 00:XX format */ -} FuriHalRtcLocaleMidnightFormat; - typedef enum { FuriHalRtcLocaleDateFormatDMY = 0x0, /**< Day/Month/Year */ FuriHalRtcLocaleDateFormatMDY = 0x1, /**< Month/Day/Year */ @@ -236,18 +231,6 @@ void furi_hal_rtc_set_locale_timeformat(FuriHalRtcLocaleTimeFormat value); */ FuriHalRtcLocaleTimeFormat furi_hal_rtc_get_locale_timeformat(void); -/** Set RTC Locale Midnight Format - * - * @param[in] value The RTC Locale Midnight Format - */ -void furi_hal_rtc_set_locale_midnightformat(FuriHalRtcLocaleMidnightFormat value); - -/** Get RTC Locale Midnight Format - * - * @return The RTC Locale Midnight Format. - */ -FuriHalRtcLocaleMidnightFormat furi_hal_rtc_get_locale_midnightformat(void); - /** Set RTC Locale Date Format * * @param[in] value The RTC Locale Date Format