mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-11 23:38:11 -07:00
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".
This commit is contained in:
@@ -58,10 +58,13 @@ 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.format_12 != time_format_12 ||
|
||||
desktop->clock.midnight_format != midnight_format) {
|
||||
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);
|
||||
@@ -96,7 +99,7 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) {
|
||||
hour -= 12;
|
||||
}
|
||||
if(hour == 0) {
|
||||
hour = 12;
|
||||
hour = (desktop->clock.midnight_format == LocaleMidnightFormatZero) ? 0 : 12;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#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"
|
||||
@@ -40,6 +41,7 @@ typedef struct {
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
bool format_12; // 1 - 12 hour, 0 - 24H
|
||||
LocaleMidnightFormat midnight_format;
|
||||
} DesktopClock;
|
||||
|
||||
struct Desktop {
|
||||
|
||||
@@ -44,6 +44,7 @@ typedef struct {
|
||||
bool pin_locked;
|
||||
int8_t cover_offset;
|
||||
DesktopViewLockedState view_state;
|
||||
LocaleMidnightFormat midnight_format;
|
||||
} DesktopViewLockedModel;
|
||||
|
||||
void desktop_view_locked_set_callback(
|
||||
@@ -79,6 +80,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 = (model->midnight_format == LocaleMidnightFormatZero) ? 0 : 12;
|
||||
}
|
||||
}
|
||||
snprintf(time_str, 9, "%.2d:%.2d", pm ? datetime.hour - 12 : datetime.hour, datetime.minute);
|
||||
snprintf(second_str, 5, ":%.2d", datetime.second);
|
||||
@@ -297,6 +301,7 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "menu.h"
|
||||
|
||||
#include "locale/locale.h"
|
||||
#include <gui/elements.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/icon_i.h>
|
||||
@@ -384,7 +385,10 @@ static void menu_draw_callback(Canvas* canvas, void* _model) {
|
||||
hour -= 12;
|
||||
}
|
||||
if(hour == 0) {
|
||||
hour = 12;
|
||||
hour = (locale_get_midnight_format() == LocaleMidnightFormatTwelve &&
|
||||
locale_get_time_format() == LocaleTimeFormat12h) ?
|
||||
12 :
|
||||
0;
|
||||
}
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
char clk[20];
|
||||
|
||||
@@ -18,6 +18,14 @@ 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();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ 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 */
|
||||
@@ -64,6 +69,18 @@ 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
|
||||
|
||||
@@ -165,6 +165,22 @@ 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",
|
||||
@@ -350,6 +366,17 @@ 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(
|
||||
|
||||
@@ -1628,6 +1628,7 @@ 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,
|
||||
@@ -1651,6 +1652,7 @@ 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
|
||||
@@ -2347,9 +2349,11 @@ 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
|
||||
|
||||
|
@@ -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;
|
||||
FuriHalRtcLocaleDateFormat locale_dateformat : 2;
|
||||
FuriHalRtcLogDevice log_device : 2;
|
||||
FuriHalRtcLogBaudRate log_baud_rate : 3;
|
||||
uint8_t reserved : 1;
|
||||
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;
|
||||
} SystemReg;
|
||||
|
||||
_Static_assert(sizeof(SystemReg) == 4, "SystemReg size mismatch");
|
||||
@@ -379,6 +379,19 @@ 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;
|
||||
|
||||
@@ -65,6 +65,11 @@ 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 */
|
||||
@@ -231,6 +236,18 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user