[FL-2815, FL-2821] Dummy mode (#1739)

* Dummy mode implementation
* dumb -> dummy
* F7: Add new api_symbols: game icon
* Starting snake game from dummy mode

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov 2022-09-19 16:03:42 +03:00 committed by GitHub
parent 3d3c422751
commit d80329b323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 216 additions and 113 deletions

View File

@ -270,7 +270,7 @@ void archive_file_array_load(ArchiveBrowserView* browser, int8_t dir) {
ArchiveFile_t* archive_get_current_file(ArchiveBrowserView* browser) { ArchiveFile_t* archive_get_current_file(ArchiveBrowserView* browser) {
furi_assert(browser); furi_assert(browser);
ArchiveFile_t* selected; ArchiveFile_t* selected = NULL;
with_view_model( with_view_model(
browser->view, (ArchiveBrowserViewModel * model) { browser->view, (ArchiveBrowserViewModel * model) {
selected = files_array_size(model->files) ? selected = files_array_size(model->files) ?
@ -284,7 +284,7 @@ ArchiveFile_t* archive_get_current_file(ArchiveBrowserView* browser) {
ArchiveFile_t* archive_get_file_at(ArchiveBrowserView* browser, size_t idx) { ArchiveFile_t* archive_get_file_at(ArchiveBrowserView* browser, size_t idx) {
furi_assert(browser); furi_assert(browser);
ArchiveFile_t* selected; ArchiveFile_t* selected = NULL;
with_view_model( with_view_model(
browser->view, (ArchiveBrowserViewModel * model) { browser->view, (ArchiveBrowserViewModel * model) {
@ -298,7 +298,7 @@ ArchiveFile_t* archive_get_file_at(ArchiveBrowserView* browser, size_t idx) {
ArchiveTabEnum archive_get_tab(ArchiveBrowserView* browser) { ArchiveTabEnum archive_get_tab(ArchiveBrowserView* browser) {
furi_assert(browser); furi_assert(browser);
ArchiveTabEnum tab_id; ArchiveTabEnum tab_id = 0;
with_view_model( with_view_model(
browser->view, (ArchiveBrowserViewModel * model) { browser->view, (ArchiveBrowserViewModel * model) {
tab_id = model->tab_idx; tab_id = model->tab_idx;
@ -451,8 +451,6 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
archive_file_browser_set_path( archive_file_browser_set_path(
browser, browser->path, archive_get_tab_ext(tab), skip_assets); browser, browser->path, archive_get_tab_ext(tab), skip_assets);
tab_empty = false; // Empty check will be performed later tab_empty = false; // Empty check will be performed later
} else {
tab_empty = true;
} }
} }

View File

@ -32,13 +32,18 @@ static void desktop_loader_callback(const void* message, void* context) {
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAfterAppFinished); view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAfterAppFinished);
} }
} }
static void desktop_lock_icon_draw_callback(Canvas* canvas, void* context) {
static void desktop_lock_icon_callback(Canvas* canvas, void* context) {
UNUSED(context); UNUSED(context);
furi_assert(canvas); furi_assert(canvas);
canvas_draw_icon(canvas, 0, 0, &I_Lock_8x8); canvas_draw_icon(canvas, 0, 0, &I_Lock_8x8);
} }
static void desktop_dummy_mode_icon_draw_callback(Canvas* canvas, void* context) {
UNUSED(context);
furi_assert(canvas);
canvas_draw_icon(canvas, 0, 0, &I_GameMode_11x8);
}
static bool desktop_custom_event_callback(void* context, uint32_t event) { static bool desktop_custom_event_callback(void* context, uint32_t event) {
furi_assert(context); furi_assert(context);
Desktop* desktop = (Desktop*)context; Desktop* desktop = (Desktop*)context;
@ -52,7 +57,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
animation_manager_load_and_continue_animation(desktop->animation_manager); animation_manager_load_and_continue_animation(desktop->animation_manager);
// TODO: Implement a message mechanism for loading settings and (optionally) // TODO: Implement a message mechanism for loading settings and (optionally)
// locking and unlocking // locking and unlocking
LOAD_DESKTOP_SETTINGS(&desktop->settings); DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_auto_lock_arm(desktop); desktop_auto_lock_arm(desktop);
return true; return true;
case DesktopGlobalAutoLock: case DesktopGlobalAutoLock:
@ -127,7 +132,7 @@ void desktop_lock(Desktop* desktop) {
} }
void desktop_unlock(Desktop* desktop) { void desktop_unlock(Desktop* desktop) {
view_port_enabled_set(desktop->lock_viewport, false); view_port_enabled_set(desktop->lock_icon_viewport, false);
Gui* gui = furi_record_open(RECORD_GUI); Gui* gui = furi_record_open(RECORD_GUI);
gui_set_lockdown(gui, false); gui_set_lockdown(gui, false);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
@ -136,6 +141,13 @@ void desktop_unlock(Desktop* desktop) {
desktop_auto_lock_arm(desktop); desktop_auto_lock_arm(desktop);
} }
void desktop_set_dummy_mode_state(Desktop* desktop, bool enabled) {
view_port_enabled_set(desktop->dummy_mode_icon_viewport, enabled);
desktop_main_set_dummy_mode_state(desktop->main_view, enabled);
desktop->settings.dummy_mode = enabled;
DESKTOP_SETTINGS_SAVE(&desktop->settings);
}
Desktop* desktop_alloc() { Desktop* desktop_alloc() {
Desktop* desktop = malloc(sizeof(Desktop)); Desktop* desktop = malloc(sizeof(Desktop));
@ -212,11 +224,20 @@ Desktop* desktop_alloc() {
desktop_view_slideshow_get_view(desktop->slideshow_view)); desktop_view_slideshow_get_view(desktop->slideshow_view));
// Lock icon // Lock icon
desktop->lock_viewport = view_port_alloc(); desktop->lock_icon_viewport = view_port_alloc();
view_port_set_width(desktop->lock_viewport, icon_get_width(&I_Lock_8x8)); view_port_set_width(desktop->lock_icon_viewport, icon_get_width(&I_Lock_8x8));
view_port_draw_callback_set(desktop->lock_viewport, desktop_lock_icon_callback, desktop); view_port_draw_callback_set(
view_port_enabled_set(desktop->lock_viewport, false); desktop->lock_icon_viewport, desktop_lock_icon_draw_callback, desktop);
gui_add_view_port(desktop->gui, desktop->lock_viewport, GuiLayerStatusBarLeft); view_port_enabled_set(desktop->lock_icon_viewport, false);
gui_add_view_port(desktop->gui, desktop->lock_icon_viewport, GuiLayerStatusBarLeft);
// Dummy mode icon
desktop->dummy_mode_icon_viewport = view_port_alloc();
view_port_set_width(desktop->dummy_mode_icon_viewport, icon_get_width(&I_GameMode_11x8));
view_port_draw_callback_set(
desktop->dummy_mode_icon_viewport, desktop_dummy_mode_icon_draw_callback, desktop);
view_port_enabled_set(desktop->dummy_mode_icon_viewport, false);
gui_add_view_port(desktop->gui, desktop->dummy_mode_icon_viewport, GuiLayerStatusBarLeft);
// Special case: autostart application is already running // Special case: autostart application is already running
desktop->loader = furi_record_open(RECORD_LOADER); desktop->loader = furi_record_open(RECORD_LOADER);
@ -301,12 +322,15 @@ int32_t desktop_srv(void* p) {
UNUSED(p); UNUSED(p);
Desktop* desktop = desktop_alloc(); Desktop* desktop = desktop_alloc();
bool loaded = LOAD_DESKTOP_SETTINGS(&desktop->settings); bool loaded = DESKTOP_SETTINGS_LOAD(&desktop->settings);
if(!loaded) { if(!loaded) {
memset(&desktop->settings, 0, sizeof(desktop->settings)); memset(&desktop->settings, 0, sizeof(desktop->settings));
SAVE_DESKTOP_SETTINGS(&desktop->settings); DESKTOP_SETTINGS_SAVE(&desktop->settings);
} }
view_port_enabled_set(desktop->dummy_mode_icon_viewport, desktop->settings.dummy_mode);
desktop_main_set_dummy_mode_state(desktop->main_view, desktop->settings.dummy_mode);
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain); scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
desktop_pin_lock_init(&desktop->settings); desktop_pin_lock_init(&desktop->settings);

View File

@ -57,7 +57,8 @@ struct Desktop {
DesktopSettings settings; DesktopSettings settings;
DesktopViewPinInput* pin_input_view; DesktopViewPinInput* pin_input_view;
ViewPort* lock_viewport; ViewPort* lock_icon_viewport;
ViewPort* dummy_mode_icon_viewport;
AnimationManager* animation_manager; AnimationManager* animation_manager;
@ -75,3 +76,4 @@ Desktop* desktop_alloc();
void desktop_free(Desktop* desktop); void desktop_free(Desktop* desktop);
void desktop_lock(Desktop* desktop); void desktop_lock(Desktop* desktop);
void desktop_unlock(Desktop* desktop); void desktop_unlock(Desktop* desktop);
void desktop_set_dummy_mode_state(Desktop* desktop, bool enabled);

View File

@ -8,7 +8,7 @@
#include <toolbox/saved_struct.h> #include <toolbox/saved_struct.h>
#include <storage/storage.h> #include <storage/storage.h>
#define DESKTOP_SETTINGS_VER (4) #define DESKTOP_SETTINGS_VER (5)
#define DESKTOP_SETTINGS_PATH INT_PATH(DESKTOP_SETTINGS_FILE_NAME) #define DESKTOP_SETTINGS_PATH INT_PATH(DESKTOP_SETTINGS_FILE_NAME)
#define DESKTOP_SETTINGS_MAGIC (0x17) #define DESKTOP_SETTINGS_MAGIC (0x17)
@ -16,7 +16,7 @@
#define DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG "run_pin_setup" #define DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG "run_pin_setup"
#define SAVE_DESKTOP_SETTINGS(x) \ #define DESKTOP_SETTINGS_SAVE(x) \
saved_struct_save( \ saved_struct_save( \
DESKTOP_SETTINGS_PATH, \ DESKTOP_SETTINGS_PATH, \
(x), \ (x), \
@ -24,7 +24,7 @@
DESKTOP_SETTINGS_MAGIC, \ DESKTOP_SETTINGS_MAGIC, \
DESKTOP_SETTINGS_VER) DESKTOP_SETTINGS_VER)
#define LOAD_DESKTOP_SETTINGS(x) \ #define DESKTOP_SETTINGS_LOAD(x) \
saved_struct_load( \ saved_struct_load( \
DESKTOP_SETTINGS_PATH, \ DESKTOP_SETTINGS_PATH, \
(x), \ (x), \
@ -46,4 +46,5 @@ typedef struct {
PinCode pin_code; PinCode pin_code;
uint8_t is_locked; uint8_t is_locked;
uint32_t auto_lock_delay_ms; uint32_t auto_lock_delay_ms;
uint8_t dummy_mode;
} DesktopSettings; } DesktopSettings;

View File

@ -72,7 +72,7 @@ void desktop_pin_lock(DesktopSettings* settings) {
cli_session_close(cli); cli_session_close(cli);
furi_record_close(RECORD_CLI); furi_record_close(RECORD_CLI);
settings->is_locked = 1; settings->is_locked = 1;
SAVE_DESKTOP_SETTINGS(settings); DESKTOP_SETTINGS_SAVE(settings);
} }
void desktop_pin_unlock(DesktopSettings* settings) { void desktop_pin_unlock(DesktopSettings* settings) {
@ -83,7 +83,7 @@ void desktop_pin_unlock(DesktopSettings* settings) {
cli_session_open(cli, &cli_vcp); cli_session_open(cli, &cli_vcp);
furi_record_close(RECORD_CLI); furi_record_close(RECORD_CLI);
settings->is_locked = 0; settings->is_locked = 0;
SAVE_DESKTOP_SETTINGS(settings); DESKTOP_SETTINGS_SAVE(settings);
} }
void desktop_pin_lock_init(DesktopSettings* settings) { void desktop_pin_lock_init(DesktopSettings* settings) {
@ -95,7 +95,7 @@ void desktop_pin_lock_init(DesktopSettings* settings) {
} else { } else {
if(desktop_pin_lock_is_locked()) { if(desktop_pin_lock_is_locked()) {
settings->is_locked = 1; settings->is_locked = 1;
SAVE_DESKTOP_SETTINGS(settings); DESKTOP_SETTINGS_SAVE(settings);
} }
} }
} else { } else {

View File

@ -22,10 +22,11 @@ void desktop_scene_lock_menu_callback(DesktopEvent event, void* context) {
void desktop_scene_lock_menu_on_enter(void* context) { void desktop_scene_lock_menu_on_enter(void* context) {
Desktop* desktop = (Desktop*)context; Desktop* desktop = (Desktop*)context;
LOAD_DESKTOP_SETTINGS(&desktop->settings); DESKTOP_SETTINGS_LOAD(&desktop->settings);
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0); scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop); desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
desktop_lock_menu_pin_set(desktop->lock_menu, desktop->settings.pin_code.length > 0); desktop_lock_menu_set_pin_state(desktop->lock_menu, desktop->settings.pin_code.length > 0);
desktop_lock_menu_set_dummy_mode_state(desktop->lock_menu, desktop->settings.dummy_mode);
desktop_lock_menu_set_idx(desktop->lock_menu, 0); desktop_lock_menu_set_idx(desktop->lock_menu, 0);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu); view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu);
@ -39,9 +40,9 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
bool check_pin_changed = bool check_pin_changed =
scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLockMenu); scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLockMenu);
if(check_pin_changed) { if(check_pin_changed) {
LOAD_DESKTOP_SETTINGS(&desktop->settings); DESKTOP_SETTINGS_LOAD(&desktop->settings);
if(desktop->settings.pin_code.length > 0) { if(desktop->settings.pin_code.length > 0) {
desktop_lock_menu_pin_set(desktop->lock_menu, 1); desktop_lock_menu_set_pin_state(desktop->lock_menu, true);
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0); scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
} }
} }
@ -67,15 +68,21 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
} }
consumed = true; consumed = true;
break; break;
case DesktopLockMenuEventExit: case DesktopLockMenuEventDummyModeOn:
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0); desktop_set_dummy_mode_state(desktop, true);
scene_manager_search_and_switch_to_previous_scene(
desktop->scene_manager, DesktopSceneMain);
break;
case DesktopLockMenuEventDummyModeOff:
desktop_set_dummy_mode_state(desktop, false);
scene_manager_search_and_switch_to_previous_scene( scene_manager_search_and_switch_to_previous_scene(
desktop->scene_manager, DesktopSceneMain); desktop->scene_manager, DesktopSceneMain);
consumed = true;
break; break;
default: default:
break; break;
} }
} else if(event.type == SceneManagerEventTypeBack) {
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
} }
return consumed; return consumed;
} }

View File

@ -46,13 +46,13 @@ void desktop_scene_locked_on_enter(void* context) {
uint32_t state = scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLocked); uint32_t state = scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLocked);
if(state == SCENE_LOCKED_FIRST_ENTER) { if(state == SCENE_LOCKED_FIRST_ENTER) {
bool pin_locked = desktop_pin_lock_is_locked(); bool pin_locked = desktop_pin_lock_is_locked();
view_port_enabled_set(desktop->lock_viewport, true); view_port_enabled_set(desktop->lock_icon_viewport, true);
Gui* gui = furi_record_open(RECORD_GUI); Gui* gui = furi_record_open(RECORD_GUI);
gui_set_lockdown(gui, true); gui_set_lockdown(gui, true);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
if(pin_locked) { if(pin_locked) {
LOAD_DESKTOP_SETTINGS(&desktop->settings); DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_view_locked_lock(desktop->locked_view, true); desktop_view_locked_lock(desktop->locked_view, true);
uint32_t pin_timeout = desktop_pin_lock_get_fail_timeout(); uint32_t pin_timeout = desktop_pin_lock_get_fail_timeout();
if(pin_timeout > 0) { if(pin_timeout > 0) {

View File

@ -113,7 +113,7 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
} }
case DesktopMainEventOpenFavoritePrimary: case DesktopMainEventOpenFavoritePrimary:
LOAD_DESKTOP_SETTINGS(&desktop->settings); DESKTOP_SETTINGS_LOAD(&desktop->settings);
if(desktop->settings.favorite_primary < FLIPPER_APPS_COUNT) { if(desktop->settings.favorite_primary < FLIPPER_APPS_COUNT) {
LoaderStatus status = loader_start( LoaderStatus status = loader_start(
desktop->loader, FLIPPER_APPS[desktop->settings.favorite_primary].name, NULL); desktop->loader, FLIPPER_APPS[desktop->settings.favorite_primary].name, NULL);
@ -126,7 +126,7 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
consumed = true; consumed = true;
break; break;
case DesktopMainEventOpenFavoriteSecondary: case DesktopMainEventOpenFavoriteSecondary:
LOAD_DESKTOP_SETTINGS(&desktop->settings); DESKTOP_SETTINGS_LOAD(&desktop->settings);
if(desktop->settings.favorite_secondary < FLIPPER_APPS_COUNT) { if(desktop->settings.favorite_secondary < FLIPPER_APPS_COUNT) {
LoaderStatus status = loader_start( LoaderStatus status = loader_start(
desktop->loader, desktop->loader,
@ -157,6 +157,21 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
} }
consumed = true; consumed = true;
break; break;
case DesktopMainEventOpenPassport: {
LoaderStatus status = loader_start(desktop->loader, "Passport", NULL);
if(status != LoaderStatusOk) {
FURI_LOG_E(TAG, "loader_start failed: %d", status);
}
break;
}
case DesktopMainEventOpenGameMenu: {
LoaderStatus status = loader_start(
desktop->loader, "Applications", EXT_PATH("/apps/Games/snake_game.fap"));
if(status != LoaderStatusOk) {
FURI_LOG_E(TAG, "loader_start failed: %d", status);
}
break;
}
case DesktopLockedEventUpdate: case DesktopLockedEventUpdate:
desktop_view_locked_update(desktop->locked_view); desktop_view_locked_update(desktop->locked_view);
consumed = true; consumed = true;

View File

@ -7,9 +7,11 @@ typedef enum {
DesktopMainEventOpenFavoriteSecondary, DesktopMainEventOpenFavoriteSecondary,
DesktopMainEventOpenMenu, DesktopMainEventOpenMenu,
DesktopMainEventOpenDebug, DesktopMainEventOpenDebug,
DesktopMainEventOpenPassport, /**< Broken, don't use it */ DesktopMainEventOpenPassport,
DesktopMainEventOpenPowerOff, DesktopMainEventOpenPowerOff,
DesktopMainEventOpenGameMenu,
DesktopLockedEventUnlocked, DesktopLockedEventUnlocked,
DesktopLockedEventUpdate, DesktopLockedEventUpdate,
DesktopLockedEventShowPinInput, DesktopLockedEventShowPinInput,
@ -28,7 +30,8 @@ typedef enum {
DesktopLockMenuEventLock, DesktopLockMenuEventLock,
DesktopLockMenuEventPinLock, DesktopLockMenuEventPinLock,
DesktopLockMenuEventExit, DesktopLockMenuEventDummyModeOn,
DesktopLockMenuEventDummyModeOff,
DesktopAnimationEventCheckAnimation, DesktopAnimationEventCheckAnimation,
DesktopAnimationEventNewIdleAnimation, DesktopAnimationEventNewIdleAnimation,

View File

@ -4,7 +4,13 @@
#include "../desktop_i.h" #include "../desktop_i.h"
#include "desktop_view_lock_menu.h" #include "desktop_view_lock_menu.h"
#define LOCK_MENU_ITEMS_NB 3 typedef enum {
DesktopLockMenuIndexLock,
DesktopLockMenuIndexPinLock,
DesktopLockMenuIndexDummy,
DesktopLockMenuIndexTotalCount
} DesktopLockMenuIndex;
void desktop_lock_menu_set_callback( void desktop_lock_menu_set_callback(
DesktopLockMenuView* lock_menu, DesktopLockMenuView* lock_menu,
@ -16,16 +22,24 @@ void desktop_lock_menu_set_callback(
lock_menu->context = context; lock_menu->context = context;
} }
void desktop_lock_menu_pin_set(DesktopLockMenuView* lock_menu, bool pin_is_set) { void desktop_lock_menu_set_pin_state(DesktopLockMenuView* lock_menu, bool pin_is_set) {
with_view_model( with_view_model(
lock_menu->view, (DesktopLockMenuViewModel * model) { lock_menu->view, (DesktopLockMenuViewModel * model) {
model->pin_set = pin_is_set; model->pin_is_set = pin_is_set;
return true;
});
}
void desktop_lock_menu_set_dummy_mode_state(DesktopLockMenuView* lock_menu, bool dummy_mode) {
with_view_model(
lock_menu->view, (DesktopLockMenuViewModel * model) {
model->dummy_mode = dummy_mode;
return true; return true;
}); });
} }
void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx) { void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx) {
furi_assert(idx < LOCK_MENU_ITEMS_NB); furi_assert(idx < DesktopLockMenuIndexTotalCount);
with_view_model( with_view_model(
lock_menu->view, (DesktopLockMenuViewModel * model) { lock_menu->view, (DesktopLockMenuViewModel * model) {
model->idx = idx; model->idx = idx;
@ -33,43 +47,34 @@ void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx) {
}); });
} }
static void lock_menu_callback(void* context, uint8_t index) { void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) {
furi_assert(context);
DesktopLockMenuView* lock_menu = context;
switch(index) {
case 0: // lock
lock_menu->callback(DesktopLockMenuEventLock, lock_menu->context);
break;
case 1: // lock
lock_menu->callback(DesktopLockMenuEventPinLock, lock_menu->context);
break;
default: // wip message
with_view_model(
lock_menu->view, (DesktopLockMenuViewModel * model) {
model->hint_timeout = HINT_TIMEOUT;
return true;
});
break;
}
}
void desktop_lock_menu_render(Canvas* canvas, void* model) {
const char* Lockmenu_Items[LOCK_MENU_ITEMS_NB] = {"Lock", "Lock with PIN", "DUMB mode"};
DesktopLockMenuViewModel* m = model; DesktopLockMenuViewModel* m = model;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_icon(canvas, -57, 0 + STATUS_BAR_Y_SHIFT, &I_DoorLeft_70x55); canvas_draw_icon(canvas, -57, 0 + STATUS_BAR_Y_SHIFT, &I_DoorLeft_70x55);
canvas_draw_icon(canvas, 116, 0 + STATUS_BAR_Y_SHIFT, &I_DoorRight_70x55); canvas_draw_icon(canvas, 116, 0 + STATUS_BAR_Y_SHIFT, &I_DoorRight_70x55);
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
for(uint8_t i = 0; i < LOCK_MENU_ITEMS_NB; ++i) { for(uint8_t i = 0; i < DesktopLockMenuIndexTotalCount; ++i) {
const char* str = Lockmenu_Items[i]; const char* str = NULL;
if(i == 1 && !m->pin_set) str = "Set PIN"; if(i == DesktopLockMenuIndexLock) {
if(m->hint_timeout && m->idx == 2 && m->idx == i) str = "Not Implemented"; str = "Lock";
} else if(i == DesktopLockMenuIndexPinLock) {
if(m->pin_is_set) {
str = "Lock with PIN";
} else {
str = "Set PIN";
}
} else if(i == DesktopLockMenuIndexDummy) {
if(m->dummy_mode) {
str = "Brainiac Mode";
} else {
str = "Dummy Mode";
}
}
if(str != NULL) if(str)
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str); canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str);
@ -82,33 +87,58 @@ View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu) {
return lock_menu->view; return lock_menu->view;
} }
bool desktop_lock_menu_input(InputEvent* event, void* context) { bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
furi_assert(event); furi_assert(event);
furi_assert(context); furi_assert(context);
DesktopLockMenuView* lock_menu = context; DesktopLockMenuView* lock_menu = context;
uint8_t idx; uint8_t idx = 0;
bool consumed = false;
bool dummy_mode = false;
if(event->type != InputTypeShort) return false;
with_view_model( with_view_model(
lock_menu->view, (DesktopLockMenuViewModel * model) { lock_menu->view, (DesktopLockMenuViewModel * model) {
model->hint_timeout = 0; // clear hint timeout bool ret = false;
if(event->key == InputKeyUp) { if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
model->idx = CLAMP(model->idx - 1, LOCK_MENU_ITEMS_NB - 1, 0); if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) { if(model->idx == 0) {
model->idx = CLAMP(model->idx + 1, LOCK_MENU_ITEMS_NB - 1, 0); model->idx = DesktopLockMenuIndexTotalCount - 1;
} else {
model->idx = CLAMP(model->idx - 1, DesktopLockMenuIndexTotalCount - 1, 0);
}
ret = true;
consumed = true;
} else if(event->key == InputKeyDown) {
if(model->idx == DesktopLockMenuIndexTotalCount - 1) {
model->idx = 0;
} else {
model->idx = CLAMP(model->idx + 1, DesktopLockMenuIndexTotalCount - 1, 0);
}
ret = true;
consumed = true;
}
} }
idx = model->idx; idx = model->idx;
return true; dummy_mode = model->dummy_mode;
return ret;
}); });
if(event->key == InputKeyBack) { if(event->key == InputKeyOk) {
lock_menu->callback(DesktopLockMenuEventExit, lock_menu->context); if((idx == DesktopLockMenuIndexLock) && (event->type == InputTypeShort)) {
} else if(event->key == InputKeyOk) { lock_menu->callback(DesktopLockMenuEventLock, lock_menu->context);
lock_menu_callback(lock_menu, idx); } else if((idx == DesktopLockMenuIndexPinLock) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventPinLock, lock_menu->context);
} else if(idx == DesktopLockMenuIndexDummy) {
if((dummy_mode == false) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventDummyModeOn, lock_menu->context);
} else if((dummy_mode == true) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventDummyModeOff, lock_menu->context);
}
}
consumed = true;
} }
return true; return consumed;
} }
DesktopLockMenuView* desktop_lock_menu_alloc() { DesktopLockMenuView* desktop_lock_menu_alloc() {
@ -116,8 +146,8 @@ DesktopLockMenuView* desktop_lock_menu_alloc() {
lock_menu->view = view_alloc(); lock_menu->view = view_alloc();
view_allocate_model(lock_menu->view, ViewModelTypeLocking, sizeof(DesktopLockMenuViewModel)); view_allocate_model(lock_menu->view, ViewModelTypeLocking, sizeof(DesktopLockMenuViewModel));
view_set_context(lock_menu->view, lock_menu); view_set_context(lock_menu->view, lock_menu);
view_set_draw_callback(lock_menu->view, (ViewDrawCallback)desktop_lock_menu_render); view_set_draw_callback(lock_menu->view, (ViewDrawCallback)desktop_lock_menu_draw_callback);
view_set_input_callback(lock_menu->view, desktop_lock_menu_input); view_set_input_callback(lock_menu->view, desktop_lock_menu_input_callback);
return lock_menu; return lock_menu;
} }

View File

@ -17,8 +17,8 @@ struct DesktopLockMenuView {
typedef struct { typedef struct {
uint8_t idx; uint8_t idx;
uint8_t hint_timeout; bool pin_is_set;
bool pin_set; bool dummy_mode;
} DesktopLockMenuViewModel; } DesktopLockMenuViewModel;
void desktop_lock_menu_set_callback( void desktop_lock_menu_set_callback(
@ -27,7 +27,8 @@ void desktop_lock_menu_set_callback(
void* context); void* context);
View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu); View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu);
void desktop_lock_menu_pin_set(DesktopLockMenuView* lock_menu, bool pin_is_set); void desktop_lock_menu_set_pin_state(DesktopLockMenuView* lock_menu, bool pin_is_set);
void desktop_lock_menu_set_dummy_mode_state(DesktopLockMenuView* lock_menu, bool dummy_mode);
void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx); void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx);
DesktopLockMenuView* desktop_lock_menu_alloc(); DesktopLockMenuView* desktop_lock_menu_alloc();
void desktop_lock_menu_free(DesktopLockMenuView* lock_menu); void desktop_lock_menu_free(DesktopLockMenuView* lock_menu);

View File

@ -14,6 +14,7 @@ struct DesktopMainView {
DesktopMainViewCallback callback; DesktopMainViewCallback callback;
void* context; void* context;
TimerHandle_t poweroff_timer; TimerHandle_t poweroff_timer;
bool dummy_mode;
}; };
#define DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT 5000 #define DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT 5000
@ -38,29 +39,48 @@ View* desktop_main_get_view(DesktopMainView* main_view) {
return main_view->view; return main_view->view;
} }
bool desktop_main_input(InputEvent* event, void* context) { void desktop_main_set_dummy_mode_state(DesktopMainView* main_view, bool dummy_mode) {
furi_assert(main_view);
main_view->dummy_mode = dummy_mode;
}
bool desktop_main_input_callback(InputEvent* event, void* context) {
furi_assert(event); furi_assert(event);
furi_assert(context); furi_assert(context);
DesktopMainView* main_view = context; DesktopMainView* main_view = context;
if(event->type == InputTypeShort) { if(main_view->dummy_mode == false) {
if(event->key == InputKeyOk) { if(event->type == InputTypeShort) {
main_view->callback(DesktopMainEventOpenMenu, main_view->context); if(event->key == InputKeyOk) {
} else if(event->key == InputKeyUp) { main_view->callback(DesktopMainEventOpenMenu, main_view->context);
main_view->callback(DesktopMainEventOpenLockMenu, main_view->context); } else if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) { main_view->callback(DesktopMainEventOpenLockMenu, main_view->context);
main_view->callback(DesktopMainEventOpenArchive, main_view->context); } else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) { main_view->callback(DesktopMainEventOpenArchive, main_view->context);
main_view->callback(DesktopMainEventOpenFavoritePrimary, main_view->context); } else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) { main_view->callback(DesktopMainEventOpenFavoritePrimary, main_view->context);
main_view->callback(DesktopMainEventOpenPassport, main_view->context); }
// Right key is handled by animation manager
} else if(event->type == InputTypeLong) {
if(event->key == InputKeyDown) {
main_view->callback(DesktopMainEventOpenDebug, main_view->context);
} else if(event->key == InputKeyLeft) {
main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context);
}
} }
} else if(event->type == InputTypeLong) { } else {
if(event->key == InputKeyDown) { if(event->type == InputTypeShort) {
main_view->callback(DesktopMainEventOpenDebug, main_view->context); if(event->key == InputKeyOk) {
} else if(event->key == InputKeyLeft) { main_view->callback(DesktopMainEventOpenGameMenu, main_view->context);
main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context); } else if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventOpenLockMenu, main_view->context);
} else if(event->key == InputKeyDown) {
main_view->callback(DesktopMainEventOpenPassport, main_view->context);
} else if(event->key == InputKeyLeft) {
main_view->callback(DesktopMainEventOpenPassport, main_view->context);
}
// Right key is handled by animation manager
} }
} }
@ -84,7 +104,7 @@ DesktopMainView* desktop_main_alloc() {
main_view->view = view_alloc(); main_view->view = view_alloc();
view_allocate_model(main_view->view, ViewModelTypeLockFree, 1); view_allocate_model(main_view->view, ViewModelTypeLockFree, 1);
view_set_context(main_view->view, main_view); view_set_context(main_view->view, main_view);
view_set_input_callback(main_view->view, desktop_main_input); view_set_input_callback(main_view->view, desktop_main_input_callback);
main_view->poweroff_timer = xTimerCreate( main_view->poweroff_timer = xTimerCreate(
NULL, NULL,

View File

@ -13,5 +13,6 @@ void desktop_main_set_callback(
void* context); void* context);
View* desktop_main_get_view(DesktopMainView* main_view); View* desktop_main_get_view(DesktopMainView* main_view);
void desktop_main_set_dummy_mode_state(DesktopMainView* main_view, bool dummy_mode);
DesktopMainView* desktop_main_alloc(); DesktopMainView* desktop_main_alloc();
void desktop_main_free(DesktopMainView* main_view); void desktop_main_free(DesktopMainView* main_view);

View File

@ -89,7 +89,7 @@ void desktop_settings_app_free(DesktopSettingsApp* app) {
extern int32_t desktop_settings_app(void* p) { extern int32_t desktop_settings_app(void* p) {
DesktopSettingsApp* app = desktop_settings_app_alloc(); DesktopSettingsApp* app = desktop_settings_app_alloc();
LOAD_DESKTOP_SETTINGS(&app->settings); DESKTOP_SETTINGS_LOAD(&app->settings);
if(p && (strcmp(p, DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG) == 0)) { if(p && (strcmp(p, DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG) == 0)) {
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinSetupHowto); scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinSetupHowto);
} else { } else {

View File

@ -56,6 +56,6 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e
void desktop_settings_scene_favorite_on_exit(void* context) { void desktop_settings_scene_favorite_on_exit(void* context) {
DesktopSettingsApp* app = context; DesktopSettingsApp* app = context;
SAVE_DESKTOP_SETTINGS(&app->settings); DESKTOP_SETTINGS_SAVE(&app->settings);
submenu_reset(app->submenu); submenu_reset(app->submenu);
} }

View File

@ -33,7 +33,7 @@ static void pin_auth_back_callback(void* context) {
void desktop_settings_scene_pin_auth_on_enter(void* context) { void desktop_settings_scene_pin_auth_on_enter(void* context) {
DesktopSettingsApp* app = context; DesktopSettingsApp* app = context;
LOAD_DESKTOP_SETTINGS(&app->settings); DESKTOP_SETTINGS_LOAD(&app->settings);
furi_assert(app->settings.pin_code.length > 0); furi_assert(app->settings.pin_code.length > 0);
desktop_view_pin_input_set_context(app->pin_input_view, app); desktop_view_pin_input_set_context(app->pin_input_view, app);

View File

@ -20,7 +20,7 @@ void desktop_settings_scene_pin_disable_on_enter(void* context) {
DesktopSettingsApp* app = context; DesktopSettingsApp* app = context;
app->settings.pin_code.length = 0; app->settings.pin_code.length = 0;
memset(app->settings.pin_code.data, '0', sizeof(app->settings.pin_code.data)); memset(app->settings.pin_code.data, '0', sizeof(app->settings.pin_code.data));
SAVE_DESKTOP_SETTINGS(&app->settings); DESKTOP_SETTINGS_SAVE(&app->settings);
popup_set_context(app->popup, app); popup_set_context(app->popup, app);
popup_set_callback(app->popup, pin_disable_back_callback); popup_set_callback(app->popup, pin_disable_back_callback);

View File

@ -24,7 +24,7 @@ void desktop_settings_scene_pin_setup_done_on_enter(void* context) {
DesktopSettingsApp* app = context; DesktopSettingsApp* app = context;
app->settings.pin_code = app->pincode_buffer; app->settings.pin_code = app->pincode_buffer;
SAVE_DESKTOP_SETTINGS(&app->settings); DESKTOP_SETTINGS_SAVE(&app->settings);
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION); NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message(notification, &sequence_single_vibro); notification_message(notification, &sequence_single_vibro);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);

View File

@ -96,5 +96,5 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even
void desktop_settings_scene_start_on_exit(void* context) { void desktop_settings_scene_start_on_exit(void* context) {
DesktopSettingsApp* app = context; DesktopSettingsApp* app = context;
variable_item_list_reset(app->variable_item_list); variable_item_list_reset(app->variable_item_list);
SAVE_DESKTOP_SETTINGS(&app->settings); DESKTOP_SETTINGS_SAVE(&app->settings);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -1,5 +1,5 @@
entry,status,name,type,params entry,status,name,type,params
Version,+,1.4,, Version,+,1.5,,
Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,, Header,+,applications/services/cli/cli_vcp.h,,
@ -2603,6 +2603,7 @@ Variable,+,I_FaceCharging_29x14,const Icon,
Variable,+,I_FaceConfused_29x14,const Icon, Variable,+,I_FaceConfused_29x14,const Icon,
Variable,+,I_FaceNopower_29x14,const Icon, Variable,+,I_FaceNopower_29x14,const Icon,
Variable,+,I_FaceNormal_29x14,const Icon, Variable,+,I_FaceNormal_29x14,const Icon,
Variable,+,I_GameMode_11x8,const Icon,
Variable,+,I_Health_16x16,const Icon, Variable,+,I_Health_16x16,const Icon,
Variable,+,I_InfraredArrowDown_4x8,const Icon, Variable,+,I_InfraredArrowDown_4x8,const Icon,
Variable,+,I_InfraredArrowUp_4x8,const Icon, Variable,+,I_InfraredArrowUp_4x8,const Icon,

1 entry status name type params
2 Version + 1.4 1.5
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
2603 Variable + I_FaceConfused_29x14 const Icon
2604 Variable + I_FaceNopower_29x14 const Icon
2605 Variable + I_FaceNormal_29x14 const Icon
2606 Variable + I_GameMode_11x8 const Icon
2607 Variable + I_Health_16x16 const Icon
2608 Variable + I_InfraredArrowDown_4x8 const Icon
2609 Variable + I_InfraredArrowUp_4x8 const Icon