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

Desktop Clock: some improvements #490

Merged
merged 1 commit into from
May 29, 2023
Merged
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
57 changes: 30 additions & 27 deletions applications/services/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down