Просмотр исходного кода

upd hex viewer

fixes by Willy-JL
MX 1 год назад
Родитель
Сommit
3b83d0198e

+ 4 - 5
helpers/hex_viewer_haptic.c

@@ -1,10 +1,9 @@
 #include "hex_viewer_haptic.h"
 #include "../hex_viewer.h"
 
-
 void hex_viewer_play_happy_bump(void* context) {
     HexViewer* app = context;
-    if (app->haptic != 1) {
+    if(app->haptic != 1) {
         return;
     }
     notification_message(app->notification, &sequence_set_vibro_on);
@@ -14,7 +13,7 @@ void hex_viewer_play_happy_bump(void* context) {
 
 void hex_viewer_play_bad_bump(void* context) {
     HexViewer* app = context;
-    if (app->haptic != 1) {
+    if(app->haptic != 1) {
         return;
     }
     notification_message(app->notification, &sequence_set_vibro_on);
@@ -24,10 +23,10 @@ void hex_viewer_play_bad_bump(void* context) {
 
 void hex_viewer_play_long_bump(void* context) {
     HexViewer* app = context;
-    if (app->haptic != 1) {
+    if(app->haptic != 1) {
         return;
     }
-    for (int i = 0; i < 4; i++) {
+    for(int i = 0; i < 4; i++) {
         notification_message(app->notification, &sequence_set_vibro_on);
         furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
         notification_message(app->notification, &sequence_reset_vibro);

+ 0 - 1
helpers/hex_viewer_haptic.h

@@ -5,4 +5,3 @@ void hex_viewer_play_happy_bump(void* context);
 void hex_viewer_play_bad_bump(void* context);
 
 void hex_viewer_play_long_bump(void* context);
-

+ 6 - 6
helpers/hex_viewer_led.c

@@ -1,11 +1,9 @@
 #include "hex_viewer_led.h"
 #include "../hex_viewer.h"
 
-
-
 void hex_viewer_led_set_rgb(void* context, int red, int green, int blue) {
     HexViewer* app = context;
-    if (app->led != 1) {
+    if(app->led != 1) {
         return;
     }
     NotificationMessage notification_led_message_1;
@@ -26,7 +24,8 @@ void hex_viewer_led_set_rgb(void* context, int red, int green, int blue) {
         NULL,
     };
     notification_message(app->notification, &notification_sequence);
-    furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set    
+    furi_thread_flags_wait(
+        0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
 }
 
 void hex_viewer_led_reset(void* context) {
@@ -34,6 +33,7 @@ void hex_viewer_led_reset(void* context) {
     notification_message(app->notification, &sequence_reset_red);
     notification_message(app->notification, &sequence_reset_green);
     notification_message(app->notification, &sequence_reset_blue);
-    
-    furi_thread_flags_wait(0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set    
+
+    furi_thread_flags_wait(
+        0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set
 }

+ 0 - 1
helpers/hex_viewer_led.h

@@ -3,4 +3,3 @@
 void hex_viewer_led_set_rgb(void* context, int red, int green, int blue);
 
 void hex_viewer_led_reset(void* context);
-

+ 2 - 3
helpers/hex_viewer_speaker.c

@@ -5,19 +5,18 @@
 
 void hex_viewer_play_input_sound(void* context) {
     HexViewer* app = context;
-    if (app->speaker != 1) {
+    if(app->speaker != 1) {
         return;
     }
     float volume = 1.0f;
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
         furi_hal_speaker_start(NOTE_INPUT, volume);
     }
-    
 }
 
 void hex_viewer_stop_all_sound(void* context) {
     HexViewer* app = context;
-    if (app->speaker != 1) {
+    if(app->speaker != 1) {
         return;
     }
     if(furi_hal_speaker_is_mine()) {

+ 13 - 7
hex_viewer.c

@@ -45,9 +45,6 @@ HexViewer* hex_viewer_app_alloc() {
     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;
     app->speaker = 1;
@@ -61,6 +58,7 @@ HexViewer* hex_viewer_app_alloc() {
     // Load configs
     hex_viewer_read_settings(app);
 
+    app->submenu = submenu_alloc();
     view_dispatcher_add_view(
         app->view_dispatcher, HexViewerViewIdMenu, submenu_get_view(app->submenu));
 
@@ -70,6 +68,7 @@ HexViewer* hex_viewer_app_alloc() {
         HexViewerViewIdStartscreen,
         hex_viewer_startscreen_get_view(app->hex_viewer_startscreen));
 
+    app->text_input = text_input_alloc();
     view_dispatcher_add_view(
         app->view_dispatcher, HexViewerViewIdScroll, text_input_get_view(app->text_input));
 
@@ -97,12 +96,13 @@ void hex_viewer_app_free(HexViewer* app) {
 
     // View Dispatcher
     view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdMenu);
+    submenu_free(app->submenu);
     view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdStartscreen);
+    hex_viewer_startscreen_free(app->hex_viewer_startscreen);
     view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdScroll);
-    view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdSettings);
-
-    submenu_free(app->submenu);
     text_input_free(app->text_input);
+    view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdSettings);
+    variable_item_list_free(app->variable_item_list);
 
     view_dispatcher_free(app->view_dispatcher);
     furi_record_close(RECORD_STORAGE);
@@ -128,7 +128,13 @@ int32_t hex_viewer_app(void* p) {
 
     view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
 
-    scene_manager_next_scene(app->scene_manager, HexViewerSceneStartscreen);
+    if(p && strlen(p) && hex_viewer_open_file(app, (const char*)p)) {
+        hex_viewer_read_file(app);
+        scene_manager_next_scene(app->scene_manager, HexViewerSceneStartscreen);
+    } else {
+        scene_manager_next_scene(app->scene_manager, HexViewerSceneStartscreen);
+        scene_manager_next_scene(app->scene_manager, HexViewerSceneOpen);
+    }
 
     furi_hal_power_suppress_charge_enter();
 

+ 4 - 18
scenes/hex_viewer_scene_settings.c

@@ -43,7 +43,6 @@ const uint32_t settings_value[2] = {
     HexViewerSettingsOn,
 };
 
-
 static void hex_viewer_scene_settings_set_haptic(VariableItem* item) {
     HexViewer* app = variable_item_get_context(item);
     uint8_t index = variable_item_get_current_value_index(item);
@@ -85,33 +84,21 @@ void hex_viewer_scene_settings_on_enter(void* context) {
 
     // Vibro on/off
     item = variable_item_list_add(
-        app->variable_item_list,
-        "Vibro/Haptic:",
-        2,
-        hex_viewer_scene_settings_set_haptic,
-        app);
+        app->variable_item_list, "Vibro/Haptic:", 2, hex_viewer_scene_settings_set_haptic, app);
     value_index = value_index_uint32(app->haptic, haptic_value, 2);
     variable_item_set_current_value_index(item, value_index);
     variable_item_set_current_value_text(item, haptic_text[value_index]);
 
     // Sound on/off
     item = variable_item_list_add(
-        app->variable_item_list,
-        "Sound:",
-        2,
-        hex_viewer_scene_settings_set_speaker,
-        app);
+        app->variable_item_list, "Sound:", 2, hex_viewer_scene_settings_set_speaker, app);
     value_index = value_index_uint32(app->speaker, speaker_value, 2);
     variable_item_set_current_value_index(item, value_index);
     variable_item_set_current_value_text(item, speaker_text[value_index]);
 
     // LED Effects on/off
     item = variable_item_list_add(
-        app->variable_item_list,
-        "LED FX:",
-        2,
-        hex_viewer_scene_settings_set_led,
-        app);
+        app->variable_item_list, "LED FX:", 2, hex_viewer_scene_settings_set_led, app);
     value_index = value_index_uint32(app->led, led_value, 2);
     variable_item_set_current_value_index(item, value_index);
     variable_item_set_current_value_text(item, led_text[value_index]);
@@ -126,7 +113,7 @@ void hex_viewer_scene_settings_on_enter(void* context) {
     value_index = value_index_uint32(app->save_settings, settings_value, 2);
     variable_item_set_current_value_index(item, value_index);
     variable_item_set_current_value_text(item, settings_text[value_index]);
-    
+
     view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdSettings);
 }
 
@@ -135,7 +122,6 @@ bool hex_viewer_scene_settings_on_event(void* context, SceneManagerEvent event)
     UNUSED(app);
     bool consumed = false;
     if(event.type == SceneManagerEventTypeCustom) {
-        
     }
     return consumed;
 }