@@ -27,26 +27,29 @@ int32_t nfc_playlist_main(void* p) {
27
27
Storage * storage = furi_record_open (RECORD_STORAGE );
28
28
Stream * stream = file_stream_alloc (storage );
29
29
FuriString * line = furi_string_alloc ();
30
- NfcDevice * nfcDevice = nfc_device_alloc ();
31
- Nfc * nfc = nfc_alloc ();
32
30
33
31
// Read file
34
32
if (file_stream_open (stream , APP_DATA_PATH ("playlistTest.txt" ), FSAM_READ , FSOM_OPEN_EXISTING )) {
33
+
34
+ // Get resources
35
+ NfcDevice * nfc_device = nfc_device_alloc ();
36
+ Nfc * nfc = nfc_alloc ();
37
+
35
38
while (stream_read_line (stream , line )) {
36
39
// Store file location
37
- const char * fileLocation = strcat ("/ext/nfc/" ,furi_string_get_cstr (line ));
40
+ const char * fileLocation = strcat ("/ext/nfc/" , furi_string_get_cstr (line ));
38
41
39
42
// Load file
40
- if (nfc_device_load (nfcDevice , fileLocation )) {
43
+ if (nfc_device_load (nfc_device , fileLocation )) {
41
44
42
45
if (DEBUG ) {FURI_LOG_I (TAG , "Loaded file" );}
43
46
44
47
// Get protocol
45
- const NfcProtocol protocol = nfc_device_get_protocol (nfcDevice );
48
+ const NfcProtocol nfc_protocol = nfc_device_get_protocol (nfc_device );
46
49
// Get listern
47
- NfcListener * mfu_listener = nfc_listener_alloc (nfc , protocol , nfc_device_get_data (nfcDevice , protocol ));
50
+ NfcListener * listener = nfc_listener_alloc (nfc , nfc_protocol , nfc_device_get_data (nfc_device , nfc_protocol ));
48
51
// Start listener
49
- nfc_listener_start (mfu_listener , NULL , NULL );
52
+ nfc_listener_start (listener , NULL , NULL );
50
53
51
54
// Worst timer ever
52
55
int counter = 0 ;
@@ -59,17 +62,22 @@ int32_t nfc_playlist_main(void* p) {
59
62
}
60
63
61
64
// Stop listener && free
62
- nfc_listener_stop (mfu_listener );
63
- nfc_listener_free (mfu_listener );
65
+ nfc_listener_stop (listener );
66
+ nfc_listener_free (listener );
64
67
65
68
} else {
66
69
if (DEBUG ) {FURI_LOG_E (TAG , "Failed to load file" );}
67
70
}
68
71
// output file location
69
72
if (DEBUG ) {FURI_LOG_I (TAG , "%s" , fileLocation );}
70
73
// clear instance
71
- nfc_device_clear (nfcDevice );
74
+ nfc_device_clear (nfc_device );
72
75
}
76
+
77
+ // Free/close resources
78
+ nfc_device_free (nfc_device );
79
+ nfc_free (nfc );
80
+
73
81
} else {
74
82
if (DEBUG ) {FURI_LOG_E (TAG , "Failed to open file" );}
75
83
}
@@ -78,8 +86,6 @@ int32_t nfc_playlist_main(void* p) {
78
86
furi_string_free (line );
79
87
file_stream_close (stream );
80
88
stream_free (stream );
81
- nfc_device_free (nfcDevice );
82
- nfc_free (nfc );
83
89
84
90
// Close storage
85
91
furi_record_close (RECORD_STORAGE );
0 commit comments