diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index 31e53f3f2..c25af0da5 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "animations/animation_manager.h" #include "desktop/scenes/desktop_scene.h" @@ -48,6 +49,21 @@ static void desktop_dummy_mode_icon_draw_callback(Canvas* canvas, void* context) canvas_draw_icon(canvas, 0, 0, &I_GameMode_11x8); } +static void desktop_togle_clock_view(Desktop* desktop, bool is_enabled) { + furi_assert(desktop); + + // clock type upd after 1 minute + desktop->clock_type = (locale_get_time_format() == LocaleTimeFormat24h); + + if(is_enabled) { // && !furi_timer_is_running(desktop->update_clock_timer)) { + furi_timer_start(desktop->update_clock_timer, furi_ms_to_ticks(1000)); + } else if(!is_enabled) { //&& furi_timer_is_running(desktop->update_clock_timer)) { + furi_timer_stop(desktop->update_clock_timer); + } + + view_port_enabled_set(desktop->clock_viewport, is_enabled); +} + static uint8_t desktop_clock_get_num_w(uint8_t num) { if(num == 1) { return 3; @@ -81,7 +97,8 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) { desktop_clock_get_num_w(d[3]) + //c4 2 + 4; // ":" + 4 separators - view_port_set_width(desktop->clock_viewport, new_w - 1); + // further away from the battery charge indicator, if the smallest minute is 1 + view_port_set_width(desktop->clock_viewport, new_w - !(d[0] == 1)); uint8_t x = new_w; @@ -123,6 +140,9 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) { // TODO: Implement a message mechanism for loading settings and (optionally) // locking and unlocking DESKTOP_SETTINGS_LOAD(&desktop->settings); + + desktop_togle_clock_view(desktop, desktop->settings.display_clock); + desktop_auto_lock_arm(desktop); return true; case DesktopGlobalAutoLock: @@ -192,15 +212,25 @@ static void desktop_update_clock_timer_callback(void* context) { furi_assert(context); Desktop* desktop = context; - FuriHalRtcDateTime curr_dt; - furi_hal_rtc_get_datetime(&curr_dt); - if(desktop->minute != curr_dt.minute) { - desktop->hour = curr_dt.hour; - desktop->minute = curr_dt.minute; - view_port_update(desktop->clock_viewport); - } + if(gui_get_count_of_enabled_view_port_in_layer(desktop->gui, GuiLayerStatusBarLeft) < 6) { + FuriHalRtcDateTime curr_dt; + furi_hal_rtc_get_datetime(&curr_dt); - // view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAutoLock); + 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); + } + + view_port_enabled_set(desktop->clock_viewport, true); + } else { + view_port_enabled_set(desktop->clock_viewport, false); + } } void desktop_lock(Desktop* desktop) { @@ -353,7 +383,7 @@ Desktop* desktop_alloc() { desktop->clock_viewport = view_port_alloc(); view_port_set_width(desktop->clock_viewport, 25); view_port_draw_callback_set(desktop->clock_viewport, desktop_clock_draw_callback, desktop); - view_port_enabled_set(desktop->clock_viewport, true); + view_port_enabled_set(desktop->clock_viewport, false); gui_add_view_port(desktop->gui, desktop->clock_viewport, GuiLayerStatusBarRight); // Stealth mode icon @@ -391,11 +421,14 @@ Desktop* desktop_alloc() { FuriHalRtcDateTime curr_dt; furi_hal_rtc_get_datetime(&curr_dt); - desktop->hour = curr_dt.hour; + 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; - furi_timer_start(desktop->update_clock_timer, furi_ms_to_ticks(1000)); - furi_record_create(RECORD_DESKTOP, desktop); return desktop; @@ -489,6 +522,9 @@ int32_t desktop_srv(void* p) { } view_port_enabled_set(desktop->dummy_mode_icon_viewport, desktop->settings.dummy_mode); + + desktop_togle_clock_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( desktop->animation_manager, desktop->settings.dummy_mode); diff --git a/applications/services/desktop/desktop_i.h b/applications/services/desktop/desktop_i.h index 0fac0f34c..2d033c196 100644 --- a/applications/services/desktop/desktop_i.h +++ b/applications/services/desktop/desktop_i.h @@ -75,8 +75,9 @@ struct Desktop { uint8_t hour; uint8_t minute; + bool clock_type : 1; // true - 24h false - 12h - bool in_transition; + bool in_transition : 1; }; Desktop* desktop_alloc(); diff --git a/applications/services/desktop/desktop_settings.h b/applications/services/desktop/desktop_settings.h index e750c696c..49291b371 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -63,4 +63,5 @@ typedef struct { uint32_t auto_lock_delay_ms; uint8_t displayBatteryPercentage; uint8_t dummy_mode; + uint8_t display_clock; } DesktopSettings; diff --git a/applications/services/gui/gui.c b/applications/services/gui/gui.c index 392011620..87cc962ca 100644 --- a/applications/services/gui/gui.c +++ b/applications/services/gui/gui.c @@ -17,6 +17,23 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) { return NULL; } +uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer) { + furi_assert(gui); + furi_check(layer < GuiLayerMAX); + uint8_t ret = 0; + + ViewPortArray_it_t it; + ViewPortArray_it_last(it, gui->layers[layer]); + while(!ViewPortArray_end_p(it)) { + ViewPort* view_port = *ViewPortArray_ref(it); + if(view_port_is_enabled(view_port)) { + ret++; + } + ViewPortArray_previous(it); + } + return ret; +} + void gui_update(Gui* gui) { furi_assert(gui); if(!gui->direct_draw) furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_DRAW); diff --git a/applications/services/gui/gui.h b/applications/services/gui/gui.h index 1b5987eda..a59a4ff6a 100644 --- a/applications/services/gui/gui.h +++ b/applications/services/gui/gui.h @@ -132,6 +132,8 @@ Canvas* gui_direct_draw_acquire(Gui* gui); */ void gui_direct_draw_release(Gui* gui); +uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer); + #ifdef __cplusplus } #endif diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c index 9d63f6628..b9233a0fa 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c @@ -11,7 +11,8 @@ #define SCENE_EVENT_SELECT_PIN_SETUP 3 #define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 4 #define SCENE_EVENT_SELECT_BATTERY_DISPLAY 5 -#define SCENE_EVENT_SELECT_CHANGE_NAME 6 +#define SCENE_EVENT_SELECT_CLOCK_DISPLAY 6 +#define SCENE_EVENT_SELECT_CHANGE_NAME 7 #define AUTO_LOCK_DELAY_COUNT 9 const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = { @@ -29,6 +30,14 @@ const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = { const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] = {0, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000}; +#define CLOCK_ENABLE_COUNT 2 +const char* const clock_enable_text[CLOCK_ENABLE_COUNT] = { + "OFF", + "ON", +}; + +const uint32_t clock_enable_value[CLOCK_ENABLE_COUNT] = {0, 1}; + #define BATTERY_VIEW_COUNT 6 const char* const battery_view_count_text[BATTERY_VIEW_COUNT] = @@ -55,6 +64,14 @@ static void desktop_settings_scene_start_battery_view_changed(VariableItem* item app->settings.displayBatteryPercentage = index; } +static void desktop_settings_scene_start_clock_enable_changed(VariableItem* item) { + DesktopSettingsApp* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, clock_enable_text[index]); + app->settings.display_clock = index; +} + static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* item) { DesktopSettingsApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -106,6 +123,18 @@ void desktop_settings_scene_start_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, battery_view_count_text[value_index]); + item = variable_item_list_add( + variable_item_list, + "Clock on desktop", + CLOCK_ENABLE_COUNT, + desktop_settings_scene_start_clock_enable_changed, // + app); + + value_index = + value_index_uint32(app->settings.display_clock, clock_enable_value, CLOCK_ENABLE_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, clock_enable_text[value_index]); + variable_item_list_add(variable_item_list, "Change Flipper Name", 0, NULL, app); view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList); @@ -142,6 +171,9 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even case SCENE_EVENT_SELECT_BATTERY_DISPLAY: consumed = true; break; + case SCENE_EVENT_SELECT_CLOCK_DISPLAY: + consumed = true; + break; case SCENE_EVENT_SELECT_CHANGE_NAME: scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneChangeName); consumed = true; diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index cd79ebb23..2f9cf5314 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1658,6 +1658,7 @@ Function,+,gui_add_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, voi Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer" Function,+,gui_direct_draw_acquire,Canvas*,Gui* Function,+,gui_direct_draw_release,void,Gui* +Function,-,gui_get_count_of_enabled_view_port_in_layer,uint8_t,"Gui*, GuiLayer" Function,+,gui_get_framebuffer_size,size_t,const Gui* Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*" Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"