QtRoS 2 лет назад
Родитель
Сommit
9b5894bb59
3 измененных файлов с 55 добавлено и 36 удалено
  1. 3 1
      helpers/hex_viewer_custom_event.h
  2. 37 20
      hex_viewer.c
  3. 15 15
      scenes/hex_viewer_scene_scene_1.c

+ 3 - 1
helpers/hex_viewer_custom_event.h

@@ -25,6 +25,7 @@ enum HexViewerCustomEventType {
     // Reserve first 100 events for button types and indexes, starting from 0
     HexViewerCustomEventMenuVoid,
     HexViewerCustomEventMenuSelected,
+    HexViewerCustomEventMenuPercentEntered,
 };
 
 #pragma pack(push, 1)
@@ -41,7 +42,8 @@ static inline uint32_t hex_viewer_custom_menu_event_pack(uint16_t type, int16_t
     HexViewerCustomEventMenu event = {.content = {.type = type, .value = value}};
     return event.packed_value;
 }
-static inline void hex_viewer_custom_menu_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
+static inline void
+    hex_viewer_custom_menu_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
     HexViewerCustomEventMenu event = {.packed_value = packed_value};
     if(type) *type = event.content.type;
     if(value) *value = event.content.value;

+ 37 - 20
hex_viewer.c

@@ -1,6 +1,5 @@
 #include "hex_viewer.h"
 
-
 bool hex_viewer_custom_event_callback(void* context, uint32_t event) {
     furi_assert(context);
     HexViewer* app = context;
@@ -29,7 +28,7 @@ HexViewer* hex_viewer_app_alloc() {
     app->gui = furi_record_open(RECORD_GUI);
     app->storage = furi_record_open(RECORD_STORAGE);
     app->notification = furi_record_open(RECORD_NOTIFICATION);
-    
+
     //Turn backlight on, believe me this makes testing your app easier
     notification_message(app->notification, &sequence_display_backlight_on);
 
@@ -39,10 +38,15 @@ HexViewer* hex_viewer_app_alloc() {
 
     app->scene_manager = scene_manager_alloc(&hex_viewer_scene_handlers, app);
     view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
-    view_dispatcher_set_navigation_event_callback(app->view_dispatcher, hex_viewer_navigation_event_callback);
-    view_dispatcher_set_tick_event_callback(app->view_dispatcher, hex_viewer_tick_event_callback, 100);
-    view_dispatcher_set_custom_event_callback(app->view_dispatcher, hex_viewer_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(
+        app->view_dispatcher, hex_viewer_navigation_event_callback);
+    view_dispatcher_set_tick_event_callback(
+        app->view_dispatcher, hex_viewer_tick_event_callback, 100);
+    view_dispatcher_set_custom_event_callback(
+        app->view_dispatcher, hex_viewer_custom_event_callback);
+
     app->submenu = submenu_alloc();
+    app->text_input = text_input_alloc();
 
     // Set defaults, in case no config loaded
     app->haptic = 1;
@@ -57,18 +61,32 @@ HexViewer* hex_viewer_app_alloc() {
     // Load configs
     hex_viewer_read_settings(app);
 
-    view_dispatcher_add_view(app->view_dispatcher, HexViewerViewIdMenu, submenu_get_view(app->submenu));
+    view_dispatcher_add_view(
+        app->view_dispatcher, HexViewerViewIdMenu, submenu_get_view(app->submenu));
     app->hex_viewer_startscreen = hex_viewer_startscreen_alloc();
-    view_dispatcher_add_view(app->view_dispatcher, HexViewerViewIdStartscreen, hex_viewer_startscreen_get_view(app->hex_viewer_startscreen));
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        HexViewerViewIdStartscreen,
+        hex_viewer_startscreen_get_view(app->hex_viewer_startscreen));
     app->hex_viewer_scene_1 = hex_viewer_scene_1_alloc();
-    view_dispatcher_add_view(app->view_dispatcher, HexViewerViewIdScene1, hex_viewer_scene_1_get_view(app->hex_viewer_scene_1));
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        HexViewerViewIdScene1,
+        hex_viewer_scene_1_get_view(app->hex_viewer_scene_1));
     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));
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        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));
-    
+    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, HexViewerViewIdSettings, variable_item_list_get_view(app->variable_item_list));
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        HexViewerViewIdSettings,
+        variable_item_list_get_view(app->variable_item_list));
 
     //End Scene Additions
 
