|
@@ -5,15 +5,13 @@
|
|
|
#include <nfc/nfc_device.h>
|
|
#include <nfc/nfc_device.h>
|
|
|
#include <nfc/nfc_device_i.h>
|
|
#include <nfc/nfc_device_i.h>
|
|
|
#include <nfc/nfc_listener.h>
|
|
#include <nfc/nfc_listener.h>
|
|
|
-#include <nfc/nfc_poller.h>
|
|
|
|
|
-#include <nfc/nfc_scanner.h>
|
|
|
|
|
-
|
|
|
|
|
-#include <nfc/protocols/iso14443_3a/iso14443_3a.h>
|
|
|
|
|
|
|
|
|
|
#include <storage/storage.h>
|
|
#include <storage/storage.h>
|
|
|
#include <toolbox/stream/stream.h>
|
|
#include <toolbox/stream/stream.h>
|
|
|
#include <toolbox/stream/file_stream.h>
|
|
#include <toolbox/stream/file_stream.h>
|
|
|
|
|
|
|
|
|
|
+#include <nfc_playlist_worker.h>
|
|
|
|
|
+
|
|
|
// Define log tag
|
|
// Define log tag
|
|
|
#define TAG "NfcPlaylist"
|
|
#define TAG "NfcPlaylist"
|
|
|
|
|
|
|
@@ -22,70 +20,32 @@ int32_t nfc_playlist_main(void* p) {
|
|
|
// Mark argument as unused
|
|
// Mark argument as unused
|
|
|
UNUSED(p);
|
|
UNUSED(p);
|
|
|
// Just a little debug toggle
|
|
// Just a little debug toggle
|
|
|
- const bool DEBUG = false;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const bool DEBUG = true;
|
|
|
|
|
+ // open/alloc resources
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
Stream* stream = file_stream_alloc(storage);
|
|
Stream* stream = file_stream_alloc(storage);
|
|
|
FuriString* line = furi_string_alloc();
|
|
FuriString* line = furi_string_alloc();
|
|
|
-
|
|
|
|
|
|
|
+ NfcPlaylistWorker* nfc_playlist_worker = nfc_playlist_worker_alloc();
|
|
|
// Read file
|
|
// 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();
|
|
|
|
|
|
|
+ if(file_stream_open(stream, APP_DATA_PATH("playlist.txt"), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
|
|
|
|
|
|
|
+ // read the file line by line and print the text
|
|
|
while(stream_read_line(stream, line)) {
|
|
while(stream_read_line(stream, line)) {
|
|
|
- // Store file location
|
|
|
|
|
- const char* fileLocation = strcat("/ext/nfc/", furi_string_get_cstr(line));
|
|
|
|
|
-
|
|
|
|
|
- // Load file
|
|
|
|
|
- if (nfc_device_load(nfc_device, fileLocation)) {
|
|
|
|
|
-
|
|
|
|
|
- if (DEBUG) {FURI_LOG_I(TAG, "Loaded file");}
|
|
|
|
|
-
|
|
|
|
|
- // Get protocol
|
|
|
|
|
- const NfcProtocol nfc_protocol = nfc_device_get_protocol(nfc_device);
|
|
|
|
|
- // Get listern
|
|
|
|
|
- NfcListener* listener = nfc_listener_alloc(nfc, nfc_protocol, nfc_device_get_data(nfc_device, nfc_protocol));
|
|
|
|
|
- // Start listener
|
|
|
|
|
- nfc_listener_start(listener, NULL, NULL);
|
|
|
|
|
-
|
|
|
|
|
- // Worst timer ever
|
|
|
|
|
- int counter = 0;
|
|
|
|
|
- while(true) {
|
|
|
|
|
- furi_delay_ms(50);
|
|
|
|
|
- counter++;
|
|
|
|
|
- if (counter == 100) {
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Stop listener && free
|
|
|
|
|
- nfc_listener_stop(listener);
|
|
|
|
|
- nfc_listener_free(listener);
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- if (DEBUG) {FURI_LOG_E(TAG, "Failed to load file");}
|
|
|
|
|
- }
|
|
|
|
|
- // output file location
|
|
|
|
|
- if (DEBUG) {FURI_LOG_I(TAG, "%s", fileLocation);}
|
|
|
|
|
- // clear instance
|
|
|
|
|
- nfc_device_clear(nfc_device);
|
|
|
|
|
|
|
+ if (DEBUG) {FURI_LOG_I(TAG, "Read line: %s", furi_string_get_cstr(line));}
|
|
|
|
|
+ nfc_playlist_worker_set_nfc_data(nfc_playlist_worker, (char*)furi_string_get_cstr(line));
|
|
|
|
|
+ nfc_playlist_worker_start(nfc_playlist_worker);
|
|
|
|
|
+ furi_delay_ms(1500);
|
|
|
|
|
+ nfc_playlist_worker_stop(nfc_playlist_worker);
|
|
|
|
|
+ furi_string_reset(line);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Free/close resources
|
|
|
|
|
- nfc_device_free(nfc_device);
|
|
|
|
|
- nfc_free(nfc);
|
|
|
|
|
-
|
|
|
|
|
} else {
|
|
} else {
|
|
|
if (DEBUG) {FURI_LOG_E(TAG, "Failed to open file");}
|
|
if (DEBUG) {FURI_LOG_E(TAG, "Failed to open file");}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// Free/close resources
|
|
// Free/close resources
|
|
|
furi_string_free(line);
|
|
furi_string_free(line);
|
|
|
file_stream_close(stream);
|
|
file_stream_close(stream);
|
|
|
stream_free(stream);
|
|
stream_free(stream);
|
|
|
|
|
+ nfc_playlist_worker_free(nfc_playlist_worker);
|
|
|
|
|
|
|
|
// Close storage
|
|
// Close storage
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
furi_record_close(RECORD_STORAGE);
|