[FL-1824] Dolphin refactoring (#701)
* refactoring p1 * refactoring p2 * cleanups * locked screen refresh rate fix * better locked view logic * seperate dolphin service and desktop app * Desktop: Favorite app acess (Left key), Settings app * Desktop settings version, submenu header * remove unused icon anomation + naming fix Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
166
applications/desktop/views/desktop_debug.c
Normal file
166
applications/desktop/views/desktop_debug.c
Normal file
@@ -0,0 +1,166 @@
|
||||
#include <furi.h>
|
||||
#include "../desktop_i.h"
|
||||
#include "desktop_debug.h"
|
||||
|
||||
#include "applications/dolphin/helpers/dolphin_state.h"
|
||||
#include "applications/dolphin/dolphin.h"
|
||||
|
||||
void desktop_debug_set_callback(
|
||||
DesktopDebugView* debug_view,
|
||||
DesktopDebugViewCallback callback,
|
||||
void* context) {
|
||||
furi_assert(debug_view);
|
||||
furi_assert(callback);
|
||||
debug_view->callback = callback;
|
||||
debug_view->context = context;
|
||||
}
|
||||
|
||||
void desktop_debug_render(Canvas* canvas, void* model) {
|
||||
canvas_clear(canvas);
|
||||
DesktopDebugViewModel* m = model;
|
||||
const Version* ver;
|
||||
char buffer[64];
|
||||
|
||||
static const char* headers[] = {"FW Version info:", "Boot Version info:", "Desktop info:"};
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 13, headers[m->screen]);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
if(m->screen != DesktopViewStatsMeta) {
|
||||
// Hardware version
|
||||
const char* my_name = furi_hal_version_get_name_ptr();
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"HW: %d.F%dB%dC%d %s",
|
||||
furi_hal_version_get_hw_version(),
|
||||
furi_hal_version_get_hw_target(),
|
||||
furi_hal_version_get_hw_body(),
|
||||
furi_hal_version_get_hw_connect(),
|
||||
my_name ? my_name : "Unknown");
|
||||
canvas_draw_str(canvas, 5, 23, buffer);
|
||||
|
||||
ver = m->screen == DesktopViewStatsBoot ? furi_hal_version_get_boot_version() :
|
||||
furi_hal_version_get_firmware_version();
|
||||
|
||||
if(!ver) {
|
||||
canvas_draw_str(canvas, 5, 33, "No info");
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%s [%s]",
|
||||
version_get_version(ver),
|
||||
version_get_builddate(ver));
|
||||
canvas_draw_str(canvas, 5, 33, buffer);
|
||||
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%s [%s]",
|
||||
version_get_githash(ver),
|
||||
version_get_gitbranchnum(ver));
|
||||
canvas_draw_str(canvas, 5, 43, buffer);
|
||||
|
||||
snprintf(
|
||||
buffer, sizeof(buffer), "[%s] %s", version_get_target(ver), version_get_gitbranch(ver));
|
||||
canvas_draw_str(canvas, 5, 53, buffer);
|
||||
|
||||
} else {
|
||||
char buffer[64];
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
snprintf(buffer, 64, "Icounter: %ld", m->icounter);
|
||||
canvas_draw_str(canvas, 5, 30, buffer);
|
||||
snprintf(buffer, 64, "Butthurt: %ld", m->butthurt);
|
||||
canvas_draw_str(canvas, 5, 40, buffer);
|
||||
canvas_draw_str(canvas, 0, 53, "[< >] icounter value [ok] save");
|
||||
}
|
||||
}
|
||||
|
||||
View* desktop_debug_get_view(DesktopDebugView* debug_view) {
|
||||
furi_assert(debug_view);
|
||||
return debug_view->view;
|
||||
}
|
||||
|
||||
bool desktop_debug_input(InputEvent* event, void* context) {
|
||||
furi_assert(event);
|
||||
furi_assert(context);
|
||||
|
||||
DesktopDebugView* debug_view = context;
|
||||
|
||||
if(event->type != InputTypeShort) return false;
|
||||
DesktopViewStatsScreens current = 0;
|
||||
with_view_model(
|
||||
debug_view->view, (DesktopDebugViewModel * model) {
|
||||
if(event->key == InputKeyDown) {
|
||||
model->screen = (model->screen + 1) % DesktopViewStatsTotalCount;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
model->screen = ((model->screen - 1) + DesktopViewStatsTotalCount) %
|
||||
DesktopViewStatsTotalCount;
|
||||
}
|
||||
current = model->screen;
|
||||
return true;
|
||||
});
|
||||
|
||||
if(current == DesktopViewStatsMeta) {
|
||||
if(event->key == InputKeyLeft) {
|
||||
debug_view->callback(DesktopDebugEventWrongDeed, debug_view->context);
|
||||
} else if(event->key == InputKeyRight) {
|
||||
debug_view->callback(DesktopDebugEventDeed, debug_view->context);
|
||||
} else if(event->key == InputKeyOk) {
|
||||
debug_view->callback(DesktopDebugEventSaveState, debug_view->context);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
debug_view->callback(DesktopDebugEventExit, debug_view->context);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DesktopDebugView* desktop_debug_alloc() {
|
||||
DesktopDebugView* debug_view = furi_alloc(sizeof(DesktopDebugView));
|
||||
debug_view->view = view_alloc();
|
||||
view_allocate_model(debug_view->view, ViewModelTypeLocking, sizeof(DesktopDebugViewModel));
|
||||
view_set_context(debug_view->view, debug_view);
|
||||
view_set_draw_callback(debug_view->view, (ViewDrawCallback)desktop_debug_render);
|
||||
view_set_input_callback(debug_view->view, desktop_debug_input);
|
||||
|
||||
return debug_view;
|
||||
}
|
||||
|
||||
void desktop_debug_free(DesktopDebugView* debug_view) {
|
||||
furi_assert(debug_view);
|
||||
|
||||
view_free(debug_view->view);
|
||||
free(debug_view);
|
||||
}
|
||||
|
||||
void desktop_debug_get_dolphin_data(DesktopDebugView* debug_view) {
|
||||
Dolphin* dolphin = furi_record_open("dolphin");
|
||||
DolphinDeedWeight stats = dolphin_stats(dolphin);
|
||||
with_view_model(
|
||||
debug_view->view, (DesktopDebugViewModel * model) {
|
||||
model->icounter = stats.icounter;
|
||||
model->butthurt = stats.butthurt;
|
||||
return true;
|
||||
});
|
||||
|
||||
furi_record_close("dolphin");
|
||||
}
|
||||
|
||||
void desktop_debug_reset_screen_idx(DesktopDebugView* debug_view) {
|
||||
with_view_model(
|
||||
debug_view->view, (DesktopDebugViewModel * model) {
|
||||
model->screen = 0;
|
||||
return true;
|
||||
});
|
||||
}
|
52
applications/desktop/views/desktop_debug.h
Normal file
52
applications/desktop/views/desktop_debug.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui_i.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
typedef enum {
|
||||
DesktopDebugEventDeed,
|
||||
DesktopDebugEventWrongDeed,
|
||||
DesktopDebugEventSaveState,
|
||||
DesktopDebugEventExit,
|
||||
} DesktopDebugEvent;
|
||||
|
||||
typedef struct DesktopDebugView DesktopDebugView;
|
||||
|
||||
typedef void (*DesktopDebugViewCallback)(DesktopDebugEvent event, void* context);
|
||||
|
||||
// Debug info
|
||||
typedef enum {
|
||||
DesktopViewStatsFw,
|
||||
DesktopViewStatsBoot,
|
||||
DesktopViewStatsMeta,
|
||||
DesktopViewStatsTotalCount,
|
||||
} DesktopViewStatsScreens;
|
||||
|
||||
struct DesktopDebugView {
|
||||
View* view;
|
||||
DesktopDebugViewCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t icounter;
|
||||
uint32_t butthurt;
|
||||
DesktopViewStatsScreens screen;
|
||||
} DesktopDebugViewModel;
|
||||
|
||||
void desktop_debug_set_callback(
|
||||
DesktopDebugView* debug_view,
|
||||
DesktopDebugViewCallback callback,
|
||||
void* context);
|
||||
|
||||
View* desktop_debug_get_view(DesktopDebugView* debug_view);
|
||||
|
||||
DesktopDebugView* desktop_debug_alloc();
|
||||
void desktop_debug_free(DesktopDebugView* debug_view);
|
||||
|
||||
void desktop_debug_get_dolphin_data(DesktopDebugView* debug_view);
|
||||
void desktop_debug_reset_screen_idx(DesktopDebugView* debug_view);
|
107
applications/desktop/views/desktop_first_start.c
Normal file
107
applications/desktop/views/desktop_first_start.c
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <furi.h>
|
||||
#include "../desktop_i.h"
|
||||
#include "desktop_first_start.h"
|
||||
|
||||
void desktop_first_start_set_callback(
|
||||
DesktopFirstStartView* first_start_view,
|
||||
DesktopFirstStartViewCallback callback,
|
||||
void* context) {
|
||||
furi_assert(first_start_view);
|
||||
furi_assert(callback);
|
||||
first_start_view->callback = callback;
|
||||
first_start_view->context = context;
|
||||
}
|
||||
|
||||
void desktop_first_start_render(Canvas* canvas, void* model) {
|
||||
DesktopFirstStartViewModel* m = model;
|
||||
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
uint8_t width = canvas_width(canvas);
|
||||
uint8_t height = canvas_height(canvas);
|
||||
const char* my_name = furi_hal_version_get_name_ptr();
|
||||
if(m->page == 0) {
|
||||
canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart0_70x53);
|
||||
elements_multiline_text_framed(canvas, 75, 20, "Hey m8,\npress > to\ncontinue");
|
||||
} else if(m->page == 1) {
|
||||
canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart1_59x53);
|
||||
elements_multiline_text_framed(canvas, 64, 20, "First Of All,\n... >");
|
||||
} else if(m->page == 2) {
|
||||
canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart2_59x51);
|
||||
elements_multiline_text_framed(canvas, 64, 20, "Thank you\nfor your\nsupport! >");
|
||||
} else if(m->page == 3) {
|
||||
canvas_draw_icon(canvas, width - 57, height - 48, &I_DolphinFirstStart3_57x48);
|
||||
elements_multiline_text_framed(canvas, 0, 20, "Kickstarter\ncampaign\nwas INSANE! >");
|
||||
} else if(m->page == 4) {
|
||||
canvas_draw_icon(canvas, width - 67, height - 50, &I_DolphinFirstStart4_67x53);
|
||||
elements_multiline_text_framed(canvas, 0, 17, "Now\nallow me\nto introduce\nmyself >");
|
||||
} else if(m->page == 5) {
|
||||
char buf[64];
|
||||
snprintf(
|
||||
buf,
|
||||
64,
|
||||
"%s %s%s",
|
||||
"I am",
|
||||
my_name ? my_name : "Unknown",
|
||||
",\ncyberdesktop\nliving in your\npocket >");
|
||||
canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart5_54x49);
|
||||
elements_multiline_text_framed(canvas, 60, 17, buf);
|
||||
} else if(m->page == 6) {
|
||||
canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart6_58x54);
|
||||
elements_multiline_text_framed(
|
||||
canvas, 63, 17, "I can grow\nsmart'n'cool\nif you use me\noften >");
|
||||
} else if(m->page == 7) {
|
||||
canvas_draw_icon(canvas, width - 61, height - 48, &I_DolphinFirstStart7_61x51);
|
||||
elements_multiline_text_framed(
|
||||
canvas, 0, 17, "As long as\nyou read, write\nand emulate >");
|
||||
} else if(m->page == 8) {
|
||||
canvas_draw_icon(canvas, width - 56, height - 48, &I_DolphinFirstStart8_56x51);
|
||||
elements_multiline_text_framed(
|
||||
canvas, 0, 17, "You can check\nmy level and\nmood in the\nPassport menu");
|
||||
}
|
||||
}
|
||||
|
||||
View* desktop_first_start_get_view(DesktopFirstStartView* first_start_view) {
|
||||
furi_assert(first_start_view);
|
||||
return first_start_view->view;
|
||||
}
|
||||
|
||||
bool desktop_first_start_input(InputEvent* event, void* context) {
|
||||
furi_assert(event);
|
||||
DesktopFirstStartView* first_start_view = context;
|
||||
|
||||
if(event->type == InputTypeShort) {
|
||||
DesktopFirstStartViewModel* model = view_get_model(first_start_view->view);
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->page > 0) model->page--;
|
||||
} else if(event->key == InputKeyRight) {
|
||||
uint32_t page = ++model->page;
|
||||
if(page > 8) {
|
||||
first_start_view->callback(DesktopFirstStartCompleted, first_start_view->context);
|
||||
}
|
||||
}
|
||||
view_commit_model(first_start_view->view, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DesktopFirstStartView* desktop_first_start_alloc() {
|
||||
DesktopFirstStartView* first_start_view = furi_alloc(sizeof(DesktopFirstStartView));
|
||||
first_start_view->view = view_alloc();
|
||||
view_allocate_model(
|
||||
first_start_view->view, ViewModelTypeLocking, sizeof(DesktopFirstStartViewModel));
|
||||
view_set_context(first_start_view->view, first_start_view);
|
||||
view_set_draw_callback(first_start_view->view, (ViewDrawCallback)desktop_first_start_render);
|
||||
view_set_input_callback(first_start_view->view, desktop_first_start_input);
|
||||
|
||||
return first_start_view;
|
||||
}
|
||||
|
||||
void desktop_first_start_free(DesktopFirstStartView* first_start_view) {
|
||||
furi_assert(first_start_view);
|
||||
|
||||
view_free(first_start_view->view);
|
||||
free(first_start_view);
|
||||
}
|
35
applications/desktop/views/desktop_first_start.h
Normal file
35
applications/desktop/views/desktop_first_start.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui_i.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
|
||||
typedef enum {
|
||||
DesktopFirstStartCompleted,
|
||||
} DesktopFirstStartEvent;
|
||||
|
||||
typedef struct DesktopFirstStartView DesktopFirstStartView;
|
||||
|
||||
typedef void (*DesktopFirstStartViewCallback)(DesktopFirstStartEvent event, void* context);
|
||||
|
||||
struct DesktopFirstStartView {
|
||||
View* view;
|
||||
DesktopFirstStartViewCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t page;
|
||||
} DesktopFirstStartViewModel;
|
||||
|
||||
void desktop_first_start_set_callback(
|
||||
DesktopFirstStartView* main_view,
|
||||
DesktopFirstStartViewCallback callback,
|
||||
void* context);
|
||||
|
||||
View* desktop_first_start_get_view(DesktopFirstStartView* main_view);
|
||||
|
||||
DesktopFirstStartView* desktop_first_start_alloc();
|
||||
void desktop_first_start_free(DesktopFirstStartView* main_view);
|
66
applications/desktop/views/desktop_hw_mismatch.c
Normal file
66
applications/desktop/views/desktop_hw_mismatch.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#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);
|
||||
}
|
38
applications/desktop/views/desktop_hw_mismatch.h
Normal file
38
applications/desktop/views/desktop_hw_mismatch.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#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);
|
111
applications/desktop/views/desktop_lock_menu.c
Normal file
111
applications/desktop/views/desktop_lock_menu.c
Normal file
@@ -0,0 +1,111 @@
|
||||
#include <furi.h>
|
||||
#include "../desktop_i.h"
|
||||
#include "desktop_lock_menu.h"
|
||||
|
||||
void desktop_lock_menu_set_callback(
|
||||
DesktopLockMenuView* lock_menu,
|
||||
DesktopLockMenuViewCallback callback,
|
||||
void* context) {
|
||||
furi_assert(lock_menu);
|
||||
furi_assert(callback);
|
||||
lock_menu->callback = callback;
|
||||
lock_menu->context = context;
|
||||
}
|
||||
|
||||
void desktop_lock_menu_reset_idx(DesktopLockMenuView* lock_menu) {
|
||||
with_view_model(
|
||||
lock_menu->view, (DesktopLockMenuViewModel * model) {
|
||||
model->idx = 0;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static void lock_menu_callback(void* context, uint8_t index) {
|
||||
furi_assert(context);
|
||||
DesktopLockMenuView* lock_menu = context;
|
||||
switch(index) {
|
||||
case 0: // lock
|
||||
lock_menu->callback(DesktopLockMenuEventLock, lock_menu->context);
|
||||
default: // wip message
|
||||
with_view_model(
|
||||
lock_menu->view, (DesktopLockMenuViewModel * model) {
|
||||
model->hint_timeout = HINT_TIMEOUT_L;
|
||||
return true;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void desktop_lock_menu_render(Canvas* canvas, void* model) {
|
||||
const char* Lockmenu_Items[3] = {"Lock", "Set PIN", "DUMB mode"};
|
||||
|
||||
DesktopLockMenuViewModel* m = model;
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon(canvas, -57, 0, &I_DoorLeft_70x55);
|
||||
canvas_draw_icon(canvas, 115, 0, &I_DoorRight_70x55);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
for(uint8_t i = 0; i < 3; ++i) {
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
64,
|
||||
13 + (i * 17),
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
(m->hint_timeout && m->idx == i && m->idx) ? "Not implemented" : Lockmenu_Items[i]);
|
||||
if(m->idx == i) elements_frame(canvas, 15, 5 + (i * 17), 98, 15);
|
||||
}
|
||||
}
|
||||
|
||||
View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu) {
|
||||
furi_assert(lock_menu);
|
||||
return lock_menu->view;
|
||||
}
|
||||
|
||||
bool desktop_lock_menu_input(InputEvent* event, void* context) {
|
||||
furi_assert(event);
|
||||
furi_assert(context);
|
||||
|
||||
DesktopLockMenuView* lock_menu = context;
|
||||
uint8_t idx;
|
||||
|
||||
if(event->type != InputTypeShort) return false;
|
||||
with_view_model(
|
||||
lock_menu->view, (DesktopLockMenuViewModel * model) {
|
||||
model->hint_timeout = 0; // clear hint timeout
|
||||
if(event->key == InputKeyUp) {
|
||||
model->idx = CLAMP(model->idx - 1, 2, 0);
|
||||
} else if(event->key == InputKeyDown) {
|
||||
model->idx = CLAMP(model->idx + 1, 2, 0);
|
||||
}
|
||||
idx = model->idx;
|
||||
return true;
|
||||
});
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
lock_menu->callback(DesktopLockMenuEventExit, lock_menu->context);
|
||||
} else if(event->key == InputKeyOk) {
|
||||
lock_menu_callback(lock_menu, idx);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DesktopLockMenuView* desktop_lock_menu_alloc() {
|
||||
DesktopLockMenuView* lock_menu = furi_alloc(sizeof(DesktopLockMenuView));
|
||||
lock_menu->view = view_alloc();
|
||||
view_allocate_model(lock_menu->view, ViewModelTypeLocking, sizeof(DesktopLockMenuViewModel));
|
||||
view_set_context(lock_menu->view, lock_menu);
|
||||
view_set_draw_callback(lock_menu->view, (ViewDrawCallback)desktop_lock_menu_render);
|
||||
view_set_input_callback(lock_menu->view, desktop_lock_menu_input);
|
||||
|
||||
return lock_menu;
|
||||
}
|
||||
|
||||
void desktop_lock_menu_free(DesktopLockMenuView* lock_menu_view) {
|
||||
furi_assert(lock_menu_view);
|
||||
|
||||
view_free(lock_menu_view->view);
|
||||
free(lock_menu_view);
|
||||
}
|
39
applications/desktop/views/desktop_lock_menu.h
Normal file
39
applications/desktop/views/desktop_lock_menu.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui_i.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
|
||||
typedef enum {
|
||||
DesktopLockMenuEventLock,
|
||||
DesktopLockMenuEventUnlock,
|
||||
DesktopLockMenuEventExit,
|
||||
} DesktopLockMenuEvent;
|
||||
|
||||
typedef struct DesktopLockMenuView DesktopLockMenuView;
|
||||
|
||||
typedef void (*DesktopLockMenuViewCallback)(DesktopLockMenuEvent event, void* context);
|
||||
|
||||
struct DesktopLockMenuView {
|
||||
View* view;
|
||||
DesktopLockMenuViewCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t idx;
|
||||
uint8_t hint_timeout;
|
||||
bool locked;
|
||||
} DesktopLockMenuViewModel;
|
||||
|
||||
void desktop_lock_menu_set_callback(
|
||||
DesktopLockMenuView* lock_menu,
|
||||
DesktopLockMenuViewCallback callback,
|
||||
void* context);
|
||||
|
||||
View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu);
|
||||
void desktop_lock_menu_reset_idx(DesktopLockMenuView* lock_menu);
|
||||
DesktopLockMenuView* desktop_lock_menu_alloc();
|
||||
void desktop_lock_menu_free(DesktopLockMenuView* lock_menu);
|
171
applications/desktop/views/desktop_locked.c
Normal file
171
applications/desktop/views/desktop_locked.c
Normal file
@@ -0,0 +1,171 @@
|
||||
#include <furi.h>
|
||||
#include "../desktop_i.h"
|
||||
#include "desktop_locked.h"
|
||||
|
||||
static const Icon* idle_scenes[] = {&A_Wink_128x64, &A_WatchingTV_128x64};
|
||||
|
||||
void desktop_locked_set_callback(
|
||||
DesktopLockedView* locked_view,
|
||||
DesktopLockedViewCallback callback,
|
||||
void* context) {
|
||||
furi_assert(locked_view);
|
||||
furi_assert(callback);
|
||||
locked_view->callback = callback;
|
||||
locked_view->context = context;
|
||||
}
|
||||
|
||||
void locked_view_timer_callback(void* context) {
|
||||
DesktopLockedView* locked_view = context;
|
||||
locked_view->callback(DesktopLockedEventUpdate, locked_view->context);
|
||||
}
|
||||
|
||||
// temporary locked screen animation managment
|
||||
static void
|
||||
desktop_scene_handler_set_scene(DesktopLockedView* locked_view, const Icon* icon_data) {
|
||||
with_view_model(
|
||||
locked_view->view, (DesktopLockedViewModel * model) {
|
||||
if(model->animation) icon_animation_free(model->animation);
|
||||
model->animation = icon_animation_alloc(icon_data);
|
||||
icon_animation_start(model->animation);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_locked_update_hint_timeout(DesktopLockedView* locked_view) {
|
||||
with_view_model(
|
||||
locked_view->view, (DesktopLockedViewModel * model) {
|
||||
model->hint_timeout = HINT_TIMEOUT_H;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_locked_reset_door_pos(DesktopLockedView* locked_view) {
|
||||
with_view_model(
|
||||
locked_view->view, (DesktopLockedViewModel * model) {
|
||||
model->animation_seq_end = false;
|
||||
model->door_left_x = -57;
|
||||
model->door_right_x = 115;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_locked_manage_redraw(DesktopLockedView* locked_view) {
|
||||
bool animation_seq_end;
|
||||
|
||||
with_view_model(
|
||||
locked_view->view, (DesktopLockedViewModel * model) {
|
||||
model->animation_seq_end = !model->door_left_x;
|
||||
animation_seq_end = model->animation_seq_end;
|
||||
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if(animation_seq_end) {
|
||||
osTimerStop(locked_view->timer);
|
||||
}
|
||||
}
|
||||
|
||||
void desktop_locked_reset_counter(DesktopLockedView* locked_view) {
|
||||
locked_view->lock_count = 0;
|
||||
locked_view->lock_lastpress = 0;
|
||||
|
||||
with_view_model(
|
||||
locked_view->view, (DesktopLockedViewModel * model) {
|
||||
model->hint_timeout = 0;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_locked_render(Canvas* canvas, void* model) {
|
||||
DesktopLockedViewModel* m = model;
|
||||
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(!m->animation_seq_end) {
|
||||
canvas_draw_icon(canvas, m->door_left_x, 0, &I_DoorLeft_70x55);
|
||||
canvas_draw_icon(canvas, m->door_right_x, 0, &I_DoorRight_70x55);
|
||||
}
|
||||
|
||||
if(m->animation && m->animation_seq_end) {
|
||||
canvas_draw_icon_animation(canvas, 0, -3, m->animation);
|
||||
}
|
||||
|
||||
if(m->hint_timeout) {
|
||||
m->hint_timeout--;
|
||||
|
||||
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);
|
||||
elements_multiline_text(canvas, 65, 20, "To unlock\npress:");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
View* desktop_locked_get_view(DesktopLockedView* locked_view) {
|
||||
furi_assert(locked_view);
|
||||
return locked_view->view;
|
||||
}
|
||||
|
||||
bool desktop_locked_input(InputEvent* event, void* context) {
|
||||
furi_assert(event);
|
||||
furi_assert(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;
|
||||
});
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
uint32_t press_time = HAL_GetTick();
|
||||
|
||||
// check if pressed sequentially
|
||||
if(press_time - locked_view->lock_lastpress > UNLOCK_RST_TIMEOUT) {
|
||||
locked_view->lock_lastpress = press_time;
|
||||
locked_view->lock_count = 0;
|
||||
} else if(press_time - locked_view->lock_lastpress < UNLOCK_RST_TIMEOUT) {
|
||||
locked_view->lock_lastpress = press_time;
|
||||
locked_view->lock_count++;
|
||||
}
|
||||
|
||||
if(locked_view->lock_count == UNLOCK_CNT) {
|
||||
locked_view->lock_count = 0;
|
||||
locked_view->callback(DesktopLockedEventUnlock, locked_view->context);
|
||||
}
|
||||
}
|
||||
}
|
||||
// All events consumed
|
||||
return true;
|
||||
}
|
||||
|
||||
DesktopLockedView* desktop_locked_alloc() {
|
||||
DesktopLockedView* locked_view = furi_alloc(sizeof(DesktopLockedView));
|
||||
locked_view->view = view_alloc();
|
||||
locked_view->timer =
|
||||
osTimerNew(locked_view_timer_callback, osTimerPeriodic, locked_view, NULL);
|
||||
|
||||
view_allocate_model(locked_view->view, ViewModelTypeLocking, sizeof(DesktopLockedViewModel));
|
||||
view_set_context(locked_view->view, locked_view);
|
||||
view_set_draw_callback(locked_view->view, (ViewDrawCallback)desktop_locked_render);
|
||||
view_set_input_callback(locked_view->view, desktop_locked_input);
|
||||
|
||||
desktop_scene_handler_set_scene(locked_view, idle_scenes[random() % COUNT_OF(idle_scenes)]);
|
||||
return locked_view;
|
||||
}
|
||||
|
||||
void desktop_locked_free(DesktopLockedView* locked_view) {
|
||||
furi_assert(locked_view);
|
||||
osTimerDelete(locked_view->timer);
|
||||
view_free(locked_view->view);
|
||||
free(locked_view);
|
||||
}
|
55
applications/desktop/views/desktop_locked.h
Normal file
55
applications/desktop/views/desktop_locked.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui_i.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
|
||||
#define UNLOCK_RST_TIMEOUT 200
|
||||
#define UNLOCK_CNT 2 // 3 actually
|
||||
|
||||
typedef enum {
|
||||
DesktopLockedEventUnlock,
|
||||
DesktopLockedEventUpdate,
|
||||
} DesktopLockedEvent;
|
||||
|
||||
typedef struct DesktopLockedView DesktopLockedView;
|
||||
|
||||
typedef void (*DesktopLockedViewCallback)(DesktopLockedEvent event, void* context);
|
||||
|
||||
struct DesktopLockedView {
|
||||
View* view;
|
||||
DesktopLockedViewCallback callback;
|
||||
void* context;
|
||||
|
||||
osTimerId_t timer;
|
||||
uint8_t lock_count;
|
||||
uint32_t lock_lastpress;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
IconAnimation* animation;
|
||||
uint8_t scene_num;
|
||||
int8_t door_left_x;
|
||||
int8_t door_right_x;
|
||||
uint8_t hint_timeout;
|
||||
bool animation_seq_end;
|
||||
|
||||
} DesktopLockedViewModel;
|
||||
|
||||
void desktop_locked_set_callback(
|
||||
DesktopLockedView* locked_view,
|
||||
DesktopLockedViewCallback callback,
|
||||
void* context);
|
||||
|
||||
void desktop_locked_update_hint_timeout(DesktopLockedView* locked_view);
|
||||
void desktop_locked_reset_counter(DesktopLockedView* locked_view);
|
||||
void desktop_locked_reset_door_pos(DesktopLockedView* locked_view);
|
||||
void desktop_locked_manage_redraw(DesktopLockedView* locked_view);
|
||||
|
||||
View* desktop_locked_get_view(DesktopLockedView* locked_view);
|
||||
DesktopLockedView* desktop_locked_alloc();
|
||||
void desktop_locked_free(DesktopLockedView* locked_view);
|
||||
void desktop_main_unlocked(DesktopMainView* main_view);
|
||||
void desktop_main_reset_hint(DesktopMainView* main_view);
|
116
applications/desktop/views/desktop_main.c
Normal file
116
applications/desktop/views/desktop_main.c
Normal file
@@ -0,0 +1,116 @@
|
||||
#include <furi.h>
|
||||
#include "../desktop_i.h"
|
||||
#include "desktop_main.h"
|
||||
|
||||
static const Icon* idle_scenes[] = {&A_Wink_128x64, &A_WatchingTV_128x64};
|
||||
|
||||
void desktop_main_set_callback(
|
||||
DesktopMainView* main_view,
|
||||
DesktopMainViewCallback callback,
|
||||
void* context) {
|
||||
furi_assert(main_view);
|
||||
furi_assert(callback);
|
||||
main_view->callback = callback;
|
||||
main_view->context = context;
|
||||
}
|
||||
|
||||
void desktop_main_reset_hint(DesktopMainView* main_view) {
|
||||
with_view_model(
|
||||
main_view->view, (DesktopMainViewModel * model) {
|
||||
model->hint_timeout = 0;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
// temporary main screen animation managment
|
||||
void desktop_scene_handler_set_scene(DesktopMainView* main_view, const Icon* icon_data) {
|
||||
with_view_model(
|
||||
main_view->view, (DesktopMainViewModel * model) {
|
||||
if(model->animation) icon_animation_free(model->animation);
|
||||
model->animation = icon_animation_alloc(icon_data);
|
||||
icon_animation_start(model->animation);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_scene_handler_switch_scene(DesktopMainView* main_view) {
|
||||
with_view_model(
|
||||
main_view->view, (DesktopMainViewModel * model) {
|
||||
if(icon_animation_is_last_frame(model->animation)) {
|
||||
if(model->animation) icon_animation_free(model->animation);
|
||||
model->animation = icon_animation_alloc(idle_scenes[model->scene_num]);
|
||||
icon_animation_start(model->animation);
|
||||
model->scene_num = random() % COUNT_OF(idle_scenes);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_main_render(Canvas* canvas, void* model) {
|
||||
canvas_clear(canvas);
|
||||
DesktopMainViewModel* m = model;
|
||||
|
||||
if(m->animation) {
|
||||
canvas_draw_icon_animation(canvas, 0, -3, m->animation);
|
||||
}
|
||||
|
||||
if(m->unlocked && m->hint_timeout) {
|
||||
m->hint_timeout = CLAMP(m->hint_timeout - 1, 2, 0);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_framed(canvas, 42, 30, "Unlocked");
|
||||
}
|
||||
}
|
||||
|
||||
View* desktop_main_get_view(DesktopMainView* main_view) {
|
||||
furi_assert(main_view);
|
||||
return main_view->view;
|
||||
}
|
||||
|
||||
bool desktop_main_input(InputEvent* event, void* context) {
|
||||
furi_assert(event);
|
||||
furi_assert(context);
|
||||
|
||||
DesktopMainView* main_view = context;
|
||||
|
||||
if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
main_view->callback(DesktopMainEventOpenMenu, main_view->context);
|
||||
} else if(event->key == InputKeyDown && event->type == InputTypeLong) {
|
||||
main_view->callback(DesktopMainEventOpenDebug, main_view->context);
|
||||
} else if(event->key == InputKeyUp && event->type == InputTypeShort) {
|
||||
main_view->callback(DesktopMainEventOpenLockMenu, main_view->context);
|
||||
} else if(event->key == InputKeyDown && event->type == InputTypeShort) {
|
||||
main_view->callback(DesktopMainEventOpenArchive, main_view->context);
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
main_view->callback(DesktopMainEventOpenFavorite, main_view->context);
|
||||
}
|
||||
desktop_main_reset_hint(main_view);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DesktopMainView* desktop_main_alloc() {
|
||||
DesktopMainView* main_view = furi_alloc(sizeof(DesktopMainView));
|
||||
main_view->view = view_alloc();
|
||||
view_allocate_model(main_view->view, ViewModelTypeLocking, sizeof(DesktopMainViewModel));
|
||||
view_set_context(main_view->view, main_view);
|
||||
view_set_draw_callback(main_view->view, (ViewDrawCallback)desktop_main_render);
|
||||
view_set_input_callback(main_view->view, desktop_main_input);
|
||||
|
||||
desktop_scene_handler_set_scene(main_view, idle_scenes[random() % COUNT_OF(idle_scenes)]);
|
||||
|
||||
return main_view;
|
||||
}
|
||||
|
||||
void desktop_main_free(DesktopMainView* main_view) {
|
||||
furi_assert(main_view);
|
||||
view_free(main_view->view);
|
||||
free(main_view);
|
||||
}
|
||||
|
||||
void desktop_main_unlocked(DesktopMainView* main_view) {
|
||||
with_view_model(
|
||||
main_view->view, (DesktopMainViewModel * model) {
|
||||
model->unlocked = true;
|
||||
model->hint_timeout = 2;
|
||||
return true;
|
||||
});
|
||||
}
|
43
applications/desktop/views/desktop_main.h
Normal file
43
applications/desktop/views/desktop_main.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui_i.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
|
||||
typedef enum {
|
||||
DesktopMainEventOpenMenu,
|
||||
DesktopMainEventOpenLockMenu,
|
||||
DesktopMainEventOpenDebug,
|
||||
DesktopMainEventUnlocked,
|
||||
DesktopMainEventOpenArchive,
|
||||
DesktopMainEventOpenFavorite,
|
||||
} DesktopMainEvent;
|
||||
|
||||
typedef struct DesktopMainView DesktopMainView;
|
||||
|
||||
typedef void (*DesktopMainViewCallback)(DesktopMainEvent event, void* context);
|
||||
|
||||
struct DesktopMainView {
|
||||
View* view;
|
||||
DesktopMainViewCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
IconAnimation* animation;
|
||||
uint8_t scene_num;
|
||||
uint8_t hint_timeout;
|
||||
bool unlocked;
|
||||
} DesktopMainViewModel;
|
||||
|
||||
void desktop_main_set_callback(
|
||||
DesktopMainView* main_view,
|
||||
DesktopMainViewCallback callback,
|
||||
void* context);
|
||||
|
||||
View* desktop_main_get_view(DesktopMainView* main_view);
|
||||
|
||||
DesktopMainView* desktop_main_alloc();
|
||||
void desktop_main_free(DesktopMainView* main_view);
|
Reference in New Issue
Block a user