@@ -79,7 +97,7 @@ void hex_viewer_app_free(HexViewer* app) {
     furi_assert(app);
 
     if(app->model->stream) buffered_file_stream_close(app->model->stream);
-    
+
     // Scene manager
     scene_manager_free(app->scene_manager);
 
@@ -88,12 +106,14 @@ void hex_viewer_app_free(HexViewer* app) {
     view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdScene1);
     view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdScene2);
     view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdSettings);
+
     submenu_free(app->submenu);
+    text_input_free(app->text_input);
 
     view_dispatcher_free(app->view_dispatcher);
     furi_record_close(RECORD_STORAGE);
     furi_record_close(RECORD_GUI);
-    
+
     app->storage = NULL;
     app->gui = NULL;
     app->notification = NULL;
@@ -111,9 +131,9 @@ void hex_viewer_app_free(HexViewer* app) {
 int32_t hex_viewer_app(void* p) {
     UNUSED(p);
     HexViewer* app = hex_viewer_app_alloc();
-    
+
     view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
-    
+
     scene_manager_next_scene(app->scene_manager, HexViewerSceneStartscreen);
 
     furi_hal_power_suppress_charge_enter();
@@ -121,12 +141,9 @@ int32_t hex_viewer_app(void* p) {
     view_dispatcher_run(app->view_dispatcher);
 
     hex_viewer_save_settings(app);
-    
+
     furi_hal_power_suppress_charge_exit();
     hex_viewer_app_free(app);
 
     return 0;
 }
-
-
-

+ 15 - 15
scenes/hex_viewer_scene_scene_1.c

@@ -4,13 +4,14 @@
 
 void hex_viewer_scene_scene_1_callback(void* context) {
     HexViewer* app = (HexViewer*)context;
-    view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_RENAME_CUSTOM_EVENT);
+    view_dispatcher_send_custom_event(
+        app->view_dispatcher, HexViewerCustomEventMenuPercentEntered);
 }
 
 void hex_viewer_scene_scene_1_on_enter(void* context) {
     furi_assert(context);
     HexViewer* app = context;
-    
+
     TextInput* text_input = app->text_input;
 
     text_input_set_header_text(text_input, "Go to percent (0..100)");
@@ -26,11 +27,10 @@ void hex_viewer_scene_scene_1_on_enter(void* context) {
     //     IBUTTON_APP_FOLDER, IBUTTON_APP_FILENAME_EXTENSION, ibutton->key_name);
     // text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
 
-    view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScene1);
-
+    view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScene_1);
 
     // if(success) {
-    //     // 
+    //     //
     // }
 
     // if(success) {
@@ -50,15 +50,15 @@ bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
     bool consumed = false;
 
     if(event.type == SceneManagerEventTypeCustom) {
-        if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
-
-            float percent = atof(app->percent_buf);
-            percent = MIN(percent, 100.0);
-            percent = MAX(percent, 0);
-            percent = percent / 100;
-
-            uint32_t line_count = model->file_size / HEX_VIEWER_BYTES_PER_LINE;
-            if(model->file_size % HEX_VIEWER_BYTES_PER_LINE != 0) line_count += 1;
+        if(event.event == HexViewerCustomEventMenuPercentEntered) {
+            int ipercent = atoi(app->percent_buf);
+            // float percent = atof(app->percent_buf);
+            ipercent = MIN(ipercent, 100);
+            ipercent = MAX(ipercent, 0);
+            float percent = ipercent / 100.0;
+
+            uint32_t line_count = app->model->file_size / HEX_VIEWER_BYTES_PER_LINE;
+            if(app->model->file_size % HEX_VIEWER_BYTES_PER_LINE != 0) line_count += 1;
             uint32_t scrollable_lines = line_count - HEX_VIEWER_LINES_ON_SCREEN;
             uint32_t target_line = (uint32_t)(percent * scrollable_lines);
 
@@ -77,7 +77,7 @@ bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
             uint32_t new_file_offset = target_line * HEX_VIEWER_BYTES_PER_LINE;
             if(app->model->file_size > new_file_offset) {
                 app->model->file_offset = new_file_offset;
-                if(!hex_viewer_read_file(app)) break; // TODO Do smth
+                if(!hex_viewer_read_file(app)) new_file_offset = new_file_offset; // TODO Do smth
             }
 
             scene_manager_search_and_switch_to_previous_scene(