nfc_playlist.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <furi.h>
  2. #include <nfc/nfc.h>
  3. #include <nfc/nfc_common.h>
  4. #include <nfc/nfc_device.h>
  5. #include <nfc/nfc_device_i.h>
  6. #include <nfc/nfc_listener.h>
  7. #include <storage/storage.h>
  8. #include <toolbox/stream/stream.h>
  9. #include <toolbox/stream/file_stream.h>
  10. #include <nfc_playlist_worker.h>
  11. // Define log tag
  12. #define TAG "NfcPlaylist"
  13. // Application entry point
  14. int32_t nfc_playlist_main(void* p) {
  15. // Mark argument as unused
  16. UNUSED(p);
  17. // Just a little debug toggle
  18. const bool DEBUG = true;
  19. // open/alloc resources
  20. Storage* storage = furi_record_open(RECORD_STORAGE);
  21. Stream* stream = file_stream_alloc(storage);
  22. FuriString* line = furi_string_alloc();
  23. NfcPlaylistWorker* nfc_playlist_worker = nfc_playlist_worker_alloc();
  24. // Read file
  25. if(file_stream_open(stream, APP_DATA_PATH("playlist.txt"), FSAM_READ, FSOM_OPEN_EXISTING)) {
  26. // read the file line by line and print the text
  27. while(stream_read_line(stream, line)) {
  28. if (DEBUG) {FURI_LOG_I(TAG, "Read line: %s", furi_string_get_cstr(line));}
  29. nfc_playlist_worker_set_nfc_data(nfc_playlist_worker, (char*)furi_string_get_cstr(line));
  30. nfc_playlist_worker_start(nfc_playlist_worker);
  31. furi_delay_ms(1500);
  32. nfc_playlist_worker_stop(nfc_playlist_worker);
  33. furi_string_reset(line);
  34. }
  35. } else {
  36. if (DEBUG) {FURI_LOG_E(TAG, "Failed to open file");}
  37. }
  38. // Free/close resources
  39. furi_string_free(line);
  40. file_stream_close(stream);
  41. stream_free(stream);
  42. nfc_playlist_worker_free(nfc_playlist_worker);
  43. // Close storage
  44. furi_record_close(RECORD_STORAGE);
  45. return 0;
  46. }