Skip to content

Commit 530fc9f

Browse files
authored
Merge pull request #22 from acegoal07/dev
Dev
2 parents 42381d1 + bdec676 commit 530fc9f

12 files changed

+97
-61
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All the playlists should be placed in ext/apps_data/nfc_playlist and an example
1010
```
1111
An example file can be found in the repository
1212
## How to build
13-
This app was design, built and tested using the <a href="https://github.com/Flipper-XFW/Xtreme-Firmware">Xtreme firmware</a> so keep that in mind when building the FAP for yourself
13+
This app was design, built and tested using the <a href="https://github.com/Next-Flip/Momentum-Firmware">Momentum</a> so keep that in mind when building the FAP for yourself
1414
## Supported Firmwares
1515
As i know these firmwares are supported and working if you know any more please let me know
1616
- <a href="https://github.com/Flipper-XFW/Xtreme-Firmware">Xtreme</a>
@@ -20,6 +20,7 @@ As i know these firmwares are supported and working if you know any more please
2020
- Emulate time (How long the NFC card will be emulated for)
2121
- Delay time (How long the gap between the cards will be)
2222
- LED indicator (Whether or not the LED's will be on)
23+
- Skip errors (Makes it so you can make the emulation screen hide errors and skip delays between errors and emulation)
2324
- Reset settings (Puts all the settings back to the defaults)
2425
## Playlist editor:
2526
- Create PLaylist (Creates a new playlist with the given name)

application.fam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ App(
88
fap_category="NFC",
99
fap_author="@acegoal07",
1010
fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main",
11-
fap_version="1.7",
11+
fap_version="1.8",
1212
fap_icon="assets/icon.png",
1313
fap_private_libs=[
1414
Lib(

nfc_playlist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
2828
nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
2929
nfc_playlist->settings.emulate_delay = default_emulate_delay;
3030
nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
31+
nfc_playlist->settings.skip_error = default_skip_error;
3132

3233
nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);
3334
nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->file_browser_output);

nfc_playlist.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ typedef enum {
3535
NfcPlaylistView_VariableItemList,
3636
NfcPlaylistView_FileBrowser,
3737
NfcPlaylistView_TextInput
38-
} NfcPlaylistView;
38+
} NfcPlaylistViews;
3939

4040
typedef struct {
4141
FuriString* file_path;
4242
bool playlist_selected;
4343
uint8_t emulate_timeout;
4444
uint8_t emulate_delay;
4545
bool emulate_led_indicator;
46+
bool skip_error;
4647
} NfcPlaylistSettings;
4748

4849
typedef struct {
@@ -58,6 +59,7 @@ typedef struct {
5859
char* text_input_output;
5960
NotificationApp* notification;
6061
FuriThread* thread;
62+
FuriString* temp_furi_string;
6163
NfcPlaylistWorker* nfc_playlist_worker;
6264
NfcPlaylistSettings settings;
6365
} NfcPlaylist;
@@ -67,9 +69,11 @@ static const int default_emulate_timeout = 4;
6769
static const int options_emulate_delay[] = {0, 1, 2, 3, 4, 5, 6};
6870
static const int default_emulate_delay = 0;
6971
static const bool default_emulate_led_indicator = true;
72+
static const bool default_skip_error = false;
7073

7174
#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
7275
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"
76+
#define PLAYLIST_VIEW_MAX_SIZE 1000
7377

7478
typedef enum NfcPlaylistLedState {
7579
NfcPlaylistLedState_Normal,

scenes/nfc_playlist_scene_emulation.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ int32_t nfc_playlist_emulation_task(void* context) {
1313

1414
Storage* storage = furi_record_open(RECORD_STORAGE);
1515
Stream* stream = file_stream_alloc(storage);
16+
bool skip_delay = false;
1617

1718
popup_reset(nfc_playlist->popup);
1819
popup_set_context(nfc_playlist->popup, nfc_playlist);
19-
20+
2021
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);
2122

2223
if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
@@ -31,19 +32,20 @@ int32_t nfc_playlist_emulation_task(void* context) {
3132

3233
char* file_path = (char*)furi_string_get_cstr(line);
3334

34-
if(strlen(file_path) <= 1) {continue;}
35+
if (strlen(file_path) <= 1) {continue;}
3536

36-
if(nfc_playlist->settings.emulate_delay > 0 && file_position != 0) {
37+
if (nfc_playlist->settings.emulate_delay > 0 && file_position != 0 && !skip_delay) {
3738
popup_set_header(nfc_playlist->popup, "Delaying", 64, 10, AlignCenter, AlignTop);
3839
start_blink(nfc_playlist, NfcPlaylistLedState_Error);
3940
int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000);
40-
do {
41+
while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
4142
furi_string_printf(tmp_counter_str, "%ds", (time_counter_delay_ms/1000));
4243
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
4344
furi_delay_ms(50);
4445
time_counter_delay_ms -= 50;
45-
} while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
46+
};
4647
} else if (nfc_playlist->settings.emulate_delay > 0) {
48+
skip_delay = false;
4749
file_position++;
4850
}
4951

@@ -53,38 +55,46 @@ int32_t nfc_playlist_emulation_task(void* context) {
5355
char const* file_ext = &strrchr(file_path, '.')[1];
5456
int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000);
5557

56-
if(storage_file_exists(storage, file_path) == false) {
57-
furi_string_printf(tmp_header_str, "ERROR not found:\n%s", file_name);
58+
if(!strcasestr(file_ext, "nfc")) {
59+
if(nfc_playlist->settings.skip_error) {
60+
skip_delay = true;
61+
continue;
62+
}
63+
furi_string_printf(tmp_header_str, "ERROR invalid file:\n%s", file_name);
5864
popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop);
5965
start_blink(nfc_playlist, NfcPlaylistLedState_Error);
60-
do {
66+
while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
6167
furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000));
6268
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
6369
furi_delay_ms(50);
6470
time_counter_ms -= 50;
65-
} while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
66-
} else if (strcasestr(file_ext, "nfc") == NULL) {
67-
furi_string_printf(tmp_header_str, "ERROR invalid file:\n%s", file_name);
71+
};
72+
} else if(!storage_file_exists(storage, file_path)) {
73+
if(nfc_playlist->settings.skip_error) {
74+
skip_delay = true;
75+
continue;
76+
}
77+
furi_string_printf(tmp_header_str, "ERROR not found:\n%s", file_name);
6878
popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop);
6979
start_blink(nfc_playlist, NfcPlaylistLedState_Error);
70-
do {
80+
while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
7181
furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000));
7282
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
7383
furi_delay_ms(50);
7484
time_counter_ms -= 50;
75-
} while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
85+
};
7686
} else {
7787
furi_string_printf(tmp_header_str, "Emulating:\n%s", file_name);
7888
popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop);
7989
nfc_playlist_worker_set_nfc_data(nfc_playlist->nfc_playlist_worker, file_path);
8090
nfc_playlist_worker_start(nfc_playlist->nfc_playlist_worker);
8191
start_blink(nfc_playlist, NfcPlaylistLedState_Normal);
82-
do {
92+
while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
8393
furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000));
8494
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
8595
furi_delay_ms(50);
8696
time_counter_ms -= 50;
87-
} while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
97+
};
8898
nfc_playlist_worker_stop(nfc_playlist->nfc_playlist_worker);
8999
nfc_playlist_worker_clear_nfc_data(nfc_playlist->nfc_playlist_worker);
90100
}
@@ -98,7 +108,6 @@ int32_t nfc_playlist_emulation_task(void* context) {
98108
furi_string_free(line);
99109
furi_string_free(tmp_header_str);
100110
furi_string_free(tmp_counter_str);
101-
102111
} else {
103112
popup_set_header(nfc_playlist->popup, "Failed to open playlist", 64, 10, AlignCenter, AlignTop);
104113
popup_set_text(nfc_playlist->popup, "Press back", 64, 50, AlignCenter, AlignTop);

scenes/nfc_playlist_scene_file_rename.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
void nfc_playlist_file_rename_menu_callback(void* context) {
44
NfcPlaylist* nfc_playlist = context;
55
Storage* storage = furi_record_open(RECORD_STORAGE);
6-
FuriString* tmp_old_file_path = furi_string_alloc();
7-
FuriString* tmp_new_file_path = furi_string_alloc();
86

97
char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path);
108
char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path;
119

12-
furi_string_printf(tmp_old_file_path, "%s", old_file_path);
10+
FuriString* tmp_old_file_path = furi_string_alloc_set_str(old_file_path);
1311
furi_string_replace(tmp_old_file_path, old_file_name, "");
1412

13+
FuriString* tmp_new_file_path = furi_string_alloc();
1514
furi_string_printf(tmp_new_file_path, "%s%s.txt", furi_string_get_cstr(tmp_old_file_path), nfc_playlist->text_input_output);
1615

1716
if(!storage_file_exists(storage, furi_string_get_cstr(tmp_new_file_path))) {
@@ -27,11 +26,18 @@ void nfc_playlist_file_rename_menu_callback(void* context) {
2726

2827
void nfc_playlist_file_rename_scene_on_enter(void* context) {
2928
NfcPlaylist* nfc_playlist = context;
30-
nfc_playlist->text_input_output = (char*)malloc(50);
29+
30+
char const* tmp_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path);
31+
char const* tmp_file_name = strchr(tmp_file_path, '/') != NULL ? &strrchr(tmp_file_path, '/')[1] : tmp_file_path;
32+
33+
FuriString* tmp_file_name_furi = furi_string_alloc_set_str(tmp_file_name);
34+
furi_string_replace(tmp_file_name_furi, ".txt", "");
35+
36+
nfc_playlist->text_input_output = (char*)furi_string_get_cstr(tmp_file_name_furi);
3137
text_input_set_header_text(nfc_playlist->text_input, "Enter new file name");
3238
text_input_set_minimum_length(nfc_playlist->text_input, 1);
33-
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
34-
39+
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, false);
40+
3541
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
3642
}
3743

scenes/nfc_playlist_scene_main_menu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
6161
NfcPlaylistMenuSelection_Settings,
6262
nfc_playlist_main_menu_menu_callback,
6363
nfc_playlist);
64-
64+
6565
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Submenu);
6666
}
6767

scenes/nfc_playlist_scene_name_new_file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void nfc_playlist_name_new_file_menu_callback(void* context) {
1212
storage_file_close(file);
1313
furi_string_swap(nfc_playlist->settings.file_path, file_name);
1414
}
15-
15+
1616
storage_file_free(file);
1717
furi_string_free(file_name);
1818
furi_record_close(RECORD_STORAGE);
@@ -25,7 +25,7 @@ void nfc_playlist_name_new_file_scene_on_enter(void* context) {
2525
text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
2626
text_input_set_minimum_length(nfc_playlist->text_input, 1);
2727
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_file_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
28-
28+
2929
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
3030
}
3131

scenes/nfc_playlist_scene_nfc_select.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#include "../nfc_playlist.h"
22

3-
#define MAX_PLAYLIST_SIZE 1000
4-
53
void nfc_playlist_nfc_select_menu_callback(void* context) {
64
NfcPlaylist* nfc_playlist = context;
75

86
Storage* storage = furi_record_open(RECORD_STORAGE);
97
File* file = storage_file_alloc(storage);
10-
8+
119
if (storage_file_open(file, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ_WRITE, FSOM_OPEN_EXISTING)) {
12-
uint8_t buffer[MAX_PLAYLIST_SIZE];
13-
uint16_t read_count = storage_file_read(file, buffer, MAX_PLAYLIST_SIZE);
10+
uint8_t buffer[PLAYLIST_VIEW_MAX_SIZE];
11+
uint16_t read_count = storage_file_read(file, buffer, PLAYLIST_VIEW_MAX_SIZE);
1412
FuriString* playlist_content = furi_string_alloc();
1513

1614
for(uint16_t i = 0; i < read_count; i++) {
@@ -32,7 +30,7 @@ void nfc_playlist_nfc_select_menu_callback(void* context) {
3230
storage_file_free(file);
3331
furi_record_close(RECORD_STORAGE);
3432
furi_string_reset(nfc_playlist->file_browser_output);
35-
33+
3634
scene_manager_previous_scene(nfc_playlist->scene_manager);
3735
}
3836

@@ -50,7 +48,7 @@ void nfc_playlist_nfc_select_scene_on_enter(void* context) {
5048
FuriString* tmp_str = furi_string_alloc_set_str("/ext/nfc/");
5149
file_browser_start(nfc_playlist->file_browser, tmp_str);
5250
furi_string_free(tmp_str);
53-
51+
5452
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileBrowser);
5553
}
5654

scenes/nfc_playlist_scene_playlist_select.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ void nfc_playlist_playlist_select_scene_on_enter(void* context) {
1515
PLAYLIST_LOCATION,
1616
true,
1717
true,
18-
&I_Nfc_10px,
18+
&I_unknown_10px,
1919
true);
2020
file_browser_set_callback(nfc_playlist->file_browser, nfc_playlist_playlist_select_menu_callback, nfc_playlist);
2121
FuriString* tmp_str = furi_string_alloc_set_str(PLAYLIST_LOCATION);
2222
file_browser_start(nfc_playlist->file_browser, tmp_str);
2323
furi_string_free(tmp_str);
24-
24+
2525
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileBrowser);
2626
}
2727

0 commit comments

Comments
 (0)