acegoal07 2 лет назад
Родитель
Сommit
6a34f2b551
2 измененных файлов с 19 добавлено и 13 удалено
  1. 1 1
      application.fam
  2. 18 12
      nfc_playlist.c

+ 1 - 1
application.fam

@@ -1,6 +1,6 @@
 App(
     appid="nfc_playlist",
-    name="nfc playlist",
+    name="NFC Playlist",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="nfc_playlist_main",
     requires=["gui", "nfx"],

+ 18 - 12
nfc_playlist.c

@@ -27,26 +27,29 @@ int32_t nfc_playlist_main(void* p) {
    Storage* storage = furi_record_open(RECORD_STORAGE);
    Stream* stream = file_stream_alloc(storage);
    FuriString* line = furi_string_alloc();
-   NfcDevice* nfcDevice = nfc_device_alloc();
-   Nfc* nfc = nfc_alloc();
 
    // Read file
    if(file_stream_open(stream, APP_DATA_PATH("playlistTest.txt"), FSAM_READ, FSOM_OPEN_EXISTING)) {
+
+      // Get resources
+      NfcDevice* nfc_device = nfc_device_alloc();
+      Nfc* nfc = nfc_alloc();
+
       while(stream_read_line(stream, line)) {
          // Store file location
-         const char* fileLocation = strcat("/ext/nfc/",furi_string_get_cstr(line));
+         const char* fileLocation = strcat("/ext/nfc/", furi_string_get_cstr(line));
 
          // Load file
-         if (nfc_device_load(nfcDevice, fileLocation)) {
+         if (nfc_device_load(nfc_device, fileLocation)) {
 
             if (DEBUG) {FURI_LOG_I(TAG, "Loaded file");}
 
             // Get protocol
-            const NfcProtocol protocol = nfc_device_get_protocol(nfcDevice);
+            const NfcProtocol nfc_protocol = nfc_device_get_protocol(nfc_device);
             // Get listern
-            NfcListener* mfu_listener = nfc_listener_alloc(nfc, protocol, nfc_device_get_data(nfcDevice, protocol));
+            NfcListener* listener = nfc_listener_alloc(nfc, nfc_protocol, nfc_device_get_data(nfc_device, nfc_protocol));
             // Start listener
-            nfc_listener_start(mfu_listener, NULL, NULL);
+            nfc_listener_start(listener, NULL, NULL);
 
             // Worst timer ever
             int counter = 0;
@@ -59,8 +62,8 @@ int32_t nfc_playlist_main(void* p) {
             }
 
             // Stop listener && free
-            nfc_listener_stop(mfu_listener);
-            nfc_listener_free(mfu_listener);
+            nfc_listener_stop(listener);
+            nfc_listener_free(listener);
             
          } else {
             if (DEBUG) {FURI_LOG_E(TAG, "Failed to load file");}
@@ -68,8 +71,13 @@ int32_t nfc_playlist_main(void* p) {
          // output file location
          if (DEBUG) {FURI_LOG_I(TAG, "%s", fileLocation);}
          // clear instance
-         nfc_device_clear(nfcDevice);
+         nfc_device_clear(nfc_device);
       }
+
+      // Free/close resources
+      nfc_device_free(nfc_device);
+      nfc_free(nfc);
+
    } else {
       if (DEBUG) {FURI_LOG_E(TAG, "Failed to open file");}
    }
@@ -78,8 +86,6 @@ int32_t nfc_playlist_main(void* p) {
    furi_string_free(line);
    file_stream_close(stream);
    stream_free(stream);
-   nfc_device_free(nfcDevice);
-   nfc_free(nfc);
 
    // Close storage
    furi_record_close(RECORD_STORAGE);