From 3d7a721d5d3218fec7f3ccd0223cc944401345ce Mon Sep 17 00:00:00 2001 From: Roman Shchekin Date: Mon, 6 Nov 2023 15:17:17 +0300 Subject: [PATCH] refactor: scene 3 deleted --- hex_viewer.c | 4 - hex_viewer.h | 54 +++++++----- scenes/hex_viewer_scene_config.h | 1 - scenes/hex_viewer_scene_scene_3.c | 141 ------------------------------ 4 files changed, 30 insertions(+), 170 deletions(-) delete mode 100644 scenes/hex_viewer_scene_scene_3.c diff --git a/hex_viewer.c b/hex_viewer.c index d9a068e7380..5be549c3fe0 100644 --- a/hex_viewer.c +++ b/hex_viewer.c @@ -79,10 +79,6 @@ HexViewer* hex_viewer_app_alloc() { HexViewerViewIdScene2, hex_viewer_scene_2_get_view(app->hex_viewer_scene_2)); - app->button_menu = button_menu_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, HexViewerViewIdScene3, button_menu_get_view(app->button_menu)); - app->variable_item_list = variable_item_list_alloc(); view_dispatcher_add_view( app->view_dispatcher, diff --git a/hex_viewer.h b/hex_viewer.h index d4c7d83396b..c94d8a5f8d0 100644 --- a/hex_viewer.h +++ b/hex_viewer.h @@ -43,41 +43,43 @@ // 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; + HexViewerScene1 *hex_viewer_scene_1; + HexViewerScene2 *hex_viewer_scene_2; + DialogsApp *dialogs; // File Browser + FuriString *file_path; // File Browser uint32_t haptic; uint32_t speaker; uint32_t led; uint32_t save_settings; - ButtonMenu* button_menu; // Button Menu char percent_buf[HEX_VIEWER_PERCENT_INPUT]; } HexViewer; -typedef enum { +typedef enum +{ HexViewerViewIdStartscreen, HexViewerViewIdMenu, HexViewerViewIdScene1, @@ -88,22 +90,26 @@ typedef enum { 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 d7645201dde..eafe88d5c23 100644 --- a/scenes/hex_viewer_scene_config.h +++ b/scenes/hex_viewer_scene_config.h @@ -2,6 +2,5 @@ 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_3, Scene_3) ADD_SCENE(hex_viewer, scene_4, Scene_4) ADD_SCENE(hex_viewer, settings, Settings) \ No newline at end of file diff --git a/scenes/hex_viewer_scene_scene_3.c b/scenes/hex_viewer_scene_scene_3.c deleted file mode 100644 index cfe263e08f1..00000000000 --- a/scenes/hex_viewer_scene_scene_3.c +++ /dev/null @@ -1,141 +0,0 @@ -#include "../hex_viewer.h" -#include "../helpers/hex_viewer_custom_event.h" -#include "../helpers/hex_viewer_haptic.h" -#include "../helpers/hex_viewer_led.h" - -typedef enum { - ButtonIndexControl3 = -3, - ButtonIndexControl2 = -2, - ButtonIndexControl1 = -1, - ButtonIndexButton1 = 0, - ButtonIndexButton2 = 1, - ButtonIndexButton3 = 2, -} ButtonIndex; - -static void hex_viewer_scene_3_callback(void* context, int32_t index, InputType type) { - HexViewer* app = context; - - uint16_t custom_type; - if(type == InputTypePress) { - custom_type = HexViewerCustomEventMenuSelected; - } else if(type == InputTypeRelease) { - custom_type = HexViewerCustomEventMenuVoid; - } else if(type == InputTypeShort) { - //somehow ButtonMenuItemTypeCommon uses InputTypeShort - custom_type = HexViewerCustomEventMenuSelected; - } else { - furi_crash("Unexpected Input Type"); - } - view_dispatcher_send_custom_event(app->view_dispatcher, hex_viewer_custom_menu_event_pack(custom_type, index)); -} - -void hex_viewer_scene_scene_3_on_enter(void* context) { - furi_assert(context); - HexViewer* app = context; - ButtonMenu* button_menu = app->button_menu; - SceneManager* scene_manager = app->scene_manager; - - button_menu_add_item( - button_menu, - "Common", - ButtonIndexButton1, - hex_viewer_scene_3_callback, - ButtonMenuItemTypeCommon, - context); - button_menu_add_item( - button_menu, - "Button", - ButtonIndexButton2, - hex_viewer_scene_3_callback, - ButtonMenuItemTypeCommon, - context); - button_menu_add_item( - button_menu, - "Examples", - ButtonIndexButton1, - hex_viewer_scene_3_callback, - ButtonMenuItemTypeCommon, - context); - - button_menu_add_item( - button_menu, - "Control", - ButtonIndexControl1, - hex_viewer_scene_3_callback, - ButtonMenuItemTypeControl, - context); - - button_menu_add_item( - button_menu, - "Button", - ButtonIndexControl2, - hex_viewer_scene_3_callback, - ButtonMenuItemTypeControl, - context); - - button_menu_add_item( - button_menu, - "Examples", - ButtonIndexControl3, - hex_viewer_scene_3_callback, - ButtonMenuItemTypeControl, - context); - - button_menu_set_header(button_menu, "Button Menu"); - const int16_t button_index = - (signed)scene_manager_get_scene_state(app->scene_manager, HexViewerViewIdScene3); - button_menu_set_selected_item(button_menu, button_index); - scene_manager_set_scene_state(scene_manager, HexViewerSceneScene_3, ButtonIndexButton1); - - view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdScene3); -} - -bool hex_viewer_scene_scene_3_on_event(void* context, SceneManagerEvent event) { - HexViewer* app = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - const uint16_t custom_type = hex_viewer_custom_menu_event_get_type(event.event); - const int16_t button_index = hex_viewer_custom_menu_event_get_value(event.event); - if (custom_type == HexViewerCustomEventMenuSelected) { - switch(button_index) { - case ButtonIndexButton1: - hex_viewer_play_happy_bump(app); - hex_viewer_led_set_rgb(app, 255, 0, 0); - break; - case ButtonIndexButton2: - hex_viewer_play_happy_bump(app); - hex_viewer_led_set_rgb(app, 0, 255, 0); - break; - case ButtonIndexButton3: - hex_viewer_play_happy_bump(app); - hex_viewer_led_set_rgb(app, 0, 0, 255); - break; - case ButtonIndexControl1: - hex_viewer_play_bad_bump(app); - hex_viewer_led_set_rgb(app, 255, 0, 255); - break; - case ButtonIndexControl2: - hex_viewer_play_bad_bump(app); - hex_viewer_led_set_rgb(app, 255, 255, 0); - break; - case ButtonIndexControl3: - hex_viewer_play_bad_bump(app); - hex_viewer_led_set_rgb(app, 0, 255, 255); - break; - } - consumed = true; - } - } - - return consumed; -} - -void hex_viewer_scene_scene_3_on_exit(void* context) { - HexViewer* app = context; - button_menu_reset(app->button_menu); - notification_message(app->notification, &sequence_reset_red); - notification_message(app->notification, &sequence_reset_green); - notification_message(app->notification, &sequence_reset_blue); -} -