forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Improves how the NFC's are handled in the main app - Makes it so it can now handle multiple NFC's and doesn't end up looping the same one
- Loading branch information
Showing
4 changed files
with
165 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "nfc_playlist_worker.h" | ||
|
||
/// @brief nfc_playlist_worker_alloc() | ||
/// @return | ||
NfcPlaylistWorker* nfc_playlist_worker_alloc() { | ||
NfcPlaylistWorker* nfc_playlist_worker = malloc(sizeof(NfcPlaylistWorker)); | ||
// Worker thread attributes | ||
nfc_playlist_worker->thread = furi_thread_alloc_ex( | ||
"NfcPlaylistWorker", 8192, nfc_playlist_worker_task, nfc_playlist_worker); | ||
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped; | ||
|
||
nfc_playlist_worker->nfc = nfc_alloc(); | ||
nfc_playlist_worker->nfc_device = nfc_device_alloc(); | ||
|
||
return nfc_playlist_worker; | ||
} | ||
|
||
/// @brief nfc_playlist_worker_free() | ||
/// @param nfc_playlist_worker | ||
void nfc_playlist_worker_free(NfcPlaylistWorker* nfc_playlist_worker) { | ||
furi_assert(nfc_playlist_worker); | ||
furi_thread_free(nfc_playlist_worker->thread); | ||
|
||
nfc_free(nfc_playlist_worker->nfc); | ||
nfc_device_free(nfc_playlist_worker->nfc_device); | ||
|
||
free(nfc_playlist_worker); | ||
} | ||
|
||
/// @brief nfc_playlist_worker_stop() | ||
/// @param nfc_playlist_worker | ||
void nfc_playlist_worker_stop(NfcPlaylistWorker* nfc_playlist_worker) { | ||
furi_assert(nfc_playlist_worker); | ||
if(nfc_playlist_worker->state != NfcPlaylistWorkerState_Stopped) { | ||
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped; | ||
furi_thread_join(nfc_playlist_worker->thread); | ||
} | ||
} | ||
|
||
/// @brief nfc_playlist_worker_start() | ||
/// @param nfc_playlist_worker | ||
void nfc_playlist_worker_start(NfcPlaylistWorker* nfc_playlist_worker) { | ||
furi_assert(nfc_playlist_worker); | ||
nfc_playlist_worker->state = NfcPlaylistWorkerState_Emulating; | ||
furi_thread_start(nfc_playlist_worker->thread); | ||
} | ||
|
||
/// @brief nfc_playlist_worker_task() | ||
/// @param context | ||
/// @return | ||
int32_t nfc_playlist_worker_task(void* context) { | ||
NfcPlaylistWorker* nfc_playlist_worker = context; | ||
|
||
if(nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) { | ||
|
||
nfc_playlist_worker->nfc_listener = | ||
nfc_listener_alloc(nfc_playlist_worker->nfc, | ||
nfc_playlist_worker->nfc_protocol, | ||
nfc_device_get_data(nfc_playlist_worker->nfc_device, nfc_playlist_worker->nfc_protocol) | ||
); | ||
nfc_listener_start(nfc_playlist_worker->nfc_listener, NULL, NULL); | ||
|
||
|
||
int counter = 0; | ||
while(true) { | ||
furi_delay_ms(50); | ||
counter++; | ||
if (counter == 100) { | ||
break; | ||
} | ||
} | ||
|
||
// while(nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) { | ||
// furi_delay_ms(50); | ||
// } | ||
|
||
nfc_listener_stop(nfc_playlist_worker->nfc_listener); | ||
nfc_listener_free(nfc_playlist_worker->nfc_listener); | ||
} | ||
|
||
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped; | ||
|
||
return 0; | ||
} | ||
|
||
/// @brief nfc_playlist_worker_is_emulating() | ||
/// @param nfc_playlist_worker | ||
/// @return | ||
bool nfc_playlist_worker_is_emulating(NfcPlaylistWorker* nfc_playlist_worker) { | ||
if(nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/// @brief nfc_playlist_worker_set_nfc_data() | ||
/// @param nfc_playlist_worker | ||
/// @param nfc_data | ||
void nfc_playlist_worker_set_nfc_data(NfcPlaylistWorker* nfc_playlist_worker, char* file_path) { | ||
|
||
FURI_LOG_I("NfcPlaylistWorker", "nfc_playlist_worker_set_nfc_data: %s", file_path); | ||
|
||
nfc_device_clear(nfc_playlist_worker->nfc_device); | ||
nfc_device_load(nfc_playlist_worker->nfc_device, file_path); | ||
|
||
nfc_playlist_worker->nfc_protocol = nfc_device_get_protocol(nfc_playlist_worker->nfc_device); | ||
} | ||
|
||
/// @brief nfc_playlist_worker_get_nfc_data() | ||
/// @param nfc_playlist_worker | ||
/// @return | ||
NfcDeviceData* nfc_playlist_worker_get_nfc_data(NfcPlaylistWorker* nfc_playlist_worker) { | ||
return nfc_playlist_worker->nfc_data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
#include <furi.h> | ||
#include <furi_hal.h> | ||
|
||
#include <nfc/nfc.h> | ||
#include <nfc/nfc_device.h> | ||
#include <nfc/nfc_listener.h> | ||
|
||
typedef enum NfcPlaylistWorkerState { | ||
NfcPlaylistWorkerState_Emulating, | ||
NfcPlaylistWorkerState_Stopped, | ||
} NfcPlaylistWorkerState; | ||
|
||
typedef struct NfcPlaylistWorker { | ||
FuriThread* thread; | ||
NfcPlaylistWorkerState state; | ||
NfcListener* nfc_listener; | ||
NfcDevice* nfc_device; | ||
NfcProtocol nfc_protocol; | ||
NfcDeviceData* nfc_data; | ||
Nfc* nfc; | ||
} NfcPlaylistWorker; | ||
|
||
/// Worker | ||
NfcPlaylistWorker* nfc_playlist_worker_alloc(); | ||
void nfc_playlist_worker_free(NfcPlaylistWorker* nfc_playlist_worker); | ||
void nfc_playlist_worker_stop(NfcPlaylistWorker* nfc_playlist_worker); | ||
void nfc_playlist_worker_start(NfcPlaylistWorker* nfc_playlist_worker); | ||
// task | ||
int32_t nfc_playlist_worker_task(void* context); | ||
// | ||
bool nfc_playlist_worker_is_emulating(NfcPlaylistWorker* nfc_playlist_worker); | ||
void nfc_playlist_worker_set_nfc_data(NfcPlaylistWorker* nfc_playlist_worker, char* file_path); | ||
NfcDeviceData* nfc_playlist_worker_get_nfc_data(NfcPlaylistWorker* nfc_playlist_worker); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/ext/nfc/RickRoll.nfc | ||
/ext/nfc/Website.nfc | ||
/ext/nfc/Phone_number.nfc |