From 6b4360652609c993417affabfebb0eaa07536459 Mon Sep 17 00:00:00 2001 From: Roman Shchekin Date: Mon, 6 Nov 2023 15:49:13 +0300 Subject: [PATCH] refactor: Massive rename and cleanup --- hex_viewer.c | 11 +- hex_viewer.h | 65 ++--- scenes/hex_viewer_scene_config.h | 6 +- ...cene_scene_2.c => hex_viewer_scene_info.c} | 10 +- scenes/hex_viewer_scene_menu.c | 34 ++- ...cene_scene_4.c => hex_viewer_scene_open.c} | 6 +- ...ne_scene_1.c => hex_viewer_scene_scroll.c} | 13 +- scenes/hex_viewer_scene_startscreen.c | 3 +- views/hex_viewer_scene_1.c | 136 ---------- views/hex_viewer_scene_1.h | 19 -- views/hex_viewer_scene_2.c | 254 ------------------ views/hex_viewer_scene_2.h | 19 -- views/hex_viewer_startscreen.c | 9 +- 13 files changed, 56 insertions(+), 529 deletions(-) rename scenes/{hex_viewer_scene_scene_2.c => hex_viewer_scene_info.c} (75%) rename scenes/{hex_viewer_scene_scene_4.c => hex_viewer_scene_open.c} (84%) rename scenes/{hex_viewer_scene_scene_1.c => hex_viewer_scene_scroll.c} (84%) delete mode 100644 views/hex_viewer_scene_1.c delete mode 100644 views/hex_viewer_scene_1.h delete mode 100644 views/hex_viewer_scene_2.c delete mode 100644 views/hex_viewer_scene_2.h diff --git a/hex_viewer.c b/hex_viewer.c index 5be549c..4d73155 100644 --- a/hex_viewer.c +++ b/hex_viewer.c @@ -71,13 +71,7 @@ HexViewer* hex_viewer_app_alloc() { hex_viewer_startscreen_get_view(app->hex_viewer_startscreen)); view_dispatcher_add_view( - app->view_dispatcher, HexViewerViewIdScene1, text_input_get_view(app->text_input)); - - app->hex_viewer_scene_2 = hex_viewer_scene_2_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - HexViewerViewIdScene2, - hex_viewer_scene_2_get_view(app->hex_viewer_scene_2)); + app->view_dispatcher, HexViewerViewIdScroll, text_input_get_view(app->text_input)); app->variable_item_list = variable_item_list_alloc(); view_dispatcher_add_view( @@ -100,8 +94,7 @@ void hex_viewer_app_free(HexViewer* app) { // View Dispatcher view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdMenu); - view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdScene1); - view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdScene2); + view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdScroll); view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdSettings); submenu_free(app->submenu); diff --git a/hex_viewer.h b/hex_viewer.h index c94d8a5..72f3247 100644 --- a/hex_viewer.h +++ b/hex_viewer.h @@ -18,8 +18,6 @@ #include #include "scenes/hex_viewer_scene.h" #include "views/hex_viewer_startscreen.h" -#include "views/hex_viewer_scene_1.h" -#include "views/hex_viewer_scene_2.h" #include "helpers/hex_viewer_storage.h" #include @@ -29,9 +27,6 @@ #define TAG "HexViewer" -// #define SUBGHZ_APP_EXTENSION ".sub" -// #define SUBGHZ_APP_FOLDER ANY_PATH("subghz") - #define HEX_VIEWER_APP_PATH_FOLDER "/any" // TODO ANY_PATH #define HEX_VIEWER_APP_EXTENSION "*" #define HEX_VIEWER_PERCENT_INPUT 16 @@ -40,37 +35,30 @@ #define HEX_VIEWER_LINES_ON_SCREEN 4u #define HEX_VIEWER_BUF_SIZE (HEX_VIEWER_LINES_ON_SCREEN * HEX_VIEWER_BYTES_PER_LINE) -// typedef struct HexViewerModel HexViewerModel; -// typedef struct HexViewer HexViewer; - -typedef struct -{ +typedef struct { uint8_t file_bytes[HEX_VIEWER_LINES_ON_SCREEN][HEX_VIEWER_BYTES_PER_LINE]; uint32_t file_offset; uint32_t file_read_bytes; uint32_t file_size; - Stream *stream; + Stream* stream; } HexViewerModel; // TODO Clean -typedef struct -{ - HexViewerModel *model; - - Gui *gui; - Storage *storage; - NotificationApp *notification; - ViewDispatcher *view_dispatcher; - Submenu *submenu; - TextInput *text_input; - SceneManager *scene_manager; - VariableItemList *variable_item_list; - HexViewerStartscreen *hex_viewer_startscreen; - HexViewerScene1 *hex_viewer_scene_1; - HexViewerScene2 *hex_viewer_scene_2; - DialogsApp *dialogs; // File Browser - FuriString *file_path; // File Browser +typedef struct { + HexViewerModel* model; + + Gui* gui; + Storage* storage; + NotificationApp* notification; + ViewDispatcher* view_dispatcher; + Submenu* submenu; + TextInput* text_input; + SceneManager* scene_manager; + VariableItemList* variable_item_list; + HexViewerStartscreen* hex_viewer_startscreen; + DialogsApp* dialogs; // File Browser + FuriString* file_path; // File Browser uint32_t haptic; uint32_t speaker; uint32_t led; @@ -78,38 +66,29 @@ typedef struct char percent_buf[HEX_VIEWER_PERCENT_INPUT]; } HexViewer; -typedef enum -{ +typedef enum { HexViewerViewIdStartscreen, HexViewerViewIdMenu, - HexViewerViewIdScene1, - HexViewerViewIdScene2, - HexViewerViewIdScene3, - HexViewerViewIdScene4, - HexViewerViewIdScene5, + HexViewerViewIdScroll, HexViewerViewIdSettings, } HexViewerViewId; -typedef enum -{ +typedef enum { HexViewerHapticOff, HexViewerHapticOn, } HexViewerHapticState; -typedef enum -{ +typedef enum { HexViewerSpeakerOff, HexViewerSpeakerOn, } HexViewerSpeakerState; -typedef enum -{ +typedef enum { HexViewerLedOff, HexViewerLedOn, } HexViewerLedState; -typedef enum -{ +typedef enum { HexViewerSettingsOff, HexViewerSettingsOn, } HexViewerSettingsStoreState; diff --git a/scenes/hex_viewer_scene_config.h b/scenes/hex_viewer_scene_config.h index eafe88d..7db382b 100644 --- a/scenes/hex_viewer_scene_config.h +++ b/scenes/hex_viewer_scene_config.h @@ -1,6 +1,6 @@ ADD_SCENE(hex_viewer, startscreen, Startscreen) ADD_SCENE(hex_viewer, menu, Menu) -ADD_SCENE(hex_viewer, scene_1, Scene_1) -ADD_SCENE(hex_viewer, scene_2, Scene_2) -ADD_SCENE(hex_viewer, scene_4, Scene_4) +ADD_SCENE(hex_viewer, scroll, Scroll) +ADD_SCENE(hex_viewer, info, Info) +ADD_SCENE(hex_viewer, open, Open) ADD_SCENE(hex_viewer, settings, Settings) \ No newline at end of file diff --git a/scenes/hex_viewer_scene_scene_2.c b/scenes/hex_viewer_scene_info.c similarity index 75% rename from scenes/hex_viewer_scene_scene_2.c rename to scenes/hex_viewer_scene_info.c index 4c5f3bb..39d51b8 100644 --- a/scenes/hex_viewer_scene_scene_2.c +++ b/scenes/hex_viewer_scene_info.c @@ -1,10 +1,6 @@ #include "../hex_viewer.h" -#include "../helpers/hex_viewer_custom_event.h" -#include "../helpers/hex_viewer_haptic.h" -#include "../helpers/hex_viewer_led.h" -#include "../views/hex_viewer_scene_2.h" -void hex_viewer_scene_scene_2_on_enter(void* context) { +void hex_viewer_scene_info_on_enter(void* context) { furi_assert(context); HexViewer* app = context; @@ -31,7 +27,7 @@ void hex_viewer_scene_scene_2_on_enter(void* context) { app->scene_manager, HexViewerViewIdStartscreen); } -bool hex_viewer_scene_scene_2_on_event(void* context, SceneManagerEvent event) { +bool hex_viewer_scene_info_on_event(void* context, SceneManagerEvent event) { HexViewer* app = context; UNUSED(app); UNUSED(event); @@ -40,7 +36,7 @@ bool hex_viewer_scene_scene_2_on_event(void* context, SceneManagerEvent event) { return consumed; } -void hex_viewer_scene_scene_2_on_exit(void* context) { +void hex_viewer_scene_info_on_exit(void* context) { HexViewer* app = context; UNUSED(app); } diff --git a/scenes/hex_viewer_scene_menu.c b/scenes/hex_viewer_scene_menu.c index 68d21c3..50e0b55 100644 --- a/scenes/hex_viewer_scene_menu.c +++ b/scenes/hex_viewer_scene_menu.c @@ -1,11 +1,9 @@ #include "../hex_viewer.h" enum SubmenuIndex { - SubmenuIndexScene1 = 10, - SubmenuIndexScene2, - // SubmenuIndexScene3, - SubmenuIndexScene4, - // SubmenuIndexScene5, + SubmenuIndexScroll = 10, + SubmenuIndexInfo, + SubmenuIndexOpen, // SubmenuIndexSettings, }; @@ -21,21 +19,19 @@ void hex_viewer_scene_menu_on_enter(void* context) { submenu_add_item( app->submenu, "Open file ...", - SubmenuIndexScene4, + SubmenuIndexOpen, hex_viewer_scene_menu_submenu_callback, app); - // submenu_add_item(app->submenu, "Scene 2 (Inputs/Effects)", SubmenuIndexScene2, hex_viewer_scene_menu_submenu_callback, app); - // submenu_add_item(app->submenu, "Scene 3 (Buttonmenu)", SubmenuIndexScene3, hex_viewer_scene_menu_submenu_callback, app); submenu_add_item( app->submenu, "Scroll to ...", - SubmenuIndexScene1, + SubmenuIndexScroll, hex_viewer_scene_menu_submenu_callback, app); submenu_add_item( app->submenu, "Show info ...", - SubmenuIndexScene2, + SubmenuIndexInfo, hex_viewer_scene_menu_submenu_callback, app); // submenu_add_item(app->submenu, "Settings", SubmenuIndexSettings, hex_viewer_scene_menu_submenu_callback, app); @@ -56,20 +52,20 @@ bool hex_viewer_scene_menu_on_event(void* context, SceneManagerEvent event) { scene_manager_previous_scene(app->scene_manager); return true; } else if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexScene1) { + if(event.event == SubmenuIndexScroll) { scene_manager_set_scene_state( - app->scene_manager, HexViewerSceneMenu, SubmenuIndexScene1); - scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_1); + app->scene_manager, HexViewerSceneMenu, SubmenuIndexScroll); + scene_manager_next_scene(app->scene_manager, HexViewerSceneScroll); return true; - } else if(event.event == SubmenuIndexScene2) { + } else if(event.event == SubmenuIndexInfo) { scene_manager_set_scene_state( - app->scene_manager, HexViewerSceneMenu, SubmenuIndexScene2); - scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_2); + app->scene_manager, HexViewerSceneMenu, SubmenuIndexInfo); + scene_manager_next_scene(app->scene_manager, HexViewerSceneInfo); return true; - } else if(event.event == SubmenuIndexScene4) { + } else if(event.event == SubmenuIndexOpen) { scene_manager_set_scene_state( - app->scene_manager, HexViewerSceneMenu, SubmenuIndexScene4); - scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_4); + app->scene_manager, HexViewerSceneMenu, SubmenuIndexOpen); + scene_manager_next_scene(app->scene_manager, HexViewerSceneOpen); // } else if (event.event == SubmenuIndexSettings) { // scene_manager_set_scene_state( // app->scene_manager, HexViewerSceneMenu, SubmenuIndexSettings); diff --git a/scenes/hex_viewer_scene_scene_4.c b/scenes/hex_viewer_scene_open.c similarity index 84% rename from scenes/hex_viewer_scene_scene_4.c rename to scenes/hex_viewer_scene_open.c index 406fec0..cd9e90b 100644 --- a/scenes/hex_viewer_scene_scene_4.c +++ b/scenes/hex_viewer_scene_open.c @@ -1,6 +1,6 @@ #include "../hex_viewer.h" -void hex_viewer_scene_scene_4_on_enter(void* context) { +void hex_viewer_scene_open_on_enter(void* context) { furi_assert(context); HexViewer* app = context; @@ -29,7 +29,7 @@ void hex_viewer_scene_scene_4_on_enter(void* context) { } } -bool hex_viewer_scene_scene_4_on_event(void* context, SceneManagerEvent event) { +bool hex_viewer_scene_open_on_event(void* context, SceneManagerEvent event) { UNUSED(context); UNUSED(event); bool consumed = true; @@ -37,6 +37,6 @@ bool hex_viewer_scene_scene_4_on_event(void* context, SceneManagerEvent event) { return consumed; } -void hex_viewer_scene_scene_4_on_exit(void* context) { +void hex_viewer_scene_open_on_exit(void* context) { UNUSED(context); } diff --git a/scenes/hex_viewer_scene_scene_1.c b/scenes/hex_viewer_scene_scroll.c similarity index 84% rename from scenes/hex_viewer_scene_scene_1.c rename to scenes/hex_viewer_scene_scroll.c index bdf34dc..d20e9cf 100644 --- a/scenes/hex_viewer_scene_scene_1.c +++ b/scenes/hex_viewer_scene_scroll.c @@ -1,14 +1,13 @@ #include "../hex_viewer.h" #include "../helpers/hex_viewer_custom_event.h" -#include "../views/hex_viewer_scene_1.h" -void hex_viewer_scene_scene_1_callback(void* context) { +void hex_viewer_scene_scroll_callback(void* context) { HexViewer* app = (HexViewer*)context; view_dispatcher_send_custom_event( app->view_dispatcher, HexViewerCustomEventMenuPercentEntered); } -void hex_viewer_scene_scene_1_on_enter(void* context) { +void hex_viewer_scene_scroll_on_enter(void* context) { furi_assert(context); HexViewer* app = context; @@ -17,16 +16,16 @@ void hex_viewer_scene_scene_1_on_enter(void* context) { text_input_set_header_text(text_input, "Scroll to percent (0..100)"); text_input_set_result_callback( text_input, - hex_viewer_scene_scene_1_callback, + hex_viewer_scene_scroll_callback, app, app->percent_buf, HEX_VIEWER_PERCENT_INPUT, false); - view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScene_1); + view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScroll); } -bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) { +bool hex_viewer_scene_scroll_on_event(void* context, SceneManagerEvent event) { HexViewer* app = (HexViewer*)context; bool consumed = false; @@ -57,6 +56,6 @@ bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) { return consumed; } -void hex_viewer_scene_scene_1_on_exit(void* context) { +void hex_viewer_scene_scroll_on_exit(void* context) { UNUSED(context); } diff --git a/scenes/hex_viewer_scene_startscreen.c b/scenes/hex_viewer_scene_startscreen.c index cbe6f33..6793655 100644 --- a/scenes/hex_viewer_scene_startscreen.c +++ b/scenes/hex_viewer_scene_startscreen.c @@ -27,7 +27,6 @@ bool hex_viewer_scene_startscreen_on_event(void* context, SceneManagerEvent even consumed = true; break; case HexViewerCustomEventStartscreenRight: - // TODO Dialog consumed = true; break; case HexViewerCustomEventStartscreenUp: @@ -38,7 +37,7 @@ bool hex_viewer_scene_startscreen_on_event(void* context, SceneManagerEvent even break; case HexViewerCustomEventStartscreenOk: if(!app->model->file_size) - scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_4); + scene_manager_next_scene(app->scene_manager, HexViewerSceneOpen); else scene_manager_next_scene(app->scene_manager, HexViewerSceneMenu); consumed = true; diff --git a/views/hex_viewer_scene_1.c b/views/hex_viewer_scene_1.c deleted file mode 100644 index ca961c9..0000000 --- a/views/hex_viewer_scene_1.c +++ /dev/null @@ -1,136 +0,0 @@ -#include "../hex_viewer.h" -#include -#include -#include -#include -#include - -struct HexViewerScene1 { - View* view; - HexViewerScene1Callback callback; - void* context; -}; - - -typedef struct { - int some_value; -} HexViewerScene1Model; - -void hex_viewer_scene_1_set_callback( - HexViewerScene1* instance, - HexViewerScene1Callback callback, - void* context) { - furi_assert(instance); - furi_assert(callback); - instance->callback = callback; - instance->context = context; -} - -void hex_viewer_scene_1_draw(Canvas* canvas, HexViewerScene1Model* model) { - UNUSED(model); - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, "This is Scene 1"); - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, "An empty scene to be"); - canvas_draw_str_aligned(canvas, 0, 32, AlignLeft, AlignTop, "used as hex_viewer"); -} - -static void hex_viewer_scene_1_model_init(HexViewerScene1Model* const model) { - model->some_value = 1; -} - -bool hex_viewer_scene_1_input(InputEvent* event, void* context) { - furi_assert(context); - HexViewerScene1* instance = context; - if (event->type == InputTypeRelease) { - switch(event->key) { - case InputKeyBack: - with_view_model( - instance->view, - HexViewerScene1Model * model, - { - UNUSED(model); - instance->callback(HexViewerCustomEventScene1Back, instance->context); - }, - true); - break; - case InputKeyLeft: - case InputKeyRight: - case InputKeyUp: - case InputKeyDown: - case InputKeyOk: - with_view_model( - instance->view, - HexViewerScene1Model* model, - { - UNUSED(model); - }, - true); - break; - case InputKeyMAX: - break; - } - } - return true; -} - -void hex_viewer_scene_1_exit(void* context) { - furi_assert(context); -} - -void hex_viewer_scene_1_enter(void* context) { - furi_assert(context); - HexViewerScene1* instance = (HexViewerScene1*)context; - with_view_model( - instance->view, - HexViewerScene1Model * model, - { - hex_viewer_scene_1_model_init(model); - }, - true - ); -} - -HexViewerScene1* hex_viewer_scene_1_alloc() { - HexViewerScene1* instance = malloc(sizeof(HexViewerScene1)); - instance->view = view_alloc(); - view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(HexViewerScene1Model)); - view_set_context(instance->view, instance); // furi_assert crashes in events without this - view_set_draw_callback(instance->view, (ViewDrawCallback)hex_viewer_scene_1_draw); - view_set_input_callback(instance->view, hex_viewer_scene_1_input); - view_set_enter_callback(instance->view, hex_viewer_scene_1_enter); - view_set_exit_callback(instance->view, hex_viewer_scene_1_exit); - - with_view_model( - instance->view, - HexViewerScene1Model * model, - { - hex_viewer_scene_1_model_init(model); - }, - true - ); - - return instance; -} - -void hex_viewer_scene_1_free(HexViewerScene1* instance) { - furi_assert(instance); - - with_view_model( - instance->view, - HexViewerScene1Model * model, - { - UNUSED(model); - }, - true); - view_free(instance->view); - free(instance); -} - -View* hex_viewer_scene_1_get_view(HexViewerScene1* instance) { - furi_assert(instance); - return instance->view; -} - diff --git a/views/hex_viewer_scene_1.h b/views/hex_viewer_scene_1.h deleted file mode 100644 index 0f87194..0000000 --- a/views/hex_viewer_scene_1.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include "../helpers/hex_viewer_custom_event.h" - -typedef struct HexViewerScene1 HexViewerScene1; - -typedef void (*HexViewerScene1Callback)(HexViewerCustomEvent event, void* context); - -void hex_viewer_scene_1_set_callback( - HexViewerScene1* hex_viewer_scene_1, - HexViewerScene1Callback callback, - void* context); - -View* hex_viewer_scene_1_get_view(HexViewerScene1* hex_viewer_static); - -HexViewerScene1* hex_viewer_scene_1_alloc(); - -void hex_viewer_scene_1_free(HexViewerScene1* hex_viewer_static); \ No newline at end of file diff --git a/views/hex_viewer_scene_2.c b/views/hex_viewer_scene_2.c deleted file mode 100644 index baa6182..0000000 --- a/views/hex_viewer_scene_2.c +++ /dev/null @@ -1,254 +0,0 @@ -#include "../hex_viewer.h" -#include -#include -#include -#include -#include -#include "../helpers/hex_viewer_haptic.h" -#include "../helpers/hex_viewer_speaker.h" -#include "../helpers/hex_viewer_led.h" - -struct HexViewerScene2 { - View* view; - HexViewerScene2Callback callback; - void* context; -}; - -typedef struct { - int screen_text; -} HexViewerScene2Model; - -char buttonText[11][14] = { - "", - "Press Up", - "Press Down", - "Press Left", - "Press Right", - "Press Ok", - "Release Up", - "Release Down", - "Release Left", - "Release Right", - "Release Ok", -}; - -void hex_viewer_scene_2_set_callback( - HexViewerScene2* instance, - HexViewerScene2Callback callback, - void* context) { - furi_assert(instance); - furi_assert(callback); - instance->callback = callback; - instance->context = context; -} - -void hex_viewer_scene_2_draw(Canvas* canvas, HexViewerScene2Model* model) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, "Scene 2: Input Examples"); - canvas_set_font(canvas, FontSecondary); - char *strInput = malloc(15); - strcpy(strInput, buttonText[model->screen_text]); - canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, strInput); - free(strInput); -} - -static void hex_viewer_scene_2_model_init(HexViewerScene2Model* const model) { - model->screen_text = 0; -} - -bool hex_viewer_scene_2_input(InputEvent* event, void* context) { - furi_assert(context); - HexViewerScene2* instance = context; - if (event->type == InputTypeRelease) { - switch(event->key) { - case InputKeyBack: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - UNUSED(model); - hex_viewer_stop_all_sound(instance->context); - instance->callback(HexViewerCustomEventScene2Back, instance->context); - hex_viewer_play_long_bump(instance->context); - }, - true); - break; - case InputKeyUp: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 6; - hex_viewer_play_bad_bump(instance->context); - hex_viewer_stop_all_sound(instance->context); - hex_viewer_led_set_rgb(instance->context, 255, 0, 255); - }, - true); - break; - case InputKeyDown: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 7; - hex_viewer_play_bad_bump(instance->context); - hex_viewer_stop_all_sound(instance->context); - hex_viewer_led_set_rgb(instance->context, 255, 255, 0); - }, - true); - break; - case InputKeyLeft: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 8; - hex_viewer_play_bad_bump(instance->context); - hex_viewer_stop_all_sound(instance->context); - hex_viewer_led_set_rgb(instance->context, 0, 255, 255); - }, - true); - break; - case InputKeyRight: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 9; - hex_viewer_play_bad_bump(instance->context); - hex_viewer_stop_all_sound(instance->context); - hex_viewer_led_set_rgb(instance->context, 255, 0, 0); - }, - true); - break; - case InputKeyOk: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 10; - hex_viewer_play_bad_bump(instance->context); - hex_viewer_stop_all_sound(instance->context); - hex_viewer_led_set_rgb(instance->context, 255, 255, 255); - }, - true); - break; - case InputKeyMAX: - break; - } - } else if (event->type == InputTypePress) { - switch(event->key) { - case InputKeyUp: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 1; - hex_viewer_play_happy_bump(instance->context); - hex_viewer_play_input_sound(instance->context); - }, - true); - break; - case InputKeyDown: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 2; - hex_viewer_play_happy_bump(instance->context); - hex_viewer_play_input_sound(instance->context); - }, - true); - break; - case InputKeyLeft: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 3; - hex_viewer_play_happy_bump(instance->context); - hex_viewer_play_input_sound(instance->context); - }, - true); - break; - case InputKeyRight: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 4; - hex_viewer_play_happy_bump(instance->context); - hex_viewer_play_input_sound(instance->context); - }, - true); - break; - case InputKeyOk: - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - model->screen_text = 5; - hex_viewer_play_happy_bump(instance->context); - hex_viewer_play_input_sound(instance->context); - }, - true); - break; - case InputKeyBack: - case InputKeyMAX: - break; - } - } - - return true; -} - -void hex_viewer_scene_2_exit(void* context) { - furi_assert(context); - HexViewer* app = context; - hex_viewer_stop_all_sound(app); - //hex_viewer_led_reset(app); -} - -void hex_viewer_scene_2_enter(void* context) { - furi_assert(context); - dolphin_deed(DolphinDeedPluginStart); -} - -HexViewerScene2* hex_viewer_scene_2_alloc() { - HexViewerScene2* instance = malloc(sizeof(HexViewerScene2)); - instance->view = view_alloc(); - view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(HexViewerScene2Model)); - view_set_context(instance->view, instance); - view_set_draw_callback(instance->view, (ViewDrawCallback)hex_viewer_scene_2_draw); - view_set_input_callback(instance->view, hex_viewer_scene_2_input); - //view_set_enter_callback(instance->view, hex_viewer_scene_2_enter); - view_set_exit_callback(instance->view, hex_viewer_scene_2_exit); - - with_view_model( - instance->view, - HexViewerScene2Model * model, - { - hex_viewer_scene_2_model_init(model); - }, - true); - - return instance; -} - -void hex_viewer_scene_2_free(HexViewerScene2* instance) { - furi_assert(instance); - - - view_free(instance->view); - free(instance); -} - -View* hex_viewer_scene_2_get_view(HexViewerScene2* instance) { - furi_assert(instance); - - - return instance->view; -} - diff --git a/views/hex_viewer_scene_2.h b/views/hex_viewer_scene_2.h deleted file mode 100644 index 299e0b1..0000000 --- a/views/hex_viewer_scene_2.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include "../helpers/hex_viewer_custom_event.h" - -typedef struct HexViewerScene2 HexViewerScene2; - -typedef void (*HexViewerScene2Callback)(HexViewerCustomEvent event, void* context); - -void hex_viewer_scene_2_set_callback( - HexViewerScene2* instance, - HexViewerScene2Callback callback, - void * context); - -HexViewerScene2* hex_viewer_scene_2_alloc(); - -void hex_viewer_scene_2_free(HexViewerScene2* hex_viewer_static); - -View* hex_viewer_scene_2_get_view(HexViewerScene2* boilerpate_static); diff --git a/views/hex_viewer_startscreen.c b/views/hex_viewer_startscreen.c index 841d141..ed40de8 100644 --- a/views/hex_viewer_startscreen.c +++ b/views/hex_viewer_startscreen.c @@ -147,14 +147,7 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) { break; case InputKeyRight: with_view_model( - instance->view, - HexViewerStartscreenModel * model, - { - // instance->callback(HexViewerCustomEventStartscreenRight, instance->context); - // update_local_model_from_app(instance->context, model); - model->dbg = 0; - }, - true); + instance->view, HexViewerStartscreenModel * model, { model->dbg = 0; }, true); break; case InputKeyUp: with_view_model(