Skip to content

Commit

Permalink
feat: Works but with major input lag
Browse files Browse the repository at this point in the history
  • Loading branch information
QtRoS committed Sep 30, 2023
1 parent 025d25a commit 96c74de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 59 deletions.
38 changes: 19 additions & 19 deletions helpers/hex_viewer_storage.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "hex_viewer_storage.h"


static Storage* hex_viewer_open_storage() {
return furi_record_open(RECORD_STORAGE);
}
Expand All @@ -10,34 +9,33 @@ static void hex_viewer_close_storage() {
}

static void hex_viewer_close_config_file(FlipperFormat* file) {
if (file == NULL) return;
if(file == NULL) return;
flipper_format_file_close(file);
flipper_format_free(file);
}

void hex_viewer_save_settings(void* context) {
HexViewer* app = context;
if (app->save_settings == 0) {
if(app->save_settings == 0) {
return;
}

FURI_LOG_D(TAG, "Saving Settings");
Storage* storage = hex_viewer_open_storage();
FlipperFormat* fff_file = flipper_format_file_alloc(storage);

// Overwrite wont work, so delete first
if(storage_file_exists(storage, HEX_VIEWER_SETTINGS_SAVE_PATH)) {
storage_simply_remove(storage, HEX_VIEWER_SETTINGS_SAVE_PATH);
}

// Open File, create if not exists
if(!storage_common_stat(storage, HEX_VIEWER_SETTINGS_SAVE_PATH, NULL) == FSE_OK) {
FURI_LOG_D(TAG, "Config file %s is not found. Will create new.", HEX_VIEWER_SETTINGS_SAVE_PATH);
FURI_LOG_D(
TAG, "Config file %s is not found. Will create new.", HEX_VIEWER_SETTINGS_SAVE_PATH);
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
FURI_LOG_D(
TAG,
"Directory %s doesn't exist. Will create new.",
CONFIG_FILE_DIRECTORY_PATH);
TAG, "Directory %s doesn't exist. Will create new.", CONFIG_FILE_DIRECTORY_PATH);
if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
FURI_LOG_E(TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
}
Expand All @@ -50,19 +48,16 @@ void hex_viewer_save_settings(void* context) {
hex_viewer_close_storage();
return;
}

// Store Settings
flipper_format_write_header_cstr(
fff_file, HEX_VIEWER_SETTINGS_HEADER, HEX_VIEWER_SETTINGS_FILE_VERSION);
flipper_format_write_uint32(
fff_file, HEX_VIEWER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
flipper_format_write_uint32(
fff_file, HEX_VIEWER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
flipper_format_write_uint32(
fff_file, HEX_VIEWER_SETTINGS_KEY_LED, &app->led, 1);
flipper_format_write_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
flipper_format_write_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
flipper_format_write_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_LED, &app->led, 1);
flipper_format_write_uint32(
fff_file, HEX_VIEWER_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);

if(!flipper_format_rewind(fff_file)) {
hex_viewer_close_config_file(fff_file);
FURI_LOG_E(TAG, "Rewind error");
Expand All @@ -87,7 +82,7 @@ void hex_viewer_read_settings(void* context) {
uint32_t file_version;
FuriString* temp_str = furi_string_alloc();

if (!flipper_format_file_open_existing(fff_file, HEX_VIEWER_SETTINGS_SAVE_PATH)) {
if(!flipper_format_file_open_existing(fff_file, HEX_VIEWER_SETTINGS_SAVE_PATH)) {
FURI_LOG_E(TAG, "Cannot open file %s", HEX_VIEWER_SETTINGS_SAVE_PATH);
hex_viewer_close_config_file(fff_file);
hex_viewer_close_storage();
Expand All @@ -111,20 +106,25 @@ void hex_viewer_read_settings(void* context) {
flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_LED, &app->led, 1);
flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
flipper_format_read_uint32(
fff_file, HEX_VIEWER_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);

flipper_format_rewind(fff_file);

hex_viewer_close_config_file(fff_file);
hex_viewer_close_storage();
}


bool hex_viewer_open_file(void* context, const char* file_path) {
HexViewer* hex_viewer = context;
furi_assert(hex_viewer);
furi_assert(file_path);

if(hex_viewer->model->stream) {
buffered_file_stream_close(hex_viewer->model->stream);
stream_free(hex_viewer->model->stream); // TODO Check
}

hex_viewer->model->stream = buffered_file_stream_alloc(hex_viewer->storage);
bool isOk = true;

Expand Down
36 changes: 0 additions & 36 deletions hex_viewer.c
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
#include "hex_viewer.h"


// 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;
// bool mode; // Print address or content

// Stream* stream;
// } HexViewerModel;


// // TODO Clean
// typedef struct {
// HexViewerModel* model;
// FuriMutex** mutex; // TODO Don't need?

// Gui* gui;
// Storage* storage;
// NotificationApp* notification;
// ViewDispatcher* view_dispatcher;
// Submenu* submenu;
// 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
// } HexViewer;


bool hex_viewer_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
HexViewer* app = context;
Expand Down
2 changes: 1 addition & 1 deletion hex_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef struct {
// TODO Clean
typedef struct {
HexViewerModel* model;
FuriMutex** mutex; // TODO Don't need?
//FuriMutex** mutex; // TODO Don't need?

Gui* gui;
Storage* storage;
Expand Down
6 changes: 3 additions & 3 deletions views/hex_viewer_startscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void hex_viewer_startscreen_enter(void* context) {
HexViewerStartscreenModel * model,
{
hex_viewer_startscreen_model_init(model);
// TODO update_local_model_from_app(instance->context, model);
update_local_model_from_app(instance->context, model);
},
true
);
Expand All @@ -215,8 +215,8 @@ HexViewerStartscreen* hex_viewer_startscreen_alloc() {
view_set_context(instance->view, instance); // furi_assert crashes in events without this
view_set_draw_callback(instance->view, (ViewDrawCallback)hex_viewer_startscreen_draw);
view_set_input_callback(instance->view, hex_viewer_startscreen_input);
//view_set_enter_callback(instance->view, hex_viewer_startscreen_enter);
//view_set_exit_callback(instance->view, hex_viewer_startscreen_exit);
view_set_enter_callback(instance->view, hex_viewer_startscreen_enter);
view_set_exit_callback(instance->view, hex_viewer_startscreen_exit);

with_view_model(
instance->view,
Expand Down

0 comments on commit 96c74de

Please sign in to comment.