Skip to content

Commit

Permalink
refactor: Massive rename and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
QtRoS committed Nov 6, 2023
1 parent 3d7a721 commit 6b43606
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 529 deletions.
11 changes: 2 additions & 9 deletions hex_viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
65 changes: 22 additions & 43 deletions hex_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <gui/modules/dialog_ex.h>
#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 <storage/storage.h>
Expand All @@ -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
Expand All @@ -40,76 +35,60 @@
#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;
uint32_t save_settings;
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;
6 changes: 3 additions & 3 deletions scenes/hex_viewer_scene_config.h
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
Expand All @@ -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);
}
34 changes: 15 additions & 19 deletions scenes/hex_viewer_scene_menu.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "../hex_viewer.h"

enum SubmenuIndex {
SubmenuIndexScene1 = 10,
SubmenuIndexScene2,
// SubmenuIndexScene3,
SubmenuIndexScene4,
// SubmenuIndexScene5,
SubmenuIndexScroll = 10,
SubmenuIndexInfo,
SubmenuIndexOpen,
// SubmenuIndexSettings,
};

Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -29,14 +29,14 @@ 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;

return consumed;
}

void hex_viewer_scene_scene_4_on_exit(void* context) {
void hex_viewer_scene_open_on_exit(void* context) {
UNUSED(context);
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
3 changes: 1 addition & 2 deletions scenes/hex_viewer_scene_startscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 6b43606

Please sign in to comment.