Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clock: 12 hour "midnight format" #341

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions applications/services/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 2 additions & 0 deletions applications/services/desktop/desktop_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions applications/services/desktop/views/desktop_view_locked.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion applications/services/gui/modules/menu.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "menu.h"

#include "locale/locale.h"
#include <gui/elements.h>
#include <assets_icons.h>
#include <gui/icon_i.h>
Expand Down Expand Up @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions applications/services/locale/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
17 changes: 17 additions & 0 deletions applications/services/locale/locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions applications/settings/system/system_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions targets/f7/furi_hal/furi_hal_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions targets/f7/furi_hal/furi_hal_rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down