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 6 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum VarItemListIndex {
VarItemListIndexLockscreen,
VarItemListIndexStatusbar,
VarItemListIndexFileBrowser,
VarItemListIndexGeneral,
};

void momentum_app_scene_interface_var_item_list_callback(void* context, uint32_t index) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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" : "XX: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);
}
2 changes: 1 addition & 1 deletion applications/services/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion applications/services/desktop/views/desktop_view_locked.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <locale/locale.h>
#include <momentum/momentum.h>

#include "../desktop_i.h"
#include "desktop_view_locked.h"

#define COVER_MOVING_INTERVAL_MS (50)
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions 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 @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions lib/momentum/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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
Expand Down Expand Up @@ -107,6 +108,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)},
Expand Down
1 change: 1 addition & 0 deletions lib/momentum/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,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;
Expand Down
Loading