@@ -53,7 +53,7 @@ void nfc_playlist_emulation_stop(NfcPlaylist* nfc_playlist) {
53
53
54
54
int32_t nfc_playlist_emulation_task (void * context ) {
55
55
NfcPlaylist * nfc_playlist = context ;
56
- // open/alloc resources
56
+
57
57
Storage * storage = furi_record_open (RECORD_STORAGE );
58
58
Stream * stream = file_stream_alloc (storage );
59
59
FuriString * line = furi_string_alloc ();
@@ -62,87 +62,81 @@ int32_t nfc_playlist_emulation_task(void* context) {
62
62
popup_set_context (nfc_playlist -> popup , nfc_playlist );
63
63
view_dispatcher_switch_to_view (nfc_playlist -> view_dispatcher , NfcPlaylistView_Popup );
64
64
65
- // Read file
66
65
if (file_stream_open (stream , furi_string_get_cstr (nfc_playlist -> file_path ), FSAM_READ , FSOM_OPEN_EXISTING )) {
67
66
EmulationState = NfcPlaylistEmulationState_Emulating ;
68
67
int file_position = 0 ;
69
68
while (stream_read_line (stream , line ) && EmulationState == NfcPlaylistEmulationState_Emulating ) {
70
- if (strlen (furi_string_get_cstr (line )) > 1 ) {
71
- if (options_emulate_delay [nfc_playlist -> emulate_delay ] > 0 ) {
72
- if (file_position > 0 ) {
73
- popup_set_header (nfc_playlist -> popup , "Delaying" , 64 , 10 , AlignCenter , AlignTop );
74
- start_blink (nfc_playlist , NfcPlaylistLedState_Error );
75
- int time_counter_delay_ms = (options_emulate_delay [nfc_playlist -> emulate_delay ] * 1000 );
76
- do {
77
- char display_text [10 ];
78
- snprintf (display_text , 10 , "%ds" , (time_counter_delay_ms /1000 ));
79
- popup_set_text (nfc_playlist -> popup , display_text , 64 , 50 , AlignCenter , AlignTop );
80
- furi_delay_ms (500 );
81
- time_counter_delay_ms -= 500 ;
82
- } while (time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
83
- } else {
84
- file_position ++ ;
85
- }
86
- }
87
69
88
- if (EmulationState != NfcPlaylistEmulationState_Emulating ) {
89
- break ;
90
- }
70
+ char * file_path = (char * )furi_string_get_cstr (line );
91
71
92
- char * file_path = (char * )furi_string_get_cstr (line );
93
- char * file_name ;
94
- if (strchr (file_path , '/' ) != NULL ) {
95
- file_name = & strrchr (file_path , '/' )[1 ];
72
+ if (strlen (file_path ) <= 1 ) {continue ;}
73
+
74
+ if (nfc_playlist -> emulate_delay > 0 ) {
75
+ if (file_position > 0 ) {
76
+ popup_set_header (nfc_playlist -> popup , "Delaying" , 64 , 10 , AlignCenter , AlignTop );
77
+ start_blink (nfc_playlist , NfcPlaylistLedState_Error );
78
+ int time_counter_delay_ms = (options_emulate_delay [nfc_playlist -> emulate_delay ]* 1000 );
79
+ do {
80
+ char display_text [10 ];
81
+ snprintf (display_text , 10 , "%ds" , (time_counter_delay_ms /1000 ));
82
+ popup_set_text (nfc_playlist -> popup , display_text , 64 , 50 , AlignCenter , AlignTop );
83
+ furi_delay_ms (50 );
84
+ time_counter_delay_ms -= 50 ;
85
+ } while (time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
96
86
} else {
97
- file_name = file_path ;
87
+ file_position ++ ;
98
88
}
99
- char const * file_ext = & strrchr (file_path , '.' )[1 ];
100
- int time_counter_ms = (options_emulate_timeout [nfc_playlist -> emulate_timeout ] * 1000 );
89
+ }
101
90
102
- if (storage_file_exists (storage , file_path ) == false) {
103
- char popup_header_text [(18 + strlen (file_name ))];
104
- snprintf (popup_header_text , (18 + strlen (file_name )), "%s\n%s" , "ERROR not found:" , file_name );
105
- popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
106
- start_blink (nfc_playlist , NfcPlaylistLedState_Error );
107
- while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
108
- char popup_text [9 ];
109
- snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
110
- popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
111
- furi_delay_ms (500 );
112
- time_counter_ms -= 500 ;
113
- }
91
+ if (EmulationState != NfcPlaylistEmulationState_Emulating ) {break ;}
92
+
93
+ char * file_name = strchr (file_path , '/' ) != NULL ? & strrchr (file_path , '/' )[1 ] : file_path ;
94
+ char const * file_ext = & strrchr (file_path , '.' )[1 ];
95
+ int time_counter_ms = (options_emulate_timeout [nfc_playlist -> emulate_timeout ]* 1000 );
96
+
97
+ if (storage_file_exists (storage , file_path ) == false) {
98
+ char popup_header_text [(18 + strlen (file_name ))];
99
+ snprintf (popup_header_text , (18 + strlen (file_name )), "%s\n%s" , "ERROR not found:" , file_name );
100
+ popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
101
+ start_blink (nfc_playlist , NfcPlaylistLedState_Error );
102
+ while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
103
+ char popup_text [9 ];
104
+ snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
105
+ popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
106
+ furi_delay_ms (50 );
107
+ time_counter_ms -= 50 ;
114
108
}
109
+ }
115
110
116
- else if (strcasestr (file_ext , "nfc" ) == NULL ) {
117
- char popup_header_text [(21 + strlen (file_name ))];
118
- snprintf (popup_header_text , (21 + strlen (file_name )), "%s\n%s" , "ERROR invalid file:" , file_name );
119
- popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
120
- start_blink (nfc_playlist , NfcPlaylistLedState_Error );
121
- while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
122
- char popup_text [9 ];
123
- snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
124
- popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
125
- furi_delay_ms (500 );
126
- time_counter_ms -= 500 ;
127
- }
111
+ else if (strcasestr (file_ext , "nfc" ) == NULL ) {
112
+ char popup_header_text [(21 + strlen (file_name ))];
113
+ snprintf (popup_header_text , (21 + strlen (file_name )), "%s\n%s" , "ERROR invalid file:" , file_name );
114
+ popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
115
+ start_blink (nfc_playlist , NfcPlaylistLedState_Error );
116
+ while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
117
+ char popup_text [9 ];
118
+ snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
119
+ popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
120
+ furi_delay_ms (50 );
121
+ time_counter_ms -= 50 ;
128
122
}
123
+ }
129
124
130
- else {
131
- char popup_header_text [(12 + strlen (file_name ))];
132
- snprintf (popup_header_text , (12 + strlen (file_name )), "%s\n%s" , "Emulating:" , file_name );
133
- popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
134
- nfc_playlist_worker_set_nfc_data (nfc_playlist -> nfc_playlist_worker , file_path );
135
- nfc_playlist_worker_start (nfc_playlist -> nfc_playlist_worker );
136
- start_blink (nfc_playlist , NfcPlaylistLedState_Normal );
137
- while (nfc_playlist_worker_is_emulating (nfc_playlist -> nfc_playlist_worker ) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
138
- char popup_text [9 ];
139
- snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
140
- popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
141
- furi_delay_ms (500 );
142
- time_counter_ms -= 500 ;
143
- }
144
- nfc_playlist_worker_stop (nfc_playlist -> nfc_playlist_worker );
125
+ else {
126
+ char popup_header_text [(12 + strlen (file_name ))];
127
+ snprintf (popup_header_text , (12 + strlen (file_name )), "%s\n%s" , "Emulating:" , file_name );
128
+ popup_set_header (nfc_playlist -> popup , popup_header_text , 64 , 10 , AlignCenter , AlignTop );
129
+ nfc_playlist_worker_set_nfc_data (nfc_playlist -> nfc_playlist_worker , file_path );
130
+ nfc_playlist_worker_start (nfc_playlist -> nfc_playlist_worker );
131
+ start_blink (nfc_playlist , NfcPlaylistLedState_Normal );
132
+ while (nfc_playlist_worker_is_emulating (nfc_playlist -> nfc_playlist_worker ) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
133
+ char popup_text [9 ];
134
+ snprintf (popup_text , 9 , "%ds" , (time_counter_ms /1000 ));
135
+ popup_set_text (nfc_playlist -> popup , popup_text , 64 , 50 , AlignCenter , AlignTop );
136
+ furi_delay_ms (50 );
137
+ time_counter_ms -= 50 ;
145
138
}
139
+ nfc_playlist_worker_stop (nfc_playlist -> nfc_playlist_worker );
146
140
}
147
141
}
148
142
popup_reset (nfc_playlist -> popup );
@@ -154,10 +148,10 @@ int32_t nfc_playlist_emulation_task(void* context) {
154
148
popup_set_header (nfc_playlist -> popup , "Failed to open playlist" , 64 , 10 , AlignCenter , AlignTop );
155
149
popup_set_text (nfc_playlist -> popup , "Press back" , 64 , 50 , AlignCenter , AlignTop );
156
150
}
157
- // Free/close resources
151
+
158
152
furi_string_free (line );
159
153
file_stream_close (stream );
160
154
stream_free (stream );
161
- // Close storage
155
+
162
156
return 0 ;
163
157
}
0 commit comments