From 0299b27c86e24f7dd2c668e8bd5b58855853834e Mon Sep 17 00:00:00 2001 From: AdonaiDiazEsparza Date: Mon, 21 Oct 2024 10:06:45 -0600 Subject: [PATCH] feat: file browser added as an option into canplayer menu --- Canbus_app/app_user.c | 11 +++++ Canbus_app/app_user.h | 5 ++ Canbus_app/scenes/mainMenu.c | 10 ++-- Canbus_app/scenes/playLogs.c | 55 ++++++++++++++++----- Canbus_app/scenes_config/app_scene_config.h | 1 + 5 files changed, 64 insertions(+), 18 deletions(-) diff --git a/Canbus_app/app_user.c b/Canbus_app/app_user.c index 03305f8..882d27f 100644 --- a/Canbus_app/app_user.c +++ b/Canbus_app/app_user.c @@ -60,6 +60,14 @@ static App* app_alloc() { app->text = furi_string_alloc(); app->data = furi_string_alloc(); + app->path = furi_string_alloc(); + + furi_string_reset(app->data); + furi_string_cat_printf(app->data, "---"); + + app->file_browser = file_browser_alloc(app->path); + view_dispatcher_add_view( + app->view_dispatcher, FileBrowserView, file_browser_get_view(app->file_browser)); app->mcp_can = mcp_alloc(MCP_NORMAL, MCP_16MHZ, MCP_500KBPS); @@ -84,6 +92,7 @@ static void app_free(App* app) { view_dispatcher_remove_view(app->view_dispatcher, TextBoxView); view_dispatcher_remove_view(app->view_dispatcher, VarListView); view_dispatcher_remove_view(app->view_dispatcher, InputByteView); + view_dispatcher_remove_view(app->view_dispatcher, FileBrowserView); scene_manager_free(app->scene_manager); view_dispatcher_free(app->view_dispatcher); @@ -92,9 +101,11 @@ static void app_free(App* app) { submenu_free(app->submenu); text_box_free(app->textBox); byte_input_free(app->input_byte_value); + file_browser_free(app->file_browser); furi_string_free(app->text); furi_string_free(app->data); + furi_string_free(app->path); if(app->log_file && storage_file_is_open(app->log_file)) { storage_file_close(app->log_file); diff --git a/Canbus_app/app_user.h b/Canbus_app/app_user.h index b3204bf..c4a6033 100644 --- a/Canbus_app/app_user.h +++ b/Canbus_app/app_user.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include #include @@ -51,9 +53,11 @@ typedef struct { VariableItemList* varList; TextBox* textBox; ByteInput* input_byte_value; + FileBrowser* file_browser; FuriString* text; FuriString* data; + FuriString* path; Storage* storage; DialogsApp* dialogs; @@ -151,6 +155,7 @@ typedef enum { TextBoxView, DialogInfoView, InputByteView, + FileBrowserView, } scenesViews; char* sequential_file_resolve_path( diff --git a/Canbus_app/scenes/mainMenu.c b/Canbus_app/scenes/mainMenu.c index f19d1de..d33abbb 100644 --- a/Canbus_app/scenes/mainMenu.c +++ b/Canbus_app/scenes/mainMenu.c @@ -43,7 +43,7 @@ bool OpenLogFile(App* app) { } // Function to select log file -bool select_log_file(App* app) { +/*bool select_log_file(App* app) { FuriString* predefined_filepath = furi_string_alloc_set_str(PATHLOGS); FuriString* selected_filepath = furi_string_alloc(); DialogsFileBrowserOptions browser_options; @@ -65,7 +65,7 @@ bool select_log_file(App* app) { furi_string_free(selected_filepath); furi_string_free(predefined_filepath); return true; -} +}*/ // This function works to reset the values in the sender Option void reset_sender_values(void* context) { @@ -97,9 +97,9 @@ void basic_scenes_menu_callback(void* context, uint32_t index) { break; case PlayLOGOption: - if(select_log_file(app)) { - scene_manager_handle_custom_event(app->scene_manager, PlayLOGOptionEvent); - } + + scene_manager_handle_custom_event(app->scene_manager, PlayLOGOptionEvent); + break; case SettingsOption: diff --git a/Canbus_app/scenes/playLogs.c b/Canbus_app/scenes/playLogs.c index 74277c1..937db60 100644 --- a/Canbus_app/scenes/playLogs.c +++ b/Canbus_app/scenes/playLogs.c @@ -68,6 +68,7 @@ char* custom_strtok_r(char* str, const char* delim, char** saveptr) { return start; } +void path_file_name(const char* path, FuriString* file_name); void path_file_name(const char* path, FuriString* file_name) { uint8_t last_pos = 0; for(uint8_t i = 0; path[i] != '\0'; i++) { @@ -340,7 +341,7 @@ void play_data_frames_bk(void* context, int frame_interval) { debug = mcp2515_init(app->mcp_can); if(storage_file_open( - app->log_file, furi_string_get_cstr(app->data), FSAM_READ, FSOM_OPEN_EXISTING)) { + app->log_file, furi_string_get_cstr(app->path), FSAM_READ, FSOM_OPEN_EXISTING)) { log_info("File Open"); char buffer[256]; size_t buffer_index = 0; @@ -490,8 +491,6 @@ void play_data_frames_bk(void* context, int frame_interval) { int32_t thread_play_logs(void* context) { App* app = context; - UNUSED(app); - log_info("Entra al hilo"); play_data_frames_bk(app, TIMING_DEFAULT); @@ -506,6 +505,10 @@ void callback_input_player_options(void* context, uint32_t index) { UNUSED(app); switch(index) { + case 0: + scene_manager_next_scene(app->scene_manager, app_scene_file_browser_option); + break; + case 2: scene_manager_next_scene(app->scene_manager, app_scene_play_logs_widget); break; @@ -522,9 +525,6 @@ void callback_player_timing_options(VariableItem* item) { uint8_t selected_index = variable_item_list_get_selected_item_index(app->varList); switch(selected_index) { - case 0: - break; - case 1: uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, config_timing_names[index]); @@ -543,17 +543,12 @@ void app_scene_play_logs_on_enter(void* context) { VariableItem* item; - path_file_name(furi_string_get_cstr(app->data), app->text); - // reset list variable_item_list_reset(app->varList); // Choose File item = variable_item_list_add(app->varList, "File", 0, NULL, app); - - // Get the file Name - path_file_name(furi_string_get_cstr(app->data), app->text); - variable_item_set_current_value_text(item, furi_string_get_cstr(app->text)); + variable_item_set_current_value_text(item, furi_string_get_cstr(app->data)); // Timing options item = variable_item_list_add( @@ -570,7 +565,6 @@ void app_scene_play_logs_on_enter(void* context) { // Play the logs item = variable_item_list_add(app->varList, "Play", 0, NULL, app); - variable_item_set_values_count(item, 5); // Set the enter callback variable_item_list_set_enter_callback(app->varList, callback_input_player_options, app); @@ -595,6 +589,41 @@ bool app_scene_play_logs_on_event(void* context, SceneManagerEvent event) { return consumed; } +// File browser callback +void file_browser_callback(void* context) { + App* app = context; + path_file_name(furi_string_get_cstr(app->path), app->data); + scene_manager_previous_scene(app->scene_manager); +} + +// File Browser +void app_scene_file_browser_on_enter(void* context) { + App* app = context; + file_browser_configure(app->file_browser, ".log", PATHLOGS, true, true, NULL, true); + file_browser_set_callback(app->file_browser, file_browser_callback, app); + + furi_string_reset(app->text); + furi_string_cat(app->text, PATHLOGS); + + file_browser_start(app->file_browser, app->text); + view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserView); +} + +bool app_scene_file_browser_on_event(void* context, SceneManagerEvent event) { + App* app = context; + bool consumed = false; + + UNUSED(event); + UNUSED(app); + return consumed; +} + +void app_scene_file_browser_on_exit(void* context) { + App* app = context; + UNUSED(app); + file_browser_stop(app->file_browser); +} + // Test widget void app_scene_play_logs_widget_on_enter(void* context) { App* app = context; diff --git a/Canbus_app/scenes_config/app_scene_config.h b/Canbus_app/scenes_config/app_scene_config.h index 48b9177..c9d695e 100644 --- a/Canbus_app/scenes_config/app_scene_config.h +++ b/Canbus_app/scenes_config/app_scene_config.h @@ -28,4 +28,5 @@ ADD_SCENE(app, obdii_menu, obdii_option) ADD_SCENE(app, obdii_typical_codes, obdii_typical_codes_option) ADD_SCENE(app, draw_obdii, draw_obii_option) ADD_SCENE(app, play_logs, play_logs) +ADD_SCENE(app, file_browser, file_browser_option) ADD_SCENE(app, play_logs_widget, play_logs_widget)