From 73a13f584feb1854918f255ac2e953e1db277452 Mon Sep 17 00:00:00 2001 From: its your bedtime <23366927+itsyourbedtime@users.noreply.github.com> Date: Mon, 4 Oct 2021 12:33:31 +0300 Subject: [PATCH] Desktop: locked view timeout refactoring, Switch hwmismatch custom view to popup (#744) Co-authored-by: SG --- applications/desktop/desktop.c | 6 +- applications/desktop/desktop_i.h | 7 +- .../scenes/desktop_scene_hw_mismatch.c | 31 ++++++--- .../desktop/scenes/desktop_scene_main.c | 2 +- .../desktop/views/desktop_hw_mismatch.c | 66 ------------------- .../desktop/views/desktop_hw_mismatch.h | 38 ----------- .../desktop/views/desktop_lock_menu.c | 2 +- .../desktop/views/desktop_lock_menu.h | 3 +- applications/desktop/views/desktop_locked.c | 19 +++--- applications/desktop/views/desktop_locked.h | 3 +- 10 files changed, 43 insertions(+), 134 deletions(-) delete mode 100644 applications/desktop/views/desktop_hw_mismatch.c delete mode 100644 applications/desktop/views/desktop_hw_mismatch.h diff --git a/applications/desktop/desktop.c b/applications/desktop/desktop.c index ef17fc87f..4aa214538 100644 --- a/applications/desktop/desktop.c +++ b/applications/desktop/desktop.c @@ -40,7 +40,7 @@ Desktop* desktop_alloc() { desktop->locked_view = desktop_locked_alloc(); desktop->debug_view = desktop_debug_alloc(); desktop->first_start_view = desktop_first_start_alloc(); - desktop->hw_mismatch_view = desktop_hw_mismatch_alloc(); + desktop->hw_mismatch_popup = popup_alloc(); view_dispatcher_add_view( desktop->view_dispatcher, DesktopViewMain, desktop_main_get_view(desktop->main_view)); @@ -61,7 +61,7 @@ Desktop* desktop_alloc() { view_dispatcher_add_view( desktop->view_dispatcher, DesktopViewHwMismatch, - desktop_hw_mismatch_get_view(desktop->hw_mismatch_view)); + popup_get_view(desktop->hw_mismatch_popup)); // Lock icon desktop->lock_viewport = view_port_alloc(); @@ -91,7 +91,7 @@ void desktop_free(Desktop* desktop) { desktop_locked_free(desktop->locked_view); desktop_debug_free(desktop->debug_view); desktop_first_start_free(desktop->first_start_view); - desktop_hw_mismatch_free(desktop->hw_mismatch_view); + popup_free(desktop->hw_mismatch_popup); furi_record_close("gui"); desktop->gui = NULL; diff --git a/applications/desktop/desktop_i.h b/applications/desktop/desktop_i.h index 8f4241832..c23ab41b2 100644 --- a/applications/desktop/desktop_i.h +++ b/applications/desktop/desktop_i.h @@ -7,13 +7,13 @@ #include #include +#include #include #include #include #include "views/desktop_main.h" #include "views/desktop_first_start.h" -#include "views/desktop_hw_mismatch.h" #include "views/desktop_lock_menu.h" #include "views/desktop_locked.h" #include "views/desktop_debug.h" @@ -22,9 +22,6 @@ #include "desktop/desktop_settings/desktop_settings.h" -#define HINT_TIMEOUT_L 2 -#define HINT_TIMEOUT_H 11 - typedef enum { DesktopViewMain, DesktopViewLockMenu, @@ -44,7 +41,7 @@ struct Desktop { SceneManager* scene_manager; DesktopFirstStartView* first_start_view; - DesktopHwMismatchView* hw_mismatch_view; + Popup* hw_mismatch_popup; DesktopMainView* main_view; DesktopLockMenuView* lock_menu; DesktopLockedView* locked_view; diff --git a/applications/desktop/scenes/desktop_scene_hw_mismatch.c b/applications/desktop/scenes/desktop_scene_hw_mismatch.c index 224ddb586..5a33054d9 100644 --- a/applications/desktop/scenes/desktop_scene_hw_mismatch.c +++ b/applications/desktop/scenes/desktop_scene_hw_mismatch.c @@ -1,16 +1,26 @@ #include "../desktop_i.h" -#include "../views/desktop_hw_mismatch.h" +#include -void desktop_scene_hw_mismatch_callback(DesktopHwMismatchEvent event, void* context) { +#define HW_MISMATCH_BACK_EVENT (0UL) + +void desktop_scene_hw_mismatch_callback(void* context) { Desktop* desktop = (Desktop*)context; - view_dispatcher_send_custom_event(desktop->view_dispatcher, event); + view_dispatcher_send_custom_event(desktop->view_dispatcher, HW_MISMATCH_BACK_EVENT); } void desktop_scene_hw_mismatch_on_enter(void* context) { Desktop* desktop = (Desktop*)context; - - desktop_hw_mismatch_set_callback( - desktop->hw_mismatch_view, desktop_scene_hw_mismatch_callback, desktop); + Popup* popup = desktop->hw_mismatch_popup; + char buffer[256]; // strange but smaller buffer not making it + snprintf( + buffer, + sizeof(buffer), + "HW target: F%d\nFW target: " TARGET, + furi_hal_version_get_hw_target()); + popup_set_context(popup, desktop); + popup_set_header(popup, "!!!! HW Mismatch !!!!", 60, 14, AlignCenter, AlignCenter); + popup_set_text(popup, buffer, 60, 37, AlignCenter, AlignCenter); + popup_set_callback(popup, desktop_scene_hw_mismatch_callback); view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewHwMismatch); } @@ -20,7 +30,7 @@ bool desktop_scene_hw_mismatch_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { - case DesktopHwMismatchEventExit: + case HW_MISMATCH_BACK_EVENT: scene_manager_previous_scene(desktop->scene_manager); consumed = true; break; @@ -33,5 +43,10 @@ bool desktop_scene_hw_mismatch_on_event(void* context, SceneManagerEvent event) } void desktop_scene_hw_mismatch_on_exit(void* context) { - // Desktop* desktop = (Desktop*)context; + Desktop* desktop = (Desktop*)context; + Popup* popup = desktop->hw_mismatch_popup; + popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); + popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); + popup_set_callback(popup, NULL); + popup_set_context(popup, NULL); } diff --git a/applications/desktop/scenes/desktop_scene_main.c b/applications/desktop/scenes/desktop_scene_main.c index 05a5f258d..fab3a91ed 100644 --- a/applications/desktop/scenes/desktop_scene_main.c +++ b/applications/desktop/scenes/desktop_scene_main.c @@ -59,7 +59,7 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) { break; case DesktopMainEventOpenDebug: - scene_manager_next_scene(desktop->scene_manager, DesktopViewDebug); + scene_manager_next_scene(desktop->scene_manager, DesktopSceneDebug); consumed = true; break; diff --git a/applications/desktop/views/desktop_hw_mismatch.c b/applications/desktop/views/desktop_hw_mismatch.c deleted file mode 100644 index bf58d8f96..000000000 --- a/applications/desktop/views/desktop_hw_mismatch.c +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include "../desktop_i.h" -#include -#include - -#include "desktop_hw_mismatch.h" - -void desktop_hw_mismatch_set_callback( - DesktopHwMismatchView* main_view, - DesktopHwMismatchViewCallback callback, - void* context) { - furi_assert(main_view); - furi_assert(callback); - main_view->callback = callback; - main_view->context = context; -} - -void desktop_hw_mismatch_render(Canvas* canvas, void* model) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_set_font(canvas, FontPrimary); - canvas_draw_str(canvas, 2, 15, "!!!! HW Mismatch !!!!"); - - char buffer[64]; - canvas_set_font(canvas, FontSecondary); - snprintf(buffer, 64, "HW target: F%d", furi_hal_version_get_hw_target()); - canvas_draw_str(canvas, 5, 27, buffer); - canvas_draw_str(canvas, 5, 38, "FW target: " TARGET); -} - -View* desktop_hw_mismatch_get_view(DesktopHwMismatchView* hw_mismatch_view) { - furi_assert(hw_mismatch_view); - return hw_mismatch_view->view; -} - -bool desktop_hw_mismatch_input(InputEvent* event, void* context) { - furi_assert(event); - furi_assert(context); - - DesktopHwMismatchView* hw_mismatch_view = context; - - if(event->type == InputTypeShort) { - hw_mismatch_view->callback(DesktopHwMismatchEventExit, hw_mismatch_view->context); - } - - return true; -} - -DesktopHwMismatchView* desktop_hw_mismatch_alloc() { - DesktopHwMismatchView* hw_mismatch_view = furi_alloc(sizeof(DesktopHwMismatchView)); - hw_mismatch_view->view = view_alloc(); - view_allocate_model( - hw_mismatch_view->view, ViewModelTypeLocking, sizeof(DesktopHwMismatchViewModel)); - view_set_context(hw_mismatch_view->view, hw_mismatch_view); - view_set_draw_callback(hw_mismatch_view->view, (ViewDrawCallback)desktop_hw_mismatch_render); - view_set_input_callback(hw_mismatch_view->view, desktop_hw_mismatch_input); - - return hw_mismatch_view; -} - -void desktop_hw_mismatch_free(DesktopHwMismatchView* hw_mismatch_view) { - furi_assert(hw_mismatch_view); - - view_free(hw_mismatch_view->view); - free(hw_mismatch_view); -} diff --git a/applications/desktop/views/desktop_hw_mismatch.h b/applications/desktop/views/desktop_hw_mismatch.h deleted file mode 100644 index 680423412..000000000 --- a/applications/desktop/views/desktop_hw_mismatch.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -typedef enum { - DesktopHwMismatchEventExit, -} DesktopHwMismatchEvent; - -typedef struct DesktopHwMismatchView DesktopHwMismatchView; - -typedef void (*DesktopHwMismatchViewCallback)(DesktopHwMismatchEvent event, void* context); - -struct DesktopHwMismatchView { - View* view; - DesktopHwMismatchViewCallback callback; - void* context; -}; - -typedef struct { - IconAnimation* animation; - uint8_t scene_num; - uint8_t hint_timeout; - bool locked; -} DesktopHwMismatchViewModel; - -void desktop_hw_mismatch_set_callback( - DesktopHwMismatchView* hw_mismatch_view, - DesktopHwMismatchViewCallback callback, - void* context); - -View* desktop_hw_mismatch_get_view(DesktopHwMismatchView* hw_mismatch_view); - -DesktopHwMismatchView* desktop_hw_mismatch_alloc(); -void desktop_hw_mismatch_free(DesktopHwMismatchView* hw_mismatch_view); diff --git a/applications/desktop/views/desktop_lock_menu.c b/applications/desktop/views/desktop_lock_menu.c index 5bb065d6b..11392cd89 100644 --- a/applications/desktop/views/desktop_lock_menu.c +++ b/applications/desktop/views/desktop_lock_menu.c @@ -29,7 +29,7 @@ static void lock_menu_callback(void* context, uint8_t index) { default: // wip message with_view_model( lock_menu->view, (DesktopLockMenuViewModel * model) { - model->hint_timeout = HINT_TIMEOUT_L; + model->hint_timeout = HINT_TIMEOUT; return true; }); break; diff --git a/applications/desktop/views/desktop_lock_menu.h b/applications/desktop/views/desktop_lock_menu.h index d851bf91f..714069cbb 100644 --- a/applications/desktop/views/desktop_lock_menu.h +++ b/applications/desktop/views/desktop_lock_menu.h @@ -6,6 +6,8 @@ #include #include +#define HINT_TIMEOUT 2 + typedef enum { DesktopLockMenuEventLock, DesktopLockMenuEventUnlock, @@ -25,7 +27,6 @@ struct DesktopLockMenuView { typedef struct { uint8_t idx; uint8_t hint_timeout; - bool locked; } DesktopLockMenuViewModel; void desktop_lock_menu_set_callback( diff --git a/applications/desktop/views/desktop_locked.c b/applications/desktop/views/desktop_locked.c index 801409009..4e37fe190 100644 --- a/applications/desktop/views/desktop_locked.c +++ b/applications/desktop/views/desktop_locked.c @@ -33,7 +33,7 @@ static void desktop_locked_set_scene(DesktopLockedView* locked_view, const Icon* void desktop_locked_update_hint_timeout(DesktopLockedView* locked_view) { with_view_model( locked_view->view, (DesktopLockedViewModel * model) { - model->hint_timeout = HINT_TIMEOUT_H; + model->hint_expire_at = osKernelGetTickCount() + osKernelGetTickFreq(); return true; }); } @@ -59,7 +59,10 @@ void desktop_locked_manage_redraw(DesktopLockedView* locked_view) { if(!model->animation_seq_end) { model->door_left_x = CLAMP(model->door_left_x + 5, 0, -57); model->door_right_x = CLAMP(model->door_right_x - 5, 115, 60); + } else { + model->hint_expire_at = 0; } + return true; }); @@ -74,7 +77,7 @@ void desktop_locked_reset_counter(DesktopLockedView* locked_view) { with_view_model( locked_view->view, (DesktopLockedViewModel * model) { - model->hint_timeout = 0; + model->hint_expire_at = 0; return true; }); } @@ -94,12 +97,11 @@ void desktop_locked_render(Canvas* canvas, void* model) { canvas_draw_icon_animation(canvas, 0, -3, m->animation); } - if(m->hint_timeout) { - m->hint_timeout--; - + if(osKernelGetTickCount() < m->hint_expire_at) { if(!m->animation_seq_end) { canvas_set_font(canvas, FontPrimary); elements_multiline_text_framed(canvas, 42, 30, "Locked"); + } else { canvas_set_font(canvas, FontSecondary); canvas_draw_icon(canvas, 13, 5, &I_LockPopup_100x49); @@ -119,11 +121,7 @@ bool desktop_locked_input(InputEvent* event, void* context) { DesktopLockedView* locked_view = context; if(event->type == InputTypeShort) { - with_view_model( - locked_view->view, (DesktopLockedViewModel * model) { - model->hint_timeout = HINT_TIMEOUT_L; - return true; - }); + desktop_locked_update_hint_timeout(locked_view); if(event->key == InputKeyBack) { uint32_t press_time = HAL_GetTick(); @@ -159,6 +157,7 @@ void desktop_locked_enter(void* context) { void desktop_locked_exit(void* context) { DesktopLockedView* locked_view = context; + with_view_model( locked_view->view, (DesktopLockedViewModel * model) { if(model->animation) icon_animation_stop(model->animation); diff --git a/applications/desktop/views/desktop_locked.h b/applications/desktop/views/desktop_locked.h index bf8db3920..cfc3c080c 100644 --- a/applications/desktop/views/desktop_locked.h +++ b/applications/desktop/views/desktop_locked.h @@ -30,10 +30,11 @@ struct DesktopLockedView { typedef struct { IconAnimation* animation; + uint32_t hint_expire_at; + uint8_t scene_num; int8_t door_left_x; int8_t door_right_x; - uint8_t hint_timeout; bool animation_seq_end; } DesktopLockedViewModel;