@@ -21,7 +21,6 @@ bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent even
2121 default :
2222 break ;
2323 }
24-
2524 return false;
2625}
2726
@@ -36,8 +35,7 @@ void nfc_playlist_emulation_scene_on_exit(void* context) {
3635void nfc_playlist_emulation_setup (void * context ) {
3736 NfcPlaylist * nfc_playlist = context ;
3837
39- nfc_playlist -> thread = furi_thread_alloc_ex (
40- "NfcPlaylistEmulationWorker" , 8192 , nfc_playlist_emulation_task , nfc_playlist );
38+ nfc_playlist -> thread = furi_thread_alloc_ex ("NfcPlaylistEmulationWorker" , 8192 , nfc_playlist_emulation_task , nfc_playlist );
4139 nfc_playlist -> nfc_playlist_worker = nfc_playlist_worker_alloc ();
4240}
4341
@@ -74,92 +72,93 @@ int32_t nfc_playlist_emulation_task(void* context) {
7472 if (file_stream_open (stream , furi_string_get_cstr (nfc_playlist -> file_path ), FSAM_READ , FSOM_OPEN_EXISTING )) {
7573 EmulationState = NfcPlaylistEmulationState_Emulating ;
7674 int file_position = 0 ;
77- // read the file line by line and print the text
7875 while (stream_read_line (stream , line ) && EmulationState == NfcPlaylistEmulationState_Emulating ) {
79- if (options_emulate_delay [nfc_playlist -> emulate_delay ] > 0 ) {
80- if (file_position > 0 ) {
81- popup_set_header (nfc_playlist -> popup , "Delaying" , 64 , 10 , AlignCenter , AlignTop );
82- start_error_blink (nfc_playlist );
83- int time_counter_delay_ms = (options_emulate_delay [nfc_playlist -> emulate_delay ] * 1000 );
84- do {
85- char display_text [10 ];
86- snprintf (display_text , 10 , "%ds" , (time_counter_delay_ms /1000 ));
87- popup_set_text (nfc_playlist -> popup , display_text , 64 , 50 , AlignCenter , AlignTop );
88- furi_delay_ms (500 );
89- time_counter_delay_ms -= 500 ;
90- } while (time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
91- } else {
92- file_position ++ ;
76+ if (strlen (furi_string_get_cstr (line )) > 1 ) {
77+ if (options_emulate_delay [nfc_playlist -> emulate_delay ] > 0 ) {
78+ if (file_position > 0 ) {
79+ popup_set_header (nfc_playlist -> popup , "Delaying" , 64 , 10 , AlignCenter , AlignTop );
80+ start_error_blink (nfc_playlist );
81+ int time_counter_delay_ms = (options_emulate_delay [nfc_playlist -> emulate_delay ] * 1000 );
82+ do {
83+ char display_text [10 ];
84+ snprintf (display_text , 10 , "%ds" , (time_counter_delay_ms /1000 ));
85+ popup_set_text (nfc_playlist -> popup , display_text , 64 , 50 , AlignCenter , AlignTop );
86+ furi_delay_ms (500 );
87+ time_counter_delay_ms -= 500 ;
88+ } while (time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
89+ } else {
90+ file_position ++ ;
91+ }
9392 }
94- }
9593
96- if (EmulationState != NfcPlaylistEmulationState_Emulating ) {
97- break ;
98- }
94+ if (EmulationState != NfcPlaylistEmulationState_Emulating ) {
95+ break ;
96+ }
9997
100- char * file_path = (char * )furi_string_get_cstr (line );
101- char * file_name ;
102- if (strchr (file_path , '/' ) != NULL ) {
103- file_name = & strrchr (file_path , '/' )[1 ];
104- } else {
105- file_name = file_path ;
106- }
107- char const * file_ext = & strrchr (file_path , '.' )[1 ];
108- int time_counter_ms = (options_emulate_timeout [nfc_playlist -> emulate_timeout ] * 1000 );
109-
110- if (storage_file_exists (storage , file_path ) == false) {
111- char popup_header_text [(18 + strlen (file_name ))];
112- snprintf (popup_header_text , (18 + strlen (file_name )), "%s\n%s" , "ERROR not found:" , file_name );
113- popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
114- start_error_blink (nfc_playlist );
115- while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
116- char popup_text [9 ];
117- snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
118- popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
119- furi_delay_ms (500 );
120- time_counter_ms -= 500 ;
98+ char * file_path = (char * )furi_string_get_cstr (line );
99+ char * file_name ;
100+ if (strchr (file_path , '/' ) != NULL ) {
101+ file_name = & strrchr (file_path , '/' )[1 ];
102+ } else {
103+ file_name = file_path ;
121104 }
122- }
105+ char const * file_ext = & strrchr (file_path , '.' )[1 ];
106+ int time_counter_ms = (options_emulate_timeout [nfc_playlist -> emulate_timeout ] * 1000 );
123107
124- else if (strcasestr (file_ext , "nfc" ) == NULL ) {
125- char popup_header_text [(21 + strlen (file_name ))];
126- snprintf (popup_header_text , (21 + strlen (file_name )), "%s\n%s" , "ERROR invalid file:" , file_name );
127- popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
128- start_error_blink (nfc_playlist );
129- while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
130- char popup_text [9 ];
131- snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
132- popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
133- furi_delay_ms (500 );
134- time_counter_ms -= 500 ;
108+ if (storage_file_exists (storage , file_path ) == false) {
109+ char popup_header_text [(18 + strlen (file_name ))];
110+ snprintf (popup_header_text , (18 + strlen (file_name )), "%s\n%s" , "ERROR not found:" , file_name );
111+ popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
112+ start_error_blink (nfc_playlist );
113+ while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
114+ char popup_text [9 ];
115+ snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
116+ popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
117+ furi_delay_ms (500 );
118+ time_counter_ms -= 500 ;
119+ }
135120 }
136- }
137121
138- else {
139- char popup_header_text [(12 + strlen (file_name ))];
140- snprintf (popup_header_text , (12 + strlen (file_name )), "%s\n%s" , "Emulating:" , file_name );
141- popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
142- nfc_playlist_worker_set_nfc_data (nfc_playlist -> nfc_playlist_worker , file_path );
143- nfc_playlist_worker_start (nfc_playlist -> nfc_playlist_worker );
144- start_normal_blink (nfc_playlist );
145- while (nfc_playlist_worker_is_emulating (nfc_playlist -> nfc_playlist_worker ) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
146- char popup_text [9 ];
147- snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
148- popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
149- furi_delay_ms (500 );
150- time_counter_ms -= 500 ;
122+ else if (strcasestr (file_ext , "nfc" ) == NULL ) {
123+ char popup_header_text [(21 + strlen (file_name ))];
124+ snprintf (popup_header_text , (21 + strlen (file_name )), "%s\n%s" , "ERROR invalid file:" , file_name );
125+ popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
126+ start_error_blink (nfc_playlist );
127+ while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
128+ char popup_text [9 ];
129+ snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
130+ popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
131+ furi_delay_ms (500 );
132+ time_counter_ms -= 500 ;
133+ }
134+ }
135+
136+ else {
137+ char popup_header_text [(12 + strlen (file_name ))];
138+ snprintf (popup_header_text , (12 + strlen (file_name )), "%s\n%s" , "Emulating:" , file_name );
139+ popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
140+ nfc_playlist_worker_set_nfc_data (nfc_playlist -> nfc_playlist_worker , file_path );
141+ nfc_playlist_worker_start (nfc_playlist -> nfc_playlist_worker );
142+ start_normal_blink (nfc_playlist );
143+ while (nfc_playlist_worker_is_emulating (nfc_playlist -> nfc_playlist_worker ) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
144+ char popup_text [9 ];
145+ snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
146+ popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
147+ furi_delay_ms (500 );
148+ time_counter_ms -= 500 ;
149+ }
150+ nfc_playlist_worker_stop (nfc_playlist -> nfc_playlist_worker );
151151 }
152- nfc_playlist_worker_stop (nfc_playlist -> nfc_playlist_worker );
153152 }
154153 }
155154 popup_reset (nfc_playlist -> popup );
156155 popup_set_header (nfc_playlist -> popup , EmulationState == NfcPlaylistEmulationState_Canceled ? "Emulation stopped" : "Emulation finished" , 64 , 10 , AlignCenter , AlignTop );
157156 popup_set_text (nfc_playlist -> popup , "Press back" , 64 , 50 , AlignCenter , AlignTop );
158157 stop_blink (nfc_playlist );
159- EmulationState = NfcPlaylistEmulationState_Stopped ;
158+ EmulationState = NfcPlaylistEmulationState_Stopped ;
160159 } else {
161- popup_set_header (nfc_playlist -> popup , "Error: " , 64 , 10 , AlignCenter , AlignTop );
162- popup_set_text (nfc_playlist -> popup , "Failed to open file\n/ext/apps_data/nfc_playlist/playlist.txt " , 64 , 25 , AlignCenter , AlignTop );
160+ popup_set_header (nfc_playlist -> popup , "Failed to open playlist " , 64 , 10 , AlignCenter , AlignTop );
161+ popup_set_text (nfc_playlist -> popup , "Press back " , 64 , 50 , AlignCenter , AlignTop );
163162 }
164163 // Free/close resources
165164 furi_string_free (line );
0 commit comments