Skip to content

Commit

Permalink
feat: file browser added as an option into canplayer menu
Browse files Browse the repository at this point in the history
  • Loading branch information
AdonaiDiazEsparza committed Oct 21, 2024
1 parent 4615fff commit 0299b27
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
11 changes: 11 additions & 0 deletions Canbus_app/app_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Canbus_app/app_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <gui/modules/text_input.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/widget.h>
#include <gui/modules/file_browser.h>
#include <gui/modules/file_browser_worker.h>
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <storage/storage.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -151,6 +155,7 @@ typedef enum {
TextBoxView,
DialogInfoView,
InputByteView,
FileBrowserView,
} scenesViews;

char* sequential_file_resolve_path(
Expand Down
10 changes: 5 additions & 5 deletions Canbus_app/scenes/mainMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
55 changes: 42 additions & 13 deletions Canbus_app/scenes/playLogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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]);
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Canbus_app/scenes_config/app_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0299b27

Please sign in to comment.