Browse Source

feat: Works but with major input lag

QtRoS 2 years ago
parent
commit
96c74de13d
4 changed files with 23 additions and 59 deletions
  1. 19 19
      helpers/hex_viewer_storage.c
  2. 0 36
      hex_viewer.c
  3. 1 1
      hex_viewer.h
  4. 3 3
      views/hex_viewer_startscreen.c

+ 19 - 19
helpers/hex_viewer_storage.c

@@ -1,6 +1,5 @@
 #include "hex_viewer_storage.h"
 
-
 static Storage* hex_viewer_open_storage() {
     return furi_record_open(RECORD_STORAGE);
 }
@@ -10,21 +9,21 @@ 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);
@@ -32,12 +31,11 @@ void hex_viewer_save_settings(void* context) {
 
     // 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);
             }
@@ -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");
@@ -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();
@@ -111,7 +106,8 @@ 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);
 
@@ -119,12 +115,16 @@ void hex_viewer_read_settings(void* context) {
     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;
 

+ 0 - 36
hex_viewer.c

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

+ 1 - 1
hex_viewer.h

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

+ 3 - 3
views/hex_viewer_startscreen.c

@@ -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
     );
@@ -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,