Desktop: locked view timeout refactoring, Switch hwmismatch custom view to popup (#744)
Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
parent
832fb1b795
commit
73a13f584f
@ -40,7 +40,7 @@ Desktop* desktop_alloc() {
|
|||||||
desktop->locked_view = desktop_locked_alloc();
|
desktop->locked_view = desktop_locked_alloc();
|
||||||
desktop->debug_view = desktop_debug_alloc();
|
desktop->debug_view = desktop_debug_alloc();
|
||||||
desktop->first_start_view = desktop_first_start_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(
|
view_dispatcher_add_view(
|
||||||
desktop->view_dispatcher, DesktopViewMain, desktop_main_get_view(desktop->main_view));
|
desktop->view_dispatcher, DesktopViewMain, desktop_main_get_view(desktop->main_view));
|
||||||
@ -61,7 +61,7 @@ Desktop* desktop_alloc() {
|
|||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
desktop->view_dispatcher,
|
desktop->view_dispatcher,
|
||||||
DesktopViewHwMismatch,
|
DesktopViewHwMismatch,
|
||||||
desktop_hw_mismatch_get_view(desktop->hw_mismatch_view));
|
popup_get_view(desktop->hw_mismatch_popup));
|
||||||
|
|
||||||
// Lock icon
|
// Lock icon
|
||||||
desktop->lock_viewport = view_port_alloc();
|
desktop->lock_viewport = view_port_alloc();
|
||||||
@ -91,7 +91,7 @@ void desktop_free(Desktop* desktop) {
|
|||||||
desktop_locked_free(desktop->locked_view);
|
desktop_locked_free(desktop->locked_view);
|
||||||
desktop_debug_free(desktop->debug_view);
|
desktop_debug_free(desktop->debug_view);
|
||||||
desktop_first_start_free(desktop->first_start_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");
|
furi_record_close("gui");
|
||||||
desktop->gui = NULL;
|
desktop->gui = NULL;
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <gui/view_dispatcher.h>
|
#include <gui/view_dispatcher.h>
|
||||||
|
#include <gui/modules/popup.h>
|
||||||
#include <gui/scene_manager.h>
|
#include <gui/scene_manager.h>
|
||||||
#include <assets_icons.h>
|
#include <assets_icons.h>
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
|
|
||||||
#include "views/desktop_main.h"
|
#include "views/desktop_main.h"
|
||||||
#include "views/desktop_first_start.h"
|
#include "views/desktop_first_start.h"
|
||||||
#include "views/desktop_hw_mismatch.h"
|
|
||||||
#include "views/desktop_lock_menu.h"
|
#include "views/desktop_lock_menu.h"
|
||||||
#include "views/desktop_locked.h"
|
#include "views/desktop_locked.h"
|
||||||
#include "views/desktop_debug.h"
|
#include "views/desktop_debug.h"
|
||||||
@ -22,9 +22,6 @@
|
|||||||
|
|
||||||
#include "desktop/desktop_settings/desktop_settings.h"
|
#include "desktop/desktop_settings/desktop_settings.h"
|
||||||
|
|
||||||
#define HINT_TIMEOUT_L 2
|
|
||||||
#define HINT_TIMEOUT_H 11
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DesktopViewMain,
|
DesktopViewMain,
|
||||||
DesktopViewLockMenu,
|
DesktopViewLockMenu,
|
||||||
@ -44,7 +41,7 @@ struct Desktop {
|
|||||||
SceneManager* scene_manager;
|
SceneManager* scene_manager;
|
||||||
|
|
||||||
DesktopFirstStartView* first_start_view;
|
DesktopFirstStartView* first_start_view;
|
||||||
DesktopHwMismatchView* hw_mismatch_view;
|
Popup* hw_mismatch_popup;
|
||||||
DesktopMainView* main_view;
|
DesktopMainView* main_view;
|
||||||
DesktopLockMenuView* lock_menu;
|
DesktopLockMenuView* lock_menu;
|
||||||
DesktopLockedView* locked_view;
|
DesktopLockedView* locked_view;
|
||||||
|
@ -1,16 +1,26 @@
|
|||||||
#include "../desktop_i.h"
|
#include "../desktop_i.h"
|
||||||
#include "../views/desktop_hw_mismatch.h"
|
#include <furi-hal-version.h>
|
||||||
|
|
||||||
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;
|
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) {
|
void desktop_scene_hw_mismatch_on_enter(void* context) {
|
||||||
Desktop* desktop = (Desktop*)context;
|
Desktop* desktop = (Desktop*)context;
|
||||||
|
Popup* popup = desktop->hw_mismatch_popup;
|
||||||
desktop_hw_mismatch_set_callback(
|
char buffer[256]; // strange but smaller buffer not making it
|
||||||
desktop->hw_mismatch_view, desktop_scene_hw_mismatch_callback, desktop);
|
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);
|
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) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
switch(event.event) {
|
switch(event.event) {
|
||||||
case DesktopHwMismatchEventExit:
|
case HW_MISMATCH_BACK_EVENT:
|
||||||
scene_manager_previous_scene(desktop->scene_manager);
|
scene_manager_previous_scene(desktop->scene_manager);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DesktopMainEventOpenDebug:
|
case DesktopMainEventOpenDebug:
|
||||||
scene_manager_next_scene(desktop->scene_manager, DesktopViewDebug);
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneDebug);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
#include <furi.h>
|
|
||||||
#include "../desktop_i.h"
|
|
||||||
#include <furi-hal.h>
|
|
||||||
#include <furi-hal-version.h>
|
|
||||||
|
|
||||||
#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);
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <gui/gui_i.h>
|
|
||||||
#include <gui/view.h>
|
|
||||||
#include <gui/canvas.h>
|
|
||||||
#include <gui/elements.h>
|
|
||||||
#include <furi.h>
|
|
||||||
|
|
||||||
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);
|
|
@ -29,7 +29,7 @@ static void lock_menu_callback(void* context, uint8_t index) {
|
|||||||
default: // wip message
|
default: // wip message
|
||||||
with_view_model(
|
with_view_model(
|
||||||
lock_menu->view, (DesktopLockMenuViewModel * model) {
|
lock_menu->view, (DesktopLockMenuViewModel * model) {
|
||||||
model->hint_timeout = HINT_TIMEOUT_L;
|
model->hint_timeout = HINT_TIMEOUT;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
|
||||||
|
#define HINT_TIMEOUT 2
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DesktopLockMenuEventLock,
|
DesktopLockMenuEventLock,
|
||||||
DesktopLockMenuEventUnlock,
|
DesktopLockMenuEventUnlock,
|
||||||
@ -25,7 +27,6 @@ struct DesktopLockMenuView {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t idx;
|
uint8_t idx;
|
||||||
uint8_t hint_timeout;
|
uint8_t hint_timeout;
|
||||||
bool locked;
|
|
||||||
} DesktopLockMenuViewModel;
|
} DesktopLockMenuViewModel;
|
||||||
|
|
||||||
void desktop_lock_menu_set_callback(
|
void desktop_lock_menu_set_callback(
|
||||||
|
@ -33,7 +33,7 @@ static void desktop_locked_set_scene(DesktopLockedView* locked_view, const Icon*
|
|||||||
void desktop_locked_update_hint_timeout(DesktopLockedView* locked_view) {
|
void desktop_locked_update_hint_timeout(DesktopLockedView* locked_view) {
|
||||||
with_view_model(
|
with_view_model(
|
||||||
locked_view->view, (DesktopLockedViewModel * model) {
|
locked_view->view, (DesktopLockedViewModel * model) {
|
||||||
model->hint_timeout = HINT_TIMEOUT_H;
|
model->hint_expire_at = osKernelGetTickCount() + osKernelGetTickFreq();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -59,7 +59,10 @@ void desktop_locked_manage_redraw(DesktopLockedView* locked_view) {
|
|||||||
if(!model->animation_seq_end) {
|
if(!model->animation_seq_end) {
|
||||||
model->door_left_x = CLAMP(model->door_left_x + 5, 0, -57);
|
model->door_left_x = CLAMP(model->door_left_x + 5, 0, -57);
|
||||||
model->door_right_x = CLAMP(model->door_right_x - 5, 115, 60);
|
model->door_right_x = CLAMP(model->door_right_x - 5, 115, 60);
|
||||||
|
} else {
|
||||||
|
model->hint_expire_at = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -74,7 +77,7 @@ void desktop_locked_reset_counter(DesktopLockedView* locked_view) {
|
|||||||
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
locked_view->view, (DesktopLockedViewModel * model) {
|
locked_view->view, (DesktopLockedViewModel * model) {
|
||||||
model->hint_timeout = 0;
|
model->hint_expire_at = 0;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -94,12 +97,11 @@ void desktop_locked_render(Canvas* canvas, void* model) {
|
|||||||
canvas_draw_icon_animation(canvas, 0, -3, m->animation);
|
canvas_draw_icon_animation(canvas, 0, -3, m->animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m->hint_timeout) {
|
if(osKernelGetTickCount() < m->hint_expire_at) {
|
||||||
m->hint_timeout--;
|
|
||||||
|
|
||||||
if(!m->animation_seq_end) {
|
if(!m->animation_seq_end) {
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
elements_multiline_text_framed(canvas, 42, 30, "Locked");
|
elements_multiline_text_framed(canvas, 42, 30, "Locked");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_icon(canvas, 13, 5, &I_LockPopup_100x49);
|
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;
|
DesktopLockedView* locked_view = context;
|
||||||
if(event->type == InputTypeShort) {
|
if(event->type == InputTypeShort) {
|
||||||
with_view_model(
|
desktop_locked_update_hint_timeout(locked_view);
|
||||||
locked_view->view, (DesktopLockedViewModel * model) {
|
|
||||||
model->hint_timeout = HINT_TIMEOUT_L;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if(event->key == InputKeyBack) {
|
if(event->key == InputKeyBack) {
|
||||||
uint32_t press_time = HAL_GetTick();
|
uint32_t press_time = HAL_GetTick();
|
||||||
@ -159,6 +157,7 @@ void desktop_locked_enter(void* context) {
|
|||||||
|
|
||||||
void desktop_locked_exit(void* context) {
|
void desktop_locked_exit(void* context) {
|
||||||
DesktopLockedView* locked_view = context;
|
DesktopLockedView* locked_view = context;
|
||||||
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
locked_view->view, (DesktopLockedViewModel * model) {
|
locked_view->view, (DesktopLockedViewModel * model) {
|
||||||
if(model->animation) icon_animation_stop(model->animation);
|
if(model->animation) icon_animation_stop(model->animation);
|
||||||
|
@ -30,10 +30,11 @@ struct DesktopLockedView {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IconAnimation* animation;
|
IconAnimation* animation;
|
||||||
|
uint32_t hint_expire_at;
|
||||||
|
|
||||||
uint8_t scene_num;
|
uint8_t scene_num;
|
||||||
int8_t door_left_x;
|
int8_t door_left_x;
|
||||||
int8_t door_right_x;
|
int8_t door_right_x;
|
||||||
uint8_t hint_timeout;
|
|
||||||
bool animation_seq_end;
|
bool animation_seq_end;
|
||||||
|
|
||||||
} DesktopLockedViewModel;
|
} DesktopLockedViewModel;
|
||||||
|
Loading…
Reference in New Issue
Block a user