diff --git a/nfc_playlist.c b/nfc_playlist.c index 773c1018e4a..902d5400270 100644 --- a/nfc_playlist.c +++ b/nfc_playlist.c @@ -117,7 +117,6 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) { furi_string_free(nfc_playlist->settings.base_file_path); furi_string_free(nfc_playlist->settings.file_path); - free(nfc_playlist->playlist_name); free(nfc_playlist); } diff --git a/scences/confirm_delete.c b/scences/confirm_delete.c index 5315c7ca3c6..9aee6c193a7 100644 --- a/scences/confirm_delete.c +++ b/scences/confirm_delete.c @@ -14,6 +14,7 @@ void nfc_playlist_confirm_delete_scene_on_enter(void* context) { FuriString* temp_str = furi_string_alloc(); char* file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path); furi_string_printf(temp_str, "\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path); + furi_string_replace(temp_str, ".txt", ""); widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false); widget_add_button_element(nfc_playlist->widget, GuiButtonTypeLeft, "Cancel", nfc_playlist_confirm_delete_menu_callback, nfc_playlist); @@ -27,16 +28,17 @@ void nfc_playlist_confirm_delete_scene_on_enter(void* context) { bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event) { NfcPlaylist* nfc_playlist = context; bool consumed = false; - Storage* storage = furi_record_open(RECORD_STORAGE); if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { - case GuiButtonTypeRight: { + case GuiButtonTypeRight: + Storage* storage = furi_record_open(RECORD_STORAGE); storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path)); nfc_playlist->settings.file_selected = false; nfc_playlist->settings.file_selected_check = false; nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path; + furi_record_close(RECORD_STORAGE); + consumed = true; break; - } default: break; } diff --git a/scences/emulation.c b/scences/emulation.c index d61d006cbcf..380f6a40ba4 100644 --- a/scences/emulation.c +++ b/scences/emulation.c @@ -3,61 +3,14 @@ NfcPlaylistEmulationState EmulationState = NfcPlaylistEmulationState_Stopped; -void nfc_playlist_emulation_scene_on_enter(void* context) { - NfcPlaylist* nfc_playlist = context; - nfc_playlist_emulation_setup(nfc_playlist); - nfc_playlist_emulation_start(nfc_playlist); -} - -bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event) { - UNUSED(context); - if (event.event == 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { - EmulationState = NfcPlaylistEmulationState_Canceled; - return true; - } - return false; -} - -void nfc_playlist_emulation_scene_on_exit(void* context) { - NfcPlaylist* nfc_playlist = context; - EmulationState = NfcPlaylistEmulationState_Stopped; - nfc_playlist_emulation_stop(nfc_playlist); - nfc_playlist_emulation_free(nfc_playlist); - popup_reset(nfc_playlist->popup); -} - -void nfc_playlist_emulation_setup(void* context) { - NfcPlaylist* nfc_playlist = context; - nfc_playlist->thread = furi_thread_alloc_ex("NfcPlaylistEmulationWorker", 8192, nfc_playlist_emulation_task, nfc_playlist); - nfc_playlist->nfc_playlist_worker = nfc_playlist_worker_alloc(); -} - -void nfc_playlist_emulation_free(NfcPlaylist* nfc_playlist) { - furi_assert(nfc_playlist); - furi_thread_free(nfc_playlist->thread); - nfc_playlist_worker_free(nfc_playlist->nfc_playlist_worker); - nfc_playlist->thread = NULL; - nfc_playlist->nfc_playlist_worker = NULL; -} - -void nfc_playlist_emulation_start(NfcPlaylist* nfc_playlist) { - furi_assert(nfc_playlist); - furi_thread_start(nfc_playlist->thread); -} - -void nfc_playlist_emulation_stop(NfcPlaylist* nfc_playlist) { - furi_assert(nfc_playlist); - furi_thread_join(nfc_playlist->thread); -} - int32_t nfc_playlist_emulation_task(void* context) { NfcPlaylist* nfc_playlist = context; Storage* storage = furi_record_open(RECORD_STORAGE); Stream* stream = file_stream_alloc(storage); FuriString* line = furi_string_alloc(); - FuriString* temp_header_str = furi_string_alloc(); - FuriString* temp_counter_str = furi_string_alloc(); + FuriString* tmp_header_str = furi_string_alloc(); + FuriString* tmp_counter_str = furi_string_alloc(); popup_reset(nfc_playlist->popup); popup_set_context(nfc_playlist->popup, nfc_playlist); @@ -70,15 +23,15 @@ int32_t nfc_playlist_emulation_task(void* context) { char* file_path = (char*)furi_string_get_cstr(line); - if (strlen(file_path) <= 1) {continue;} + if(strlen(file_path) <= 1) {continue;} - if (nfc_playlist->settings.emulate_delay > 0 && file_position != 0) { + if(nfc_playlist->settings.emulate_delay > 0 && file_position != 0) { popup_set_header(nfc_playlist->popup, "Delaying", 64, 10, AlignCenter, AlignTop); start_blink(nfc_playlist, NfcPlaylistLedState_Error); int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000); do { - furi_string_printf(temp_counter_str, "%ds", (time_counter_delay_ms/1000)); - popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); + furi_string_printf(tmp_counter_str, "%ds", (time_counter_delay_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_delay_ms -= 50; } while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); @@ -86,41 +39,41 @@ int32_t nfc_playlist_emulation_task(void* context) { file_position++; } - if (EmulationState != NfcPlaylistEmulationState_Emulating) {break;} + if(EmulationState != NfcPlaylistEmulationState_Emulating) {break;} char* file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path; char const* file_ext = &strrchr(file_path, '.')[1]; int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000); - if (storage_file_exists(storage, file_path) == false) { - furi_string_printf(temp_header_str, "ERROR not found:\n %s", file_name); - popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop); + if(storage_file_exists(storage, file_path) == false) { + furi_string_printf(tmp_header_str, "ERROR not found:\n%s", file_name); + popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop); start_blink(nfc_playlist, NfcPlaylistLedState_Error); do { - furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); + furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_ms -= 50; } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); } else if (strcasestr(file_ext, "nfc") == NULL) { - furi_string_printf(temp_header_str, "ERROR invalid file:\n %s", file_name); - popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop); + furi_string_printf(tmp_header_str, "ERROR invalid file:\n%s", file_name); + popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop); start_blink(nfc_playlist, NfcPlaylistLedState_Error); do { - furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); + furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_ms -= 50; } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); } else { - furi_string_printf(temp_header_str, "Emulating:\n %s", file_name); - popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop); + furi_string_printf(tmp_header_str, "Emulating:\n%s", file_name); + popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop); nfc_playlist_worker_set_nfc_data(nfc_playlist->nfc_playlist_worker, file_path); nfc_playlist_worker_start(nfc_playlist->nfc_playlist_worker); start_blink(nfc_playlist, NfcPlaylistLedState_Normal); do { - furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); + furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_ms -= 50; } while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); @@ -140,11 +93,59 @@ int32_t nfc_playlist_emulation_task(void* context) { } furi_string_free(line); - furi_string_free(temp_header_str); - furi_string_free(temp_counter_str); + furi_string_free(tmp_header_str); + furi_string_free(tmp_counter_str); file_stream_close(stream); furi_record_close(RECORD_STORAGE); stream_free(stream); return 0; +} + +void nfc_playlist_emulation_setup(void* context) { + NfcPlaylist* nfc_playlist = context; + nfc_playlist->thread = furi_thread_alloc_ex("NfcPlaylistEmulationWorker", 8192, nfc_playlist_emulation_task, nfc_playlist); + nfc_playlist->nfc_playlist_worker = nfc_playlist_worker_alloc(); +} + +void nfc_playlist_emulation_free(NfcPlaylist* nfc_playlist) { + furi_assert(nfc_playlist); + furi_thread_free(nfc_playlist->thread); + nfc_playlist_worker_free(nfc_playlist->nfc_playlist_worker); + nfc_playlist->thread = NULL; + nfc_playlist->nfc_playlist_worker = NULL; +} + +void nfc_playlist_emulation_start(NfcPlaylist* nfc_playlist) { + furi_assert(nfc_playlist); + furi_thread_start(nfc_playlist->thread); +} + +void nfc_playlist_emulation_stop(NfcPlaylist* nfc_playlist) { + furi_assert(nfc_playlist); + furi_thread_join(nfc_playlist->thread); +} + +void nfc_playlist_emulation_scene_on_enter(void* context) { + NfcPlaylist* nfc_playlist = context; + nfc_playlist_emulation_setup(nfc_playlist); + nfc_playlist_emulation_start(nfc_playlist); +} + +bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event) { + UNUSED(context); + bool consumed = false; + if(event.event == 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { + EmulationState = NfcPlaylistEmulationState_Canceled; + consumed = true; + } + return consumed; +} + +void nfc_playlist_emulation_scene_on_exit(void* context) { + NfcPlaylist* nfc_playlist = context; + EmulationState = NfcPlaylistEmulationState_Stopped; + nfc_playlist_emulation_stop(nfc_playlist); + nfc_playlist_emulation_free(nfc_playlist); + popup_reset(nfc_playlist->popup); } \ No newline at end of file diff --git a/scences/emulation.h b/scences/emulation.h index e99d5b6d292..6ec765aac78 100644 --- a/scences/emulation.h +++ b/scences/emulation.h @@ -13,12 +13,6 @@ void nfc_playlist_emulation_scene_on_enter(void* context); bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event); void nfc_playlist_emulation_scene_on_exit(void* context); -void nfc_playlist_emulation_setup(void* context); -void nfc_playlist_emulation_free(NfcPlaylist* nfc_playlist); -void nfc_playlist_emulation_start(NfcPlaylist* nfc_playlist); -void nfc_playlist_emulation_stop(NfcPlaylist* nfc_playlist); -int32_t nfc_playlist_emulation_task(void* context); - typedef enum NfcPlaylistEmulationState { NfcPlaylistEmulationState_Emulating, NfcPlaylistEmulationState_Stopped, diff --git a/scences/file_edit.c b/scences/file_edit.c index 1e16b1ceb80..8cd18a80cfb 100644 --- a/scences/file_edit.c +++ b/scences/file_edit.c @@ -1,25 +1,9 @@ #include "nfc_playlist.h" #include "scences/file_edit.h" -typedef enum { - NfcPlaylistMenuSelection_DeletePlaylist, - NfcPlaylistMenuSelection_RenamePlaylist -} NfcPlaylistMenuSelection; - void nfc_playlist_file_edit_menu_callback(void* context, uint32_t index) { NfcPlaylist* nfc_playlist = context; - switch(index) { - case NfcPlaylistMenuSelection_DeletePlaylist: { - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete); - break; - } - case NfcPlaylistMenuSelection_RenamePlaylist: { - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileRename); - break; - } - default: - break; - } + scene_manager_handle_custom_event(nfc_playlist->scene_manager, index); } void nfc_playlist_file_edit_scene_on_enter(void* context) { @@ -49,9 +33,23 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) { } bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event) { - UNUSED(event); - UNUSED(context); - return false; + NfcPlaylist* nfc_playlist = context; + bool consumed = false; + if(event.type == SceneManagerEventTypeCustom) { + switch(event.event) { + case NfcPlaylistMenuSelection_DeletePlaylist: + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete); + consumed = true; + break; + case NfcPlaylistMenuSelection_RenamePlaylist: + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileRename); + consumed = true; + break; + default: + break; + } + } + return consumed; } void nfc_playlist_file_edit_scene_on_exit(void* context) { diff --git a/scences/file_edit.h b/scences/file_edit.h index 08dca0ef3ca..0c986c424d5 100644 --- a/scences/file_edit.h +++ b/scences/file_edit.h @@ -6,4 +6,9 @@ void nfc_playlist_file_edit_scene_on_enter(void* context); bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event); -void nfc_playlist_file_edit_scene_on_exit(void* context); \ No newline at end of file +void nfc_playlist_file_edit_scene_on_exit(void* context); + +typedef enum { + NfcPlaylistMenuSelection_DeletePlaylist, + NfcPlaylistMenuSelection_RenamePlaylist +} NfcPlaylistFileEditMenuSelection; \ No newline at end of file diff --git a/scences/file_rename.c b/scences/file_rename.c index 9a42d4e672e..bba0bf1f271 100644 --- a/scences/file_rename.c +++ b/scences/file_rename.c @@ -4,26 +4,24 @@ void nfc_playlist_file_rename_menu_callback(void* context) { NfcPlaylist* nfc_playlist = context; Storage* storage = furi_record_open(RECORD_STORAGE); - FuriString* new_file_path = furi_string_alloc(); + FuriString* tmp_old_file_path = furi_string_alloc(); + FuriString* tmp_new_file_path = furi_string_alloc(); char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path); char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path; - int file_path_size = (strlen(old_file_path) - strlen(old_file_name) + 1); + furi_string_printf(tmp_old_file_path, "%s", old_file_path); + furi_string_replace(tmp_old_file_path, old_file_name, ""); - char* file_path = (char*)malloc(file_path_size); - snprintf(file_path, file_path_size, "%s", old_file_path); + furi_string_printf(tmp_new_file_path, "%s%s.txt", furi_string_get_cstr(tmp_old_file_path), nfc_playlist->playlist_name); - furi_string_printf(new_file_path, "%s%s.txt", file_path, nfc_playlist->playlist_name); - - if (!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) { - storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(new_file_path)); - nfc_playlist->settings.file_path = new_file_path; + if(!storage_file_exists(storage, furi_string_get_cstr(tmp_new_file_path))) { + storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(tmp_new_file_path)); + nfc_playlist->settings.file_path = furi_string_alloc_set_str(furi_string_get_cstr(tmp_new_file_path)); } - free(file_path); - free(nfc_playlist->playlist_name); furi_record_close(RECORD_STORAGE); - furi_string_free(new_file_path); + furi_string_free(tmp_new_file_path); + furi_string_free(tmp_old_file_path); scene_manager_previous_scene(nfc_playlist->scene_manager); } @@ -34,7 +32,7 @@ void nfc_playlist_file_rename_scene_on_enter(void* context) { text_input_set_header_text(nfc_playlist->text_input, "Enter new file name"); text_input_set_minimum_length(nfc_playlist->text_input, 1); text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->playlist_name, 50, true); - view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename); + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename); } bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event) { @@ -46,4 +44,5 @@ bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent ev void nfc_playlist_file_rename_scene_on_exit(void* context) { NfcPlaylist* nfc_playlist = context; text_input_reset(nfc_playlist->text_input); + free(nfc_playlist->playlist_name); } \ No newline at end of file diff --git a/scences/main_menu.c b/scences/main_menu.c index 838ec7cc9af..fd2871fc00f 100644 --- a/scences/main_menu.c +++ b/scences/main_menu.c @@ -1,38 +1,9 @@ #include "nfc_playlist.h" #include "scences/main_menu.h" -typedef enum { - NfcPlaylistEvent_ShowEmulatingPopup, - NfcPlaylistEvent_ShowFileSelect, - NfcPlaylistEvent_ShowFileEdit, - NfcPlaylistEvent_ShowSettings -} NfcPlaylistMainMenuEvent; - -typedef enum { - NfcPlaylistMenuSelection_Start, - NfcPlaylistMenuSelection_FileSelect, - NfcPlaylistMenuSelection_FileEdit, - NfcPlaylistMenuSelection_Settings -} NfcPlaylistMenuSelection; - void nfc_playlist_main_menu_menu_callback(void* context, uint32_t index) { NfcPlaylist* nfc_playlist = context; - switch(index) { - case NfcPlaylistMenuSelection_Start: - scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowEmulatingPopup); - break; - case NfcPlaylistMenuSelection_FileSelect: - scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowFileSelect); - break; - case NfcPlaylistMenuSelection_FileEdit: - scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowFileEdit); - break; - case NfcPlaylistMenuSelection_Settings: - scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowSettings); - break; - default: - break; - } + scene_manager_handle_custom_event(nfc_playlist->scene_manager, index); } void nfc_playlist_main_menu_scene_on_enter(void* context) { diff --git a/scences/main_menu.h b/scences/main_menu.h index 8644d2e16eb..7289bbf2a41 100644 --- a/scences/main_menu.h +++ b/scences/main_menu.h @@ -6,4 +6,18 @@ void nfc_playlist_main_menu_scene_on_enter(void* context); bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent event); -void nfc_playlist_main_menu_scene_on_exit(void* context); \ No newline at end of file +void nfc_playlist_main_menu_scene_on_exit(void* context); + +typedef enum { + NfcPlaylistEvent_ShowEmulatingPopup, + NfcPlaylistEvent_ShowFileSelect, + NfcPlaylistEvent_ShowFileEdit, + NfcPlaylistEvent_ShowSettings +} NfcPlaylistMainMenuEvent; + +typedef enum { + NfcPlaylistMenuSelection_Start, + NfcPlaylistMenuSelection_FileSelect, + NfcPlaylistMenuSelection_FileEdit, + NfcPlaylistMenuSelection_Settings +} NfcPlaylistMainMenuMenuSelection; \ No newline at end of file diff --git a/scences/settings.c b/scences/settings.c index cb4117e84a9..c93a3f4c672 100644 --- a/scences/settings.c +++ b/scences/settings.c @@ -1,35 +1,9 @@ #include "nfc_playlist.h" #include "scences/settings.h" -typedef enum { - NfcPlaylistSettings_Timeout, - NfcPlaylistSettings_Delay, - NfcPlaylistSettings_LedIndicator, - NfcPlaylistSettings_Reset -} NfcPlaylistMenuSelection; - void nfc_playlist_settings_menu_callback(void* context, uint32_t index) { NfcPlaylist* nfc_playlist = context; - FuriString* temp_str = furi_string_alloc(); - if (index == NfcPlaylistSettings_Reset) { - nfc_playlist->settings.emulate_timeout = default_emulate_timeout; - VariableItem* emulation_timeout_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Timeout); - variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout); - furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); - variable_item_set_current_value_text(emulation_timeout_settings, furi_string_get_cstr(temp_str)); - - nfc_playlist->settings.emulate_delay = default_emulate_delay; - VariableItem* emulation_delay_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Delay); - variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay); - furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); - variable_item_set_current_value_text(emulation_delay_settings, furi_string_get_cstr(temp_str)); - - nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator; - VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator); - variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator); - variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF"); - } - furi_string_free(temp_str); + scene_manager_handle_custom_event(nfc_playlist->scene_manager, index); } void nfc_playlist_settings_options_change_callback(VariableItem* item) { @@ -39,18 +13,16 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) { uint8_t option_value_index = variable_item_get_current_value_index(item); FuriString* temp_str = furi_string_alloc(); switch(current_option) { - case NfcPlaylistSettings_Timeout: { + case NfcPlaylistSettings_Timeout: nfc_playlist->settings.emulate_timeout = option_value_index; furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str)); break; - } - case NfcPlaylistSettings_Delay: { + case NfcPlaylistSettings_Delay: nfc_playlist->settings.emulate_delay = option_value_index; furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str)); break; - } case NfcPlaylistSettings_LedIndicator: nfc_playlist->settings.emulate_led_indicator = option_value_index; variable_item_set_current_value_text(item, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF"); @@ -106,9 +78,38 @@ void nfc_playlist_settings_scene_on_enter(void* context) { } bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event) { - UNUSED(context); - UNUSED(event); - return false; + NfcPlaylist* nfc_playlist = context; + bool consumed = false; + if (event.type == SceneManagerEventTypeCustom) { + switch(event.event) { + case NfcPlaylistSettings_Reset: + FuriString* temp_str = furi_string_alloc(); + + nfc_playlist->settings.emulate_timeout = default_emulate_timeout; + VariableItem* emulation_timeout_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Timeout); + variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout); + furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); + variable_item_set_current_value_text(emulation_timeout_settings, furi_string_get_cstr(temp_str)); + + nfc_playlist->settings.emulate_delay = default_emulate_delay; + VariableItem* emulation_delay_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Delay); + variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay); + furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); + variable_item_set_current_value_text(emulation_delay_settings, furi_string_get_cstr(temp_str)); + + nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator; + VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator); + variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator); + variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF"); + + furi_string_free(temp_str); + consumed = true; + break; + default: + break; + } + } + return consumed; } void nfc_playlist_settings_scene_on_exit(void* context) { diff --git a/scences/settings.h b/scences/settings.h index 2372b0b69c4..ecb8a933caf 100644 --- a/scences/settings.h +++ b/scences/settings.h @@ -6,4 +6,11 @@ void nfc_playlist_settings_scene_on_enter(void* context); bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event); -void nfc_playlist_settings_scene_on_exit(void* context); \ No newline at end of file +void nfc_playlist_settings_scene_on_exit(void* context); + +typedef enum { + NfcPlaylistSettings_Timeout, + NfcPlaylistSettings_Delay, + NfcPlaylistSettings_LedIndicator, + NfcPlaylistSettings_Reset +} NfcPlaylistSettingsMenuSelection; \ No newline at end of file