From 91b7fb2e617f14f5f339491968d9c969e8db2b1f Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 15 May 2024 20:29:17 +0300 Subject: [PATCH] upd hex viewer fixes by Willy-JL --- .../hex_viewer/helpers/hex_viewer_haptic.c | 9 ++++---- .../hex_viewer/helpers/hex_viewer_haptic.h | 1 - base_pack/hex_viewer/helpers/hex_viewer_led.c | 12 +++++----- base_pack/hex_viewer/helpers/hex_viewer_led.h | 1 - .../hex_viewer/helpers/hex_viewer_speaker.c | 5 ++--- base_pack/hex_viewer/hex_viewer.c | 20 +++++++++++------ .../scenes/hex_viewer_scene_settings.c | 22 ++++--------------- 7 files changed, 29 insertions(+), 41 deletions(-) diff --git a/base_pack/hex_viewer/helpers/hex_viewer_haptic.c b/base_pack/hex_viewer/helpers/hex_viewer_haptic.c index b23eabbf142..b3d230468de 100644 --- a/base_pack/hex_viewer/helpers/hex_viewer_haptic.c +++ b/base_pack/hex_viewer/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); diff --git a/base_pack/hex_viewer/helpers/hex_viewer_haptic.h b/base_pack/hex_viewer/helpers/hex_viewer_haptic.h index c9eccb17e5d..ade33bc7808 100644 --- a/base_pack/hex_viewer/helpers/hex_viewer_haptic.h +++ b/base_pack/hex_viewer/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); - diff --git a/base_pack/hex_viewer/helpers/hex_viewer_led.c b/base_pack/hex_viewer/helpers/hex_viewer_led.c index 454c3c41481..d52fa5622f0 100644 --- a/base_pack/hex_viewer/helpers/hex_viewer_led.c +++ b/base_pack/hex_viewer/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, ¬ification_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 } diff --git a/base_pack/hex_viewer/helpers/hex_viewer_led.h b/base_pack/hex_viewer/helpers/hex_viewer_led.h index 060749f0c8b..ba0e1cdad75 100644 --- a/base_pack/hex_viewer/helpers/hex_viewer_led.h +++ b/base_pack/hex_viewer/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); - diff --git a/base_pack/hex_viewer/helpers/hex_viewer_speaker.c b/base_pack/hex_viewer/helpers/hex_viewer_speaker.c index f834a565f26..4ee3de8dc08 100644 --- a/base_pack/hex_viewer/helpers/hex_viewer_speaker.c +++ b/base_pack/hex_viewer/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()) { diff --git a/base_pack/hex_viewer/hex_viewer.c b/base_pack/hex_viewer/hex_viewer.c index 6246faa76bb..916ed9f7c30 100644 --- a/base_pack/hex_viewer/hex_viewer.c +++ b/base_pack/hex_viewer/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(); diff --git a/base_pack/hex_viewer/scenes/hex_viewer_scene_settings.c b/base_pack/hex_viewer/scenes/hex_viewer_scene_settings.c index f9c4cafbc89..70a8b3a4161 100644 --- a/base_pack/hex_viewer/scenes/hex_viewer_scene_settings.c +++ b/base_pack/hex_viewer/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; }