11#include "nfc_playlist_worker.h"
22
33NfcPlaylistWorker * nfc_playlist_worker_alloc () {
4- NfcPlaylistWorker * nfc_playlist_worker = malloc (sizeof (NfcPlaylistWorker ));
5- // Worker thread attributes
6- nfc_playlist_worker -> thread = furi_thread_alloc_ex (
7- "NfcPlaylistWorker" , 8192 , nfc_playlist_worker_task , nfc_playlist_worker );
8- nfc_playlist_worker -> state = NfcPlaylistWorkerState_Stopped ;
4+ NfcPlaylistWorker * nfc_playlist_worker = malloc (sizeof (NfcPlaylistWorker ));
95
10- nfc_playlist_worker -> nfc = nfc_alloc ( );
11- nfc_playlist_worker -> nfc_device = nfc_device_alloc () ;
6+ nfc_playlist_worker -> thread = furi_thread_alloc_ex ( "NfcPlaylistWorker" , 8192 , nfc_playlist_worker_task , nfc_playlist_worker );
7+ nfc_playlist_worker -> state = NfcPlaylistWorkerState_Stopped ;
128
13- return nfc_playlist_worker ;
9+ nfc_playlist_worker -> nfc = nfc_alloc ();
10+ nfc_playlist_worker -> nfc_device = nfc_device_alloc ();
11+
12+ return nfc_playlist_worker ;
1413}
1514
1615void nfc_playlist_worker_free (NfcPlaylistWorker * nfc_playlist_worker ) {
17- furi_assert (nfc_playlist_worker );
18- furi_thread_free (nfc_playlist_worker -> thread );
16+ furi_assert (nfc_playlist_worker );
17+ furi_thread_free (nfc_playlist_worker -> thread );
1918
20- nfc_free (nfc_playlist_worker -> nfc );
21- nfc_device_free (nfc_playlist_worker -> nfc_device );
19+ nfc_free (nfc_playlist_worker -> nfc );
20+ nfc_device_free (nfc_playlist_worker -> nfc_device );
2221
23- free (nfc_playlist_worker );
22+ free (nfc_playlist_worker );
2423}
2524
2625void nfc_playlist_worker_stop (NfcPlaylistWorker * nfc_playlist_worker ) {
27- furi_assert (nfc_playlist_worker );
28- if (nfc_playlist_worker -> state != NfcPlaylistWorkerState_Stopped ) {
29- nfc_playlist_worker -> state = NfcPlaylistWorkerState_Stopped ;
30- furi_thread_join (nfc_playlist_worker -> thread );
31- }
26+ furi_assert (nfc_playlist_worker );
27+ if (nfc_playlist_worker -> state != NfcPlaylistWorkerState_Stopped ) {
28+ nfc_playlist_worker -> state = NfcPlaylistWorkerState_Stopped ;
29+ furi_thread_join (nfc_playlist_worker -> thread );
30+ }
3231}
3332
3433void nfc_playlist_worker_start (NfcPlaylistWorker * nfc_playlist_worker ) {
35- furi_assert (nfc_playlist_worker );
36- nfc_playlist_worker -> state = NfcPlaylistWorkerState_Emulating ;
37- furi_thread_start (nfc_playlist_worker -> thread );
34+ furi_assert (nfc_playlist_worker );
35+ nfc_playlist_worker -> state = NfcPlaylistWorkerState_Emulating ;
36+ furi_thread_start (nfc_playlist_worker -> thread );
3837}
3938
4039int32_t nfc_playlist_worker_task (void * context ) {
41- NfcPlaylistWorker * nfc_playlist_worker = context ;
40+ NfcPlaylistWorker * nfc_playlist_worker = context ;
4241
43- if (nfc_playlist_worker -> state == NfcPlaylistWorkerState_Emulating ) {
42+ if (nfc_playlist_worker -> state == NfcPlaylistWorkerState_Emulating ) {
4443
45- nfc_playlist_worker -> nfc_listener =
46- nfc_listener_alloc (nfc_playlist_worker -> nfc ,
47- nfc_playlist_worker -> nfc_protocol ,
48- nfc_device_get_data (nfc_playlist_worker -> nfc_device , nfc_playlist_worker -> nfc_protocol )
49- );
50- nfc_listener_start (nfc_playlist_worker -> nfc_listener , NULL , NULL );
44+ nfc_playlist_worker -> nfc_listener =
45+ nfc_listener_alloc (nfc_playlist_worker -> nfc ,
46+ nfc_playlist_worker -> nfc_protocol ,
47+ nfc_device_get_data (nfc_playlist_worker -> nfc_device , nfc_playlist_worker -> nfc_protocol )
48+ );
49+ nfc_listener_start (nfc_playlist_worker -> nfc_listener , NULL , NULL );
5150
52- while (nfc_playlist_worker -> state == NfcPlaylistWorkerState_Emulating ) {
53- furi_delay_ms (50 );
54- }
51+ while (nfc_playlist_worker -> state == NfcPlaylistWorkerState_Emulating ) {
52+ furi_delay_ms (50 );
53+ }
5554
56- nfc_listener_stop (nfc_playlist_worker -> nfc_listener );
57- nfc_listener_free (nfc_playlist_worker -> nfc_listener );
58- }
55+ nfc_listener_stop (nfc_playlist_worker -> nfc_listener );
56+ nfc_listener_free (nfc_playlist_worker -> nfc_listener );
57+ }
5958
60- nfc_playlist_worker -> state = NfcPlaylistWorkerState_Stopped ;
59+ nfc_playlist_worker -> state = NfcPlaylistWorkerState_Stopped ;
6160
62- return 0 ;
61+ return 0 ;
6362}
6463
6564bool nfc_playlist_worker_is_emulating (NfcPlaylistWorker * nfc_playlist_worker ) {
66- if (nfc_playlist_worker -> state == NfcPlaylistWorkerState_Emulating ) {
67- return true;
68- }
69- return false;
65+ if (nfc_playlist_worker -> state == NfcPlaylistWorkerState_Emulating ) {
66+ return true;
67+ }
68+ return false;
7069}
7170
7271void nfc_playlist_worker_set_nfc_data (NfcPlaylistWorker * nfc_playlist_worker , char * file_path ) {
73- nfc_device_clear (nfc_playlist_worker -> nfc_device );
74- nfc_device_load (nfc_playlist_worker -> nfc_device , file_path );
75- nfc_playlist_worker -> nfc_protocol = nfc_device_get_protocol (nfc_playlist_worker -> nfc_device );
72+ nfc_device_clear (nfc_playlist_worker -> nfc_device );
73+ nfc_device_load (nfc_playlist_worker -> nfc_device , file_path );
74+ nfc_playlist_worker -> nfc_protocol = nfc_device_get_protocol (nfc_playlist_worker -> nfc_device );
7675}
7776
7877NfcDeviceData * nfc_playlist_worker_get_nfc_data (NfcPlaylistWorker * nfc_playlist_worker ) {
79- return nfc_playlist_worker -> nfc_data ;
78+ return nfc_playlist_worker -> nfc_data ;
8079}
0 commit comments