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:
@@ -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
|
||||
with_view_model(
|
||||
lock_menu->view, (DesktopLockMenuViewModel * model) {
|
||||
model->hint_timeout = HINT_TIMEOUT_L;
|
||||
model->hint_timeout = HINT_TIMEOUT;
|
||||
return true;
|
||||
});
|
||||
break;
|
||||
|
@@ -6,6 +6,8 @@
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
|
||||
#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(
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user