diff --git a/lib/led/nfc_playlist_led.c b/lib/led/nfc_playlist_led.c index b214776b0de..e33ce911f04 100644 --- a/lib/led/nfc_playlist_led.c +++ b/lib/led/nfc_playlist_led.c @@ -26,7 +26,7 @@ const NotificationSequence blink_sequence_error = { }; void start_blink(NfcPlaylist* nfc_playlist, int state) { - if (nfc_playlist->emulate_led_indicator) { + if (nfc_playlist->settings.emulate_led_indicator) { if (state == NfcPlaylistLedState_Normal) { notification_message_block(nfc_playlist->notification, &blink_sequence_normal); } else if (state == NfcPlaylistLedState_Error) { @@ -36,7 +36,7 @@ void start_blink(NfcPlaylist* nfc_playlist, int state) { } void stop_blink(NfcPlaylist* nfc_playlist) { - if (nfc_playlist->emulate_led_indicator) { + if (nfc_playlist->settings.emulate_led_indicator) { notification_message_block(nfc_playlist->notification, &sequence_blink_stop); } } \ No newline at end of file diff --git a/nfc_playlist.c b/nfc_playlist.c index 9c8e7209820..83d4dee1057 100644 --- a/nfc_playlist.c +++ b/nfc_playlist.c @@ -2,102 +2,105 @@ #include "nfc_playlist_i.h" static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = { - nfc_playlist_main_menu_scene_on_enter, - nfc_playlist_settings_scene_on_enter, - nfc_playlist_emulation_scene_on_enter, - nfc_playlist_file_select_scene_on_enter, - nfc_playlist_file_edit_scene_on_enter, - nfc_playlist_text_input_scene_on_enter + nfc_playlist_main_menu_scene_on_enter, + nfc_playlist_settings_scene_on_enter, + nfc_playlist_emulation_scene_on_enter, + nfc_playlist_file_select_scene_on_enter, + nfc_playlist_file_edit_scene_on_enter, + nfc_playlist_text_input_scene_on_enter }; static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = { - nfc_playlist_main_menu_scene_on_event, - nfc_playlist_settings_scene_on_event, - nfc_playlist_emulation_scene_on_event, - nfc_playlist_file_select_scene_on_event, - nfc_playlist_file_edit_scene_on_event, - nfc_playlist_text_input_scene_on_event + nfc_playlist_main_menu_scene_on_event, + nfc_playlist_settings_scene_on_event, + nfc_playlist_emulation_scene_on_event, + nfc_playlist_file_select_scene_on_event, + nfc_playlist_file_edit_scene_on_event, + nfc_playlist_text_input_scene_on_event }; static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = { - nfc_playlist_main_menu_scene_on_exit, - nfc_playlist_settings_scene_on_exit, - nfc_playlist_emulation_scene_on_exit, - nfc_playlist_file_select_scene_on_exit, - nfc_playlist_file_edit_scene_on_exit, - nfc_playlist_text_input_scene_on_exit + nfc_playlist_main_menu_scene_on_exit, + nfc_playlist_settings_scene_on_exit, + nfc_playlist_emulation_scene_on_exit, + nfc_playlist_file_select_scene_on_exit, + nfc_playlist_file_edit_scene_on_exit, + nfc_playlist_text_input_scene_on_exit }; static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = { - .on_enter_handlers = nfc_playlist_scene_on_enter_handlers, - .on_event_handlers = nfc_playlist_scene_on_event_handlers, - .on_exit_handlers = nfc_playlist_scene_on_exit_handlers, - .scene_num = NfcPlaylistScene_count, + .on_enter_handlers = nfc_playlist_scene_on_enter_handlers, + .on_event_handlers = nfc_playlist_scene_on_event_handlers, + .on_exit_handlers = nfc_playlist_scene_on_exit_handlers, + .scene_num = NfcPlaylistScene_count }; static bool nfc_playlist_custom_callback(void* context, uint32_t custom_event) { - furi_assert(context); - NfcPlaylist* nfc_playlist = context; - return scene_manager_handle_custom_event(nfc_playlist->scene_manager, custom_event); + furi_assert(context); + NfcPlaylist* nfc_playlist = context; + return scene_manager_handle_custom_event(nfc_playlist->scene_manager, custom_event); } static bool nfc_playlist_back_event_callback(void* context) { - furi_assert(context); - NfcPlaylist* nfc_playlist = context; - return scene_manager_handle_back_event(nfc_playlist->scene_manager); + furi_assert(context); + NfcPlaylist* nfc_playlist = context; + return scene_manager_handle_back_event(nfc_playlist->scene_manager); } static NfcPlaylist* nfc_playlist_alloc() { - NfcPlaylist* nfc_playlist = malloc(sizeof(NfcPlaylist)); - furi_assert(nfc_playlist); - nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_manager_handlers, nfc_playlist); - nfc_playlist->view_dispatcher = view_dispatcher_alloc(); - view_dispatcher_enable_queue(nfc_playlist->view_dispatcher); - nfc_playlist->variable_item_list = variable_item_list_alloc(); - nfc_playlist->submenu = submenu_alloc(); - nfc_playlist->base_file_path = furi_string_alloc_set_str("/ext/apps_data/nfc_playlist/"); - nfc_playlist->file_path = nfc_playlist->base_file_path; - nfc_playlist->file_selected = false; - nfc_playlist->file_selected_check = false; - nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->file_path); - nfc_playlist->text_input = text_input_alloc(); - nfc_playlist->popup = popup_alloc(); - nfc_playlist->emulate_timeout = default_emulate_timeout; - nfc_playlist->emulate_delay = default_emulate_delay; - nfc_playlist->emulate_led_indicator = default_emulate_led_indicator; - nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION); - view_dispatcher_set_event_callback_context(nfc_playlist->view_dispatcher, nfc_playlist); - view_dispatcher_set_custom_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_custom_callback); - view_dispatcher_set_navigation_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_back_event_callback); - view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu, submenu_get_view(nfc_playlist->submenu)); - view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings, variable_item_list_get_view(nfc_playlist->variable_item_list)); - view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup)); - view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect, file_browser_get_view(nfc_playlist->file_browser)); - view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu)); - view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input)); - return nfc_playlist; + NfcPlaylist* nfc_playlist = malloc(sizeof(NfcPlaylist)); + furi_assert(nfc_playlist); + nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_manager_handlers, nfc_playlist); + nfc_playlist->view_dispatcher = view_dispatcher_alloc(); + view_dispatcher_enable_queue(nfc_playlist->view_dispatcher); + nfc_playlist->variable_item_list = variable_item_list_alloc(); + nfc_playlist->submenu = submenu_alloc(); + + nfc_playlist->settings.base_file_path = furi_string_alloc_set_str("/ext/apps_data/nfc_playlist/"); + nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path; + nfc_playlist->settings.file_selected = false; + nfc_playlist->settings.file_selected_check = false; + nfc_playlist->settings.emulate_timeout = default_emulate_timeout; + nfc_playlist->settings.emulate_delay = default_emulate_delay; + nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator; + + nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION); + nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->settings.file_path); + nfc_playlist->text_input = text_input_alloc(); + nfc_playlist->popup = popup_alloc(); + + view_dispatcher_set_event_callback_context(nfc_playlist->view_dispatcher, nfc_playlist); + view_dispatcher_set_custom_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_custom_callback); + view_dispatcher_set_navigation_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_back_event_callback); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu, submenu_get_view(nfc_playlist->submenu)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings, variable_item_list_get_view(nfc_playlist->variable_item_list)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect, file_browser_get_view(nfc_playlist->file_browser)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input)); + return nfc_playlist; } static void nfc_playlist_free(NfcPlaylist* nfc_playlist) { - furi_assert(nfc_playlist); - scene_manager_free(nfc_playlist->scene_manager); - view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu); - view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings); - view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup); - view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect); - view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit); - view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); - view_dispatcher_free(nfc_playlist->view_dispatcher); - variable_item_list_free(nfc_playlist->variable_item_list); - submenu_free(nfc_playlist->submenu); - file_browser_free(nfc_playlist->file_browser); - text_input_free(nfc_playlist->text_input); - popup_free(nfc_playlist->popup); - furi_record_close(RECORD_NOTIFICATION); - furi_string_free(nfc_playlist->base_file_path); - furi_string_free(nfc_playlist->file_path); - free(nfc_playlist->playlist_name); - free(nfc_playlist); + furi_assert(nfc_playlist); + scene_manager_free(nfc_playlist->scene_manager); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); + view_dispatcher_free(nfc_playlist->view_dispatcher); + variable_item_list_free(nfc_playlist->variable_item_list); + submenu_free(nfc_playlist->submenu); + file_browser_free(nfc_playlist->file_browser); + text_input_free(nfc_playlist->text_input); + popup_free(nfc_playlist->popup); + furi_record_close(RECORD_NOTIFICATION); + 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); } int32_t nfc_playlist_main(void* p) { diff --git a/nfc_playlist.h b/nfc_playlist.h index b1ba0a509fe..056b3d80fcc 100644 --- a/nfc_playlist.h +++ b/nfc_playlist.h @@ -33,6 +33,16 @@ typedef enum { NfcPlaylistScene_count } NfcPlaylistScene; +typedef struct { + FuriString* base_file_path; + FuriString* file_path; + bool file_selected; + bool file_selected_check; + uint8_t emulate_timeout; + uint8_t emulate_delay; + bool emulate_led_indicator; +} NfcPlaylistSettings; + typedef struct { SceneManager* scene_manager; ViewDispatcher* view_dispatcher; @@ -44,13 +54,7 @@ typedef struct { NotificationApp* notification; FuriThread* thread; NfcPlaylistWorker* nfc_playlist_worker; - FuriString* base_file_path; - bool file_selected; - bool file_selected_check; - uint8_t emulate_timeout; - uint8_t emulate_delay; - bool emulate_led_indicator; - FuriString* file_path; + NfcPlaylistSettings settings; char* playlist_name; } NfcPlaylist; diff --git a/scences/emulation.c b/scences/emulation.c index e3a86e07504..0f4d2168e66 100644 --- a/scences/emulation.c +++ b/scences/emulation.c @@ -4,163 +4,155 @@ 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); + 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; + 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); + 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; + 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(); + 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; + 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); + 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); + 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(); - - popup_reset(nfc_playlist->popup); - popup_set_context(nfc_playlist->popup, nfc_playlist); - view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup); - - if(file_stream_open(stream, furi_string_get_cstr(nfc_playlist->file_path), FSAM_READ, FSOM_OPEN_EXISTING) && nfc_playlist->file_selected_check) { - EmulationState = NfcPlaylistEmulationState_Emulating; - int file_position = 0; - while(stream_read_line(stream, line) && EmulationState == NfcPlaylistEmulationState_Emulating) { - - char* file_path = (char*)furi_string_get_cstr(line); - - if (strlen(file_path) <= 1) {continue;} - - if (nfc_playlist->emulate_delay > 0) { - if (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->emulate_delay]*1000); - do { - char display_text[10]; - snprintf(display_text, 10, "%ds", (time_counter_delay_ms/1000)); - popup_set_text(nfc_playlist->popup, display_text, 64, 50, AlignCenter, AlignTop); - furi_delay_ms(50); - time_counter_delay_ms -= 50; - } while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); - } else { - file_position++; - } + NfcPlaylist* nfc_playlist = context; + + Storage* storage = furi_record_open(RECORD_STORAGE); + Stream* stream = file_stream_alloc(storage); + FuriString* line = furi_string_alloc(); + + popup_reset(nfc_playlist->popup); + popup_set_context(nfc_playlist->popup, nfc_playlist); + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup); + + if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING) && nfc_playlist->settings.file_selected_check) { + EmulationState = NfcPlaylistEmulationState_Emulating; + int file_position = 0; + while(stream_read_line(stream, line) && EmulationState == NfcPlaylistEmulationState_Emulating) { + + char* file_path = (char*)furi_string_get_cstr(line); + + if (strlen(file_path) <= 1) {continue;} + + 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 { + char display_text[10]; + snprintf(display_text, 10, "%ds", (time_counter_delay_ms/1000)); + popup_set_text(nfc_playlist->popup, display_text, 64, 50, AlignCenter, AlignTop); + furi_delay_ms(50); + time_counter_delay_ms -= 50; + } while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); + } else if (nfc_playlist->settings.emulate_delay > 0) { + file_position++; + } + + if (EmulationState != NfcPlaylistEmulationState_Emulating) {break;} + + char const* full_file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path; + char file_name[sizeof(full_file_name)]; + strcpy(file_name, full_file_name); + strtok(file_name, "."); + 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) { + int popup_header_text_size = strlen(file_name) + 18; + char popup_header_text[popup_header_text_size]; + snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR not found:", file_name); + popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop); + start_blink(nfc_playlist, NfcPlaylistLedState_Error); + while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { + char popup_text[9]; + snprintf(popup_text, 9, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); + furi_delay_ms(50); + time_counter_ms -= 50; } - - if (EmulationState != NfcPlaylistEmulationState_Emulating) {break;} - - char const* full_file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path; - char file_name[sizeof(full_file_name)]; - strcpy(file_name, full_file_name); - strtok(file_name, "."); - char const* file_ext = &strrchr(file_path, '.')[1]; - int time_counter_ms = (options_emulate_timeout[nfc_playlist->emulate_timeout]*1000); - - if (storage_file_exists(storage, file_path) == false) { - int popup_header_text_size = strlen(file_name) + 18; - char popup_header_text[popup_header_text_size]; - snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR not found:", file_name); - popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop); - start_blink(nfc_playlist, NfcPlaylistLedState_Error); - while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { - char popup_text[9]; - snprintf(popup_text, 9, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); - furi_delay_ms(50); - time_counter_ms -= 50; - } - } - - else if (strcasestr(file_ext, "nfc") == NULL) { - int popup_header_text_size = strlen(file_name) + 21; - char popup_header_text[popup_header_text_size]; - snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR invalid file:", file_name); - popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop); - start_blink(nfc_playlist, NfcPlaylistLedState_Error); - while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { - char popup_text[9]; - snprintf(popup_text, 9, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); - furi_delay_ms(50); - time_counter_ms -= 50; - } + } else if (strcasestr(file_ext, "nfc") == NULL) { + int popup_header_text_size = strlen(file_name) + 21; + char popup_header_text[popup_header_text_size]; + snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR invalid file:", file_name); + popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop); + start_blink(nfc_playlist, NfcPlaylistLedState_Error); + while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { + char popup_text[9]; + snprintf(popup_text, 9, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); + furi_delay_ms(50); + time_counter_ms -= 50; } - - else { - int popup_header_text_size = strlen(file_name) + 12; - char popup_header_text[popup_header_text_size]; - snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "Emulating:", file_name); - popup_set_header(nfc_playlist->popup, popup_header_text, 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); - while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { - char popup_text[9]; - snprintf(popup_text, 9, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); - furi_delay_ms(50); - time_counter_ms -= 50; - } - nfc_playlist_worker_stop(nfc_playlist->nfc_playlist_worker); + } else { + int popup_header_text_size = strlen(file_name) + 12; + char popup_header_text[popup_header_text_size]; + snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "Emulating:", file_name); + popup_set_header(nfc_playlist->popup, popup_header_text, 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); + while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) { + char popup_text[9]; + snprintf(popup_text, 9, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); + furi_delay_ms(50); + time_counter_ms -= 50; } - } - popup_reset(nfc_playlist->popup); - popup_set_header(nfc_playlist->popup, EmulationState == NfcPlaylistEmulationState_Canceled ? "Emulation stopped" : "Emulation finished", 64, 10, AlignCenter, AlignTop); - popup_set_text(nfc_playlist->popup, "Press back", 64, 50, AlignCenter, AlignTop); - stop_blink(nfc_playlist); - EmulationState = NfcPlaylistEmulationState_Stopped; - } - - else { - popup_set_header(nfc_playlist->popup, "Failed to open playlist", 64, 10, AlignCenter, AlignTop); - popup_set_text(nfc_playlist->popup, "Press back", 64, 50, AlignCenter, AlignTop); - } - - furi_string_free(line); - file_stream_close(stream); - furi_record_close(RECORD_STORAGE); - stream_free(stream); - - return 0; + nfc_playlist_worker_stop(nfc_playlist->nfc_playlist_worker); + } + } + popup_reset(nfc_playlist->popup); + popup_set_header(nfc_playlist->popup, EmulationState == NfcPlaylistEmulationState_Canceled ? "Emulation stopped" : "Emulation finished", 64, 10, AlignCenter, AlignTop); + popup_set_text(nfc_playlist->popup, "Press back", 64, 50, AlignCenter, AlignTop); + stop_blink(nfc_playlist); + EmulationState = NfcPlaylistEmulationState_Stopped; + } else { + popup_set_header(nfc_playlist->popup, "Failed to open playlist", 64, 10, AlignCenter, AlignTop); + popup_set_text(nfc_playlist->popup, "Press back", 64, 50, AlignCenter, AlignTop); + } + + furi_string_free(line); + file_stream_close(stream); + furi_record_close(RECORD_STORAGE); + stream_free(stream); + + return 0; } \ No newline at end of file diff --git a/scences/file_edit.c b/scences/file_edit.c index 84dc7470ceb..3d3f1b7f922 100644 --- a/scences/file_edit.c +++ b/scences/file_edit.c @@ -12,10 +12,10 @@ void nfc_playlist_file_edit_menu_callback(void* context, uint32_t index) { Storage* storage = furi_record_open(RECORD_STORAGE); switch(index) { case NfcPlaylistMenuSelection_DeletePlaylist: { - storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->file_path)); - nfc_playlist->file_selected = false; - nfc_playlist->file_selected_check = false; - nfc_playlist->file_path = nfc_playlist->base_file_path; + 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; scene_manager_previous_scene(nfc_playlist->scene_manager); break; } @@ -43,7 +43,7 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) { NfcPlaylistMenuSelection_DeletePlaylist, nfc_playlist_file_edit_menu_callback, nfc_playlist, - !nfc_playlist->file_selected_check, + !nfc_playlist->settings.file_selected_check, "No\nplaylist\nselected"); submenu_add_lockable_item( @@ -52,7 +52,7 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) { NfcPlaylistMenuSelection_RenamePlaylist, nfc_playlist_file_edit_menu_callback, nfc_playlist, - !nfc_playlist->file_selected_check, + !nfc_playlist->settings.file_selected_check, "No\nplaylist\nselected"); view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit); diff --git a/scences/file_select.c b/scences/file_select.c index 5532dbba940..42f3ce67b53 100644 --- a/scences/file_select.c +++ b/scences/file_select.c @@ -3,7 +3,7 @@ void nfc_playlist_file_select_menu_callback(void* context) { NfcPlaylist* nfc_playlist = context; - nfc_playlist->file_selected_check = true; + nfc_playlist->settings.file_selected_check = true; scene_manager_previous_scene(nfc_playlist->scene_manager); } @@ -12,14 +12,14 @@ void nfc_playlist_file_select_scene_on_enter(void* context) { file_browser_configure( nfc_playlist->file_browser, ".txt", - furi_string_get_cstr(nfc_playlist->base_file_path), + furi_string_get_cstr(nfc_playlist->settings.base_file_path), true, true, &I_sub1_10px, true); view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect); file_browser_set_callback(nfc_playlist->file_browser, nfc_playlist_file_select_menu_callback, nfc_playlist); - file_browser_start(nfc_playlist->file_browser, nfc_playlist->base_file_path); + file_browser_start(nfc_playlist->file_browser, nfc_playlist->settings.base_file_path); } bool nfc_playlist_file_select_scene_on_event(void* context, SceneManagerEvent event) { diff --git a/scences/main_menu.c b/scences/main_menu.c index 9ba6e136357..919b59908e6 100644 --- a/scences/main_menu.c +++ b/scences/main_menu.c @@ -2,107 +2,107 @@ #include "scences/main_menu.h" typedef enum { - NfcPlaylistEvent_ShowEmulatingPopup, - NfcPlaylistEvent_ShowFileSelect, - NfcPlaylistEvent_ShowFileEdit, - NfcPlaylistEvent_ShowSettings + NfcPlaylistEvent_ShowEmulatingPopup, + NfcPlaylistEvent_ShowFileSelect, + NfcPlaylistEvent_ShowFileEdit, + NfcPlaylistEvent_ShowSettings } NfcPlaylistMainMenuEvent; typedef enum { - NfcPlaylistMenuSelection_Start, - NfcPlaylistMenuSelection_FileSelect, - NfcPlaylistMenuSelection_FileEdit, - NfcPlaylistMenuSelection_Settings, + 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; + 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; } } void nfc_playlist_main_menu_scene_on_enter(void* context) { - NfcPlaylist* nfc_playlist = context; - if (!nfc_playlist->file_selected) { - nfc_playlist->file_selected = true; - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileSelect); - return; - } + NfcPlaylist* nfc_playlist = context; + if (!nfc_playlist->settings.file_selected) { + nfc_playlist->settings.file_selected = true; + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileSelect); + return; + } - submenu_set_header(nfc_playlist->submenu, "NFC Playlist"); + submenu_set_header(nfc_playlist->submenu, "NFC Playlist"); - submenu_add_lockable_item( - nfc_playlist->submenu, - "Start", - NfcPlaylistMenuSelection_Start, - nfc_playlist_main_menu_menu_callback, - nfc_playlist, - !nfc_playlist->file_selected_check, - "No\nplaylist\nselected"); + submenu_add_lockable_item( + nfc_playlist->submenu, + "Start", + NfcPlaylistMenuSelection_Start, + nfc_playlist_main_menu_menu_callback, + nfc_playlist, + !nfc_playlist->settings.file_selected_check, + "No\nplaylist\nselected"); - submenu_add_item( - nfc_playlist->submenu, - "Select playlist", - NfcPlaylistMenuSelection_FileSelect, - nfc_playlist_main_menu_menu_callback, - nfc_playlist); - - submenu_add_item( - nfc_playlist->submenu, - "Edit playlist", - NfcPlaylistMenuSelection_FileEdit, - nfc_playlist_main_menu_menu_callback, - nfc_playlist); + submenu_add_item( + nfc_playlist->submenu, + "Select playlist", + NfcPlaylistMenuSelection_FileSelect, + nfc_playlist_main_menu_menu_callback, + nfc_playlist); + + submenu_add_item( + nfc_playlist->submenu, + "Edit playlist", + NfcPlaylistMenuSelection_FileEdit, + nfc_playlist_main_menu_menu_callback, + nfc_playlist); - submenu_add_item( - nfc_playlist->submenu, - "Settings", - NfcPlaylistMenuSelection_Settings, - nfc_playlist_main_menu_menu_callback, - nfc_playlist); + submenu_add_item( + nfc_playlist->submenu, + "Settings", + NfcPlaylistMenuSelection_Settings, + nfc_playlist_main_menu_menu_callback, + nfc_playlist); - view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu); + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu); } bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent event) { NfcPlaylist* nfc_playlist = context; bool consumed = false; if (event.type == SceneManagerEventTypeCustom) { - switch(event.event) { - case NfcPlaylistEvent_ShowEmulatingPopup: - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_EmulatingPopup); - consumed = true; - break; - case NfcPlaylistEvent_ShowFileSelect: - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileSelect); - consumed = true; - break; - case NfcPlaylistEvent_ShowFileEdit: - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileEdit); - consumed = true; - break; - case NfcPlaylistEvent_ShowSettings: - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_Settings); - consumed = true; - break; - default: - break; - } - } + switch(event.event) { + case NfcPlaylistEvent_ShowEmulatingPopup: + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_EmulatingPopup); + consumed = true; + break; + case NfcPlaylistEvent_ShowFileSelect: + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileSelect); + consumed = true; + break; + case NfcPlaylistEvent_ShowFileEdit: + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileEdit); + consumed = true; + break; + case NfcPlaylistEvent_ShowSettings: + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_Settings); + consumed = true; + break; + default: + break; + } + } return consumed; } diff --git a/scences/settings.c b/scences/settings.c index fb99383b611..a7e337e2eb3 100644 --- a/scences/settings.c +++ b/scences/settings.c @@ -2,113 +2,113 @@ #include "scences/settings.h" typedef enum { - NfcPlaylistSettings_Timeout, - NfcPlaylistSettings_Delay, - NfcPlaylistSettings_LedIndicator, - NfcPlaylistSettings_Reset + NfcPlaylistSettings_Timeout, + NfcPlaylistSettings_Delay, + NfcPlaylistSettings_LedIndicator, + NfcPlaylistSettings_Reset } NfcPlaylistMenuSelection; void nfc_playlist_settings_menu_callback(void* context, uint32_t index) { - NfcPlaylist* nfc_playlist = context; - if (index == NfcPlaylistSettings_Reset) { - nfc_playlist->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->emulate_timeout); - char emulation_timeout_settings_text[3]; - snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->emulate_timeout]); - variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text); - - nfc_playlist->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->emulate_delay); - char emulation_delay_settings_text[3]; - snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->emulate_delay]); - variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text); - - nfc_playlist->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->emulate_led_indicator); - variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator ? "ON" : "OFF"); - } + NfcPlaylist* nfc_playlist = context; + 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); + char emulation_timeout_settings_text[3]; + snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); + variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text); + + 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); + char emulation_delay_settings_text[3]; + snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); + variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text); + + 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"); + } } void nfc_playlist_settings_options_change_callback(VariableItem* item) { - NfcPlaylist* nfc_playlist = variable_item_get_context(item); - - uint8_t current_option = variable_item_list_get_selected_item_index(nfc_playlist->variable_item_list); - uint8_t option_value_index = variable_item_get_current_value_index(item); - - switch(current_option) { - case NfcPlaylistSettings_Timeout: { - nfc_playlist->emulate_timeout = option_value_index; - char emulate_timeout_text[3]; - snprintf(emulate_timeout_text, 3, "%ds", options_emulate_timeout[option_value_index]); - variable_item_set_current_value_text(item, (char*)emulate_timeout_text); - break; - } - case NfcPlaylistSettings_Delay: { - nfc_playlist->emulate_delay = option_value_index; - char emulate_delay_text[3]; - snprintf(emulate_delay_text, 3, "%ds", options_emulate_delay[option_value_index]); - variable_item_set_current_value_text(item, (char*)emulate_delay_text); - break; - } - case NfcPlaylistSettings_LedIndicator: - nfc_playlist->emulate_led_indicator = option_value_index; - variable_item_set_current_value_text(item, nfc_playlist->emulate_led_indicator ? "ON" : "OFF"); - break; - default: - break; + NfcPlaylist* nfc_playlist = variable_item_get_context(item); + + uint8_t current_option = variable_item_list_get_selected_item_index(nfc_playlist->variable_item_list); + uint8_t option_value_index = variable_item_get_current_value_index(item); + + switch(current_option) { + case NfcPlaylistSettings_Timeout: { + nfc_playlist->settings.emulate_timeout = option_value_index; + char emulate_timeout_text[3]; + snprintf(emulate_timeout_text, 3, "%ds", options_emulate_timeout[option_value_index]); + variable_item_set_current_value_text(item, (char*)emulate_timeout_text); + break; + } + case NfcPlaylistSettings_Delay: { + nfc_playlist->settings.emulate_delay = option_value_index; + char emulate_delay_text[3]; + snprintf(emulate_delay_text, 3, "%ds", options_emulate_delay[option_value_index]); + variable_item_set_current_value_text(item, (char*)emulate_delay_text); + 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"); + break; + default: + break; } } void nfc_playlist_settings_scene_on_enter(void* context) { - NfcPlaylist* nfc_playlist = context; - - variable_item_list_set_header(nfc_playlist->variable_item_list, "Settings"); - - VariableItem* emulation_timeout_settings = variable_item_list_add( - nfc_playlist->variable_item_list, - "Emulate time", - (sizeof(options_emulate_timeout)/sizeof(options_emulate_timeout[0])), - nfc_playlist_settings_options_change_callback, - nfc_playlist); - variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->emulate_timeout); - char emulation_timeout_settings_text[3]; - snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->emulate_timeout]); - variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text); - - VariableItem* emulation_delay_settings = variable_item_list_add( - nfc_playlist->variable_item_list, - "Delay time", - (sizeof(options_emulate_delay)/sizeof(options_emulate_delay[0])), - nfc_playlist_settings_options_change_callback, - nfc_playlist); - variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->emulate_delay); - char emulation_delay_settings_text[3]; - snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->emulate_delay]); - variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text); - - VariableItem* emulation_led_indicator_settings = variable_item_list_add( - nfc_playlist->variable_item_list, - "LED Indicator", - 2, - nfc_playlist_settings_options_change_callback, - nfc_playlist); - variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator); - variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator ? "ON" : "OFF"); - - variable_item_list_add(nfc_playlist->variable_item_list, "Reset settings", 0, NULL, NULL); - - variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_settings_menu_callback, nfc_playlist); - - view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings); + NfcPlaylist* nfc_playlist = context; + + variable_item_list_set_header(nfc_playlist->variable_item_list, "Settings"); + + VariableItem* emulation_timeout_settings = variable_item_list_add( + nfc_playlist->variable_item_list, + "Emulate time", + (sizeof(options_emulate_timeout)/sizeof(options_emulate_timeout[0])), + nfc_playlist_settings_options_change_callback, + nfc_playlist); + variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout); + char emulation_timeout_settings_text[3]; + snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); + variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text); + + VariableItem* emulation_delay_settings = variable_item_list_add( + nfc_playlist->variable_item_list, + "Delay time", + (sizeof(options_emulate_delay)/sizeof(options_emulate_delay[0])), + nfc_playlist_settings_options_change_callback, + nfc_playlist); + variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay); + char emulation_delay_settings_text[3]; + snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); + variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text); + + VariableItem* emulation_led_indicator_settings = variable_item_list_add( + nfc_playlist->variable_item_list, + "LED Indicator", + 2, + nfc_playlist_settings_options_change_callback, + nfc_playlist); + 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"); + + variable_item_list_add(nfc_playlist->variable_item_list, "Reset settings", 0, NULL, NULL); + + variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_settings_menu_callback, nfc_playlist); + + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings); } bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event) { - UNUSED(context); - UNUSED(event); - return false; + UNUSED(context); + UNUSED(event); + return false; } void nfc_playlist_settings_scene_on_exit(void* context) { diff --git a/scences/text_input.c b/scences/text_input.c index e3082eaeb09..f93a6c29af3 100644 --- a/scences/text_input.c +++ b/scences/text_input.c @@ -5,7 +5,7 @@ void nfc_playlist_text_input_menu_callback(void* context) { NfcPlaylist* nfc_playlist = context; Storage* storage = furi_record_open(RECORD_STORAGE); - char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->file_path); + 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); @@ -19,8 +19,8 @@ void nfc_playlist_text_input_menu_callback(void* context) { snprintf(new_file_name, new_file_path_size, "%s%s%s", file_path, nfc_playlist->playlist_name, ".txt"); if (!storage_file_exists(storage, new_file_name)) { - storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->file_path), new_file_name); - nfc_playlist->file_path = furi_string_alloc_set_str(new_file_name); + storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_name); + nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_name); } free(new_file_name);