mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-26 22:40:25 +00:00
Desktop Clock: some improvements
This commit is contained in:
parent
18a895310c
commit
b17125c65c
1 changed files with 30 additions and 27 deletions
|
@ -49,11 +49,32 @@ static void desktop_dummy_mode_icon_draw_callback(Canvas* canvas, void* context)
|
|||
canvas_draw_icon(canvas, 0, 0, &I_GameMode_11x8);
|
||||
}
|
||||
|
||||
static void desktop_toggle_clock_view(Desktop* desktop, bool is_enabled) {
|
||||
static void desktop_clock_upd_time(Desktop* desktop, bool forced) {
|
||||
furi_assert(desktop);
|
||||
|
||||
// clock type upd after 1 minute
|
||||
desktop->clock_type = (locale_get_time_format() == LocaleTimeFormat24h);
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
|
||||
if(forced) {
|
||||
desktop->clock_type = (locale_get_time_format() == LocaleTimeFormat24h);
|
||||
}
|
||||
|
||||
if(forced || (desktop->minute != curr_dt.minute)) {
|
||||
if(desktop->clock_type) {
|
||||
desktop->hour = curr_dt.hour;
|
||||
} else {
|
||||
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
|
||||
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
|
||||
}
|
||||
desktop->minute = curr_dt.minute;
|
||||
view_port_update(desktop->clock_viewport);
|
||||
}
|
||||
}
|
||||
|
||||
static void desktop_clock_toggle_view(Desktop* desktop, bool is_enabled) {
|
||||
furi_assert(desktop);
|
||||
|
||||
desktop_clock_upd_time(desktop, true);
|
||||
|
||||
if(is_enabled) { // && !furi_timer_is_running(desktop->update_clock_timer)) {
|
||||
furi_timer_start(desktop->update_clock_timer, furi_ms_to_ticks(1000));
|
||||
|
@ -141,7 +162,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
|||
// locking and unlocking
|
||||
DESKTOP_SETTINGS_LOAD(&desktop->settings);
|
||||
|
||||
desktop_toggle_clock_view(desktop, desktop->settings.display_clock);
|
||||
desktop_clock_toggle_view(desktop, desktop->settings.display_clock);
|
||||
|
||||
desktop_auto_lock_arm(desktop);
|
||||
return true;
|
||||
|
@ -208,24 +229,12 @@ static void desktop_auto_lock_inhibit(Desktop* desktop) {
|
|||
}
|
||||
}
|
||||
|
||||
static void desktop_update_clock_timer_callback(void* context) {
|
||||
static void desktop_clock_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
|
||||
if(gui_get_count_of_enabled_view_port_in_layer(desktop->gui, GuiLayerStatusBarLeft) < 6) {
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
|
||||
if(desktop->minute != curr_dt.minute) {
|
||||
if(desktop->clock_type) {
|
||||
desktop->hour = curr_dt.hour;
|
||||
} else {
|
||||
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
|
||||
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
|
||||
}
|
||||
desktop->minute = curr_dt.minute;
|
||||
view_port_update(desktop->clock_viewport);
|
||||
}
|
||||
desktop_clock_upd_time(desktop, false);
|
||||
|
||||
view_port_enabled_set(desktop->clock_viewport, true);
|
||||
} else {
|
||||
|
@ -424,18 +433,12 @@ Desktop* desktop_alloc() {
|
|||
desktop->status_pubsub = furi_pubsub_alloc();
|
||||
|
||||
desktop->update_clock_timer =
|
||||
furi_timer_alloc(desktop_update_clock_timer_callback, FuriTimerTypePeriodic, desktop);
|
||||
furi_timer_alloc(desktop_clock_timer_callback, FuriTimerTypePeriodic, desktop);
|
||||
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
|
||||
if(desktop->clock_type) {
|
||||
desktop->hour = curr_dt.hour;
|
||||
} else {
|
||||
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
|
||||
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
|
||||
}
|
||||
desktop->minute = curr_dt.minute;
|
||||
desktop_clock_upd_time(desktop, true);
|
||||
|
||||
furi_record_create(RECORD_DESKTOP, desktop);
|
||||
|
||||
|
@ -483,7 +486,7 @@ int32_t desktop_srv(void* p) {
|
|||
|
||||
view_port_enabled_set(desktop->dummy_mode_icon_viewport, desktop->settings.dummy_mode);
|
||||
|
||||
desktop_toggle_clock_view(desktop, desktop->settings.display_clock);
|
||||
desktop_clock_toggle_view(desktop, desktop->settings.display_clock);
|
||||
|
||||
desktop_main_set_dummy_mode_state(desktop->main_view, desktop->settings.dummy_mode);
|
||||
animation_manager_set_dummy_mode_state(
|
||||
|
|
Loading…
Reference in a new issue