3
3
4
4
NfcPlaylistEmulationState EmulationState = NfcPlaylistEmulationState_Stopped ;
5
5
6
- void nfc_playlist_emulation_scene_on_enter (void * context ) {
7
- NfcPlaylist * nfc_playlist = context ;
8
- nfc_playlist_emulation_setup (nfc_playlist );
9
- nfc_playlist_emulation_start (nfc_playlist );
10
- }
11
-
12
- bool nfc_playlist_emulation_scene_on_event (void * context , SceneManagerEvent event ) {
13
- UNUSED (context );
14
- if (event .event == 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
15
- EmulationState = NfcPlaylistEmulationState_Canceled ;
16
- return true;
17
- }
18
- return false;
19
- }
20
-
21
- void nfc_playlist_emulation_scene_on_exit (void * context ) {
22
- NfcPlaylist * nfc_playlist = context ;
23
- EmulationState = NfcPlaylistEmulationState_Stopped ;
24
- nfc_playlist_emulation_stop (nfc_playlist );
25
- nfc_playlist_emulation_free (nfc_playlist );
26
- popup_reset (nfc_playlist -> popup );
27
- }
28
-
29
- void nfc_playlist_emulation_setup (void * context ) {
30
- NfcPlaylist * nfc_playlist = context ;
31
- nfc_playlist -> thread = furi_thread_alloc_ex ("NfcPlaylistEmulationWorker" , 8192 , nfc_playlist_emulation_task , nfc_playlist );
32
- nfc_playlist -> nfc_playlist_worker = nfc_playlist_worker_alloc ();
33
- }
34
-
35
- void nfc_playlist_emulation_free (NfcPlaylist * nfc_playlist ) {
36
- furi_assert (nfc_playlist );
37
- furi_thread_free (nfc_playlist -> thread );
38
- nfc_playlist_worker_free (nfc_playlist -> nfc_playlist_worker );
39
- nfc_playlist -> thread = NULL ;
40
- nfc_playlist -> nfc_playlist_worker = NULL ;
41
- }
42
-
43
- void nfc_playlist_emulation_start (NfcPlaylist * nfc_playlist ) {
44
- furi_assert (nfc_playlist );
45
- furi_thread_start (nfc_playlist -> thread );
46
- }
47
-
48
- void nfc_playlist_emulation_stop (NfcPlaylist * nfc_playlist ) {
49
- furi_assert (nfc_playlist );
50
- furi_thread_join (nfc_playlist -> thread );
51
- }
52
-
53
6
int32_t nfc_playlist_emulation_task (void * context ) {
54
7
NfcPlaylist * nfc_playlist = context ;
55
8
56
9
Storage * storage = furi_record_open (RECORD_STORAGE );
57
10
Stream * stream = file_stream_alloc (storage );
58
11
FuriString * line = furi_string_alloc ();
59
- FuriString * temp_header_str = furi_string_alloc ();
60
- FuriString * temp_counter_str = furi_string_alloc ();
12
+ FuriString * tmp_header_str = furi_string_alloc ();
13
+ FuriString * tmp_counter_str = furi_string_alloc ();
61
14
62
15
popup_reset (nfc_playlist -> popup );
63
16
popup_set_context (nfc_playlist -> popup , nfc_playlist );
@@ -70,57 +23,57 @@ int32_t nfc_playlist_emulation_task(void* context) {
70
23
71
24
char * file_path = (char * )furi_string_get_cstr (line );
72
25
73
- if (strlen (file_path ) <= 1 ) {continue ;}
26
+ if (strlen (file_path ) <= 1 ) {continue ;}
74
27
75
- if (nfc_playlist -> settings .emulate_delay > 0 && file_position != 0 ) {
28
+ if (nfc_playlist -> settings .emulate_delay > 0 && file_position != 0 ) {
76
29
popup_set_header (nfc_playlist -> popup , "Delaying" , 64 , 10 , AlignCenter , AlignTop );
77
30
start_blink (nfc_playlist , NfcPlaylistLedState_Error );
78
31
int time_counter_delay_ms = (options_emulate_delay [nfc_playlist -> settings .emulate_delay ]* 1000 );
79
32
do {
80
- furi_string_printf (temp_counter_str , "%ds" , (time_counter_delay_ms /1000 ));
81
- popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (temp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
33
+ furi_string_printf (tmp_counter_str , "%ds" , (time_counter_delay_ms /1000 ));
34
+ popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (tmp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
82
35
furi_delay_ms (50 );
83
36
time_counter_delay_ms -= 50 ;
84
37
} while (time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
85
38
} else if (nfc_playlist -> settings .emulate_delay > 0 ) {
86
39
file_position ++ ;
87
40
}
88
41
89
- if (EmulationState != NfcPlaylistEmulationState_Emulating ) {break ;}
42
+ if (EmulationState != NfcPlaylistEmulationState_Emulating ) {break ;}
90
43
91
44
char * file_name = strchr (file_path , '/' ) != NULL ? & strrchr (file_path , '/' )[1 ] : file_path ;
92
45
char const * file_ext = & strrchr (file_path , '.' )[1 ];
93
46
int time_counter_ms = (options_emulate_timeout [nfc_playlist -> settings .emulate_timeout ]* 1000 );
94
47
95
- if (storage_file_exists (storage , file_path ) == false) {
96
- furi_string_printf (temp_header_str , "ERROR not found:\n %s" , file_name );
97
- popup_set_header (nfc_playlist -> popup , furi_string_get_cstr (temp_header_str ), 64 , 10 , AlignCenter , AlignTop );
48
+ if (storage_file_exists (storage , file_path ) == false) {
49
+ furi_string_printf (tmp_header_str , "ERROR not found:\n%s" , file_name );
50
+ popup_set_header (nfc_playlist -> popup , furi_string_get_cstr (tmp_header_str ), 64 , 10 , AlignCenter , AlignTop );
98
51
start_blink (nfc_playlist , NfcPlaylistLedState_Error );
99
52
do {
100
- furi_string_printf (temp_counter_str , "%ds" , (time_counter_ms /1000 ));
101
- popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (temp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
53
+ furi_string_printf (tmp_counter_str , "%ds" , (time_counter_ms /1000 ));
54
+ popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (tmp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
102
55
furi_delay_ms (50 );
103
56
time_counter_ms -= 50 ;
104
57
} while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
105
58
} else if (strcasestr (file_ext , "nfc" ) == NULL ) {
106
- furi_string_printf (temp_header_str , "ERROR invalid file:\n %s" , file_name );
107
- popup_set_header (nfc_playlist -> popup , furi_string_get_cstr (temp_header_str ), 64 , 10 , AlignCenter , AlignTop );
59
+ furi_string_printf (tmp_header_str , "ERROR invalid file:\n%s" , file_name );
60
+ popup_set_header (nfc_playlist -> popup , furi_string_get_cstr (tmp_header_str ), 64 , 10 , AlignCenter , AlignTop );
108
61
start_blink (nfc_playlist , NfcPlaylistLedState_Error );
109
62
do {
110
- furi_string_printf (temp_counter_str , "%ds" , (time_counter_ms /1000 ));
111
- popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (temp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
63
+ furi_string_printf (tmp_counter_str , "%ds" , (time_counter_ms /1000 ));
64
+ popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (tmp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
112
65
furi_delay_ms (50 );
113
66
time_counter_ms -= 50 ;
114
67
} while (time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
115
68
} else {
116
- furi_string_printf (temp_header_str , "Emulating:\n %s" , file_name );
117
- popup_set_header (nfc_playlist -> popup , furi_string_get_cstr (temp_header_str ), 64 , 10 , AlignCenter , AlignTop );
69
+ furi_string_printf (tmp_header_str , "Emulating:\n%s" , file_name );
70
+ popup_set_header (nfc_playlist -> popup , furi_string_get_cstr (tmp_header_str ), 64 , 10 , AlignCenter , AlignTop );
118
71
nfc_playlist_worker_set_nfc_data (nfc_playlist -> nfc_playlist_worker , file_path );
119
72
nfc_playlist_worker_start (nfc_playlist -> nfc_playlist_worker );
120
73
start_blink (nfc_playlist , NfcPlaylistLedState_Normal );
121
74
do {
122
- furi_string_printf (temp_counter_str , "%ds" , (time_counter_ms /1000 ));
123
- popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (temp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
75
+ furi_string_printf (tmp_counter_str , "%ds" , (time_counter_ms /1000 ));
76
+ popup_set_text (nfc_playlist -> popup , furi_string_get_cstr (tmp_counter_str ), 64 , 50 , AlignCenter , AlignTop );
124
77
furi_delay_ms (50 );
125
78
time_counter_ms -= 50 ;
126
79
} while (nfc_playlist_worker_is_emulating (nfc_playlist -> nfc_playlist_worker ) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating );
@@ -140,11 +93,59 @@ int32_t nfc_playlist_emulation_task(void* context) {
140
93
}
141
94
142
95
furi_string_free (line );
143
- furi_string_free (temp_header_str );
144
- furi_string_free (temp_counter_str );
96
+ furi_string_free (tmp_header_str );
97
+ furi_string_free (tmp_counter_str );
145
98
file_stream_close (stream );
146
99
furi_record_close (RECORD_STORAGE );
147
100
stream_free (stream );
148
101
149
102
return 0 ;
103
+ }
104
+
105
+ void nfc_playlist_emulation_setup (void * context ) {
106
+ NfcPlaylist * nfc_playlist = context ;
107
+ nfc_playlist -> thread = furi_thread_alloc_ex ("NfcPlaylistEmulationWorker" , 8192 , nfc_playlist_emulation_task , nfc_playlist );
108
+ nfc_playlist -> nfc_playlist_worker = nfc_playlist_worker_alloc ();
109
+ }
110
+
111
+ void nfc_playlist_emulation_free (NfcPlaylist * nfc_playlist ) {
112
+ furi_assert (nfc_playlist );
113
+ furi_thread_free (nfc_playlist -> thread );
114
+ nfc_playlist_worker_free (nfc_playlist -> nfc_playlist_worker );
115
+ nfc_playlist -> thread = NULL ;
116
+ nfc_playlist -> nfc_playlist_worker = NULL ;
117
+ }
118
+
119
+ void nfc_playlist_emulation_start (NfcPlaylist * nfc_playlist ) {
120
+ furi_assert (nfc_playlist );
121
+ furi_thread_start (nfc_playlist -> thread );
122
+ }
123
+
124
+ void nfc_playlist_emulation_stop (NfcPlaylist * nfc_playlist ) {
125
+ furi_assert (nfc_playlist );
126
+ furi_thread_join (nfc_playlist -> thread );
127
+ }
128
+
129
+ void nfc_playlist_emulation_scene_on_enter (void * context ) {
130
+ NfcPlaylist * nfc_playlist = context ;
131
+ nfc_playlist_emulation_setup (nfc_playlist );
132
+ nfc_playlist_emulation_start (nfc_playlist );
133
+ }
134
+
135
+ bool nfc_playlist_emulation_scene_on_event (void * context , SceneManagerEvent event ) {
136
+ UNUSED (context );
137
+ bool consumed = false;
138
+ if (event .event == 0 && EmulationState == NfcPlaylistEmulationState_Emulating ) {
139
+ EmulationState = NfcPlaylistEmulationState_Canceled ;
140
+ consumed = true;
141
+ }
142
+ return consumed ;
143
+ }
144
+
145
+ void nfc_playlist_emulation_scene_on_exit (void * context ) {
146
+ NfcPlaylist * nfc_playlist = context ;
147
+ EmulationState = NfcPlaylistEmulationState_Stopped ;
148
+ nfc_playlist_emulation_stop (nfc_playlist );
149
+ nfc_playlist_emulation_free (nfc_playlist );
150
+ popup_reset (nfc_playlist -> popup );
150
151
}
0 commit comments