Просмотр исходного кода

Merge pull request #11 from acegoal07/dev

Dev
acegoal07 1 год назад
Родитель
Сommit
c6263816f0
6 измененных файлов с 28 добавлено и 24 удалено
  1. 3 3
      README.md
  2. 4 0
      lib/worker/nfc_playlist_worker.c
  3. 2 1
      lib/worker/nfc_playlist_worker.h
  4. 1 1
      nfc_playlist.c
  5. 16 17
      scences/emulation.c
  6. 2 2
      scences/main_menu.c

+ 3 - 3
README.md

@@ -1,7 +1,7 @@
 # FlipperZero_NFC_Playlist:
 The idea behind this app is to allow for you to test multiple copies of NFC's at once as a bulk test
 
-## How it works (As of the moment will change):
+## How it works:
 When starting the app you are greeted by a select file option where you choose the playlist you wanna run.
 
 All the playlists should be placed in ext/apps_data/nfc_playlist and an example of how the data in the file should look can be found below.
@@ -14,12 +14,12 @@ An example file can be found in the repository
 ## How to build
 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
 
-## Settings
+## Settings:
 - Emulate time (How long the NFC card will be emulated for)
 - Delay time (How long the gap between the cards will be)
 - LED indicator (Whether or not the LED's will be on)
 - Reset settings (Puts all the settings back to the defaults)
 
-## Playlist editor
+## Playlist editor:
 - Delete playlist (Deletes the selected playlist)
 - Rename playlist (Renames the selected playlist the new name provided)

+ 4 - 0
lib/worker/nfc_playlist_worker.c

@@ -74,6 +74,10 @@ void nfc_playlist_worker_set_nfc_data(NfcPlaylistWorker* nfc_playlist_worker, ch
    nfc_playlist_worker->nfc_protocol = nfc_device_get_protocol(nfc_playlist_worker->nfc_device);
 }
 
+void nfc_playlist_worker_clear_nfc_data(NfcPlaylistWorker* nfc_playlist_worker) {
+   nfc_device_clear(nfc_playlist_worker->nfc_device);
+}
+
 NfcDeviceData* nfc_playlist_worker_get_nfc_data(NfcPlaylistWorker* nfc_playlist_worker) {
    return nfc_playlist_worker->nfc_data;
 }

+ 2 - 1
lib/worker/nfc_playlist_worker.h

@@ -29,4 +29,5 @@ 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);
+void nfc_playlist_worker_clear_nfc_data(NfcPlaylistWorker* nfc_playlist_worker);
+NfcDeviceData* nfc_playlist_worker_get_nfc_data(NfcPlaylistWorker* nfc_playlist_worker);

+ 1 - 1
nfc_playlist.c

@@ -68,7 +68,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
    nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->settings.file_path);
    nfc_playlist->text_input = text_input_alloc();
    nfc_playlist->popup = popup_alloc();
-  
+
    view_dispatcher_set_event_callback_context(nfc_playlist->view_dispatcher, nfc_playlist);
    view_dispatcher_set_custom_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_custom_callback);
    view_dispatcher_set_navigation_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_back_event_callback);

+ 16 - 17
scences/emulation.c

@@ -70,7 +70,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
 
          if (strlen(file_path) <= 1) {continue;}
 
-         if (nfc_playlist->settings.emulate_delay > 0 && file_position > 0) {
+         if (nfc_playlist->settings.emulate_delay > 0 && file_position != 0) {
             popup_set_header(nfc_playlist->popup, "Delaying", 64, 10, AlignCenter, AlignTop);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000);
@@ -87,10 +87,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
 
          if (EmulationState != NfcPlaylistEmulationState_Emulating) {break;}
 
-         char const* full_file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path;
-         char file_name[sizeof(full_file_name)];
-         strcpy(file_name, full_file_name);
-         strtok(file_name, ".");
+         char* file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path;
          char const* file_ext = &strrchr(file_path, '.')[1];
          int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000);
 
@@ -100,26 +97,26 @@ int32_t nfc_playlist_emulation_task(void* context) {
             snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR not found:", file_name);
             popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
-            while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
-               char popup_text[9];
-               snprintf(popup_text, 9, "%ds", (time_counter_ms/1000));
+            do {
+               char popup_text[10];
+               snprintf(popup_text, 10, "%ds", (time_counter_ms/1000));
                popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop);
                furi_delay_ms(50);
                time_counter_ms -= 50;
-            }
+            } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
          } else if (strcasestr(file_ext, "nfc") == NULL) {
             int popup_header_text_size = strlen(file_name) + 21;
             char popup_header_text[popup_header_text_size];
             snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR invalid file:", file_name);
             popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
-            while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
-               char popup_text[9];
-               snprintf(popup_text, 9, "%ds", (time_counter_ms/1000));
+            do {
+               char popup_text[10];
+               snprintf(popup_text, 10, "%ds", (time_counter_ms/1000));
                popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop);
                furi_delay_ms(50);
                time_counter_ms -= 50;
-            }
+            } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
          } else {
             int popup_header_text_size = strlen(file_name) + 12;
             char popup_header_text[popup_header_text_size];
@@ -128,15 +125,17 @@ int32_t nfc_playlist_emulation_task(void* context) {
             nfc_playlist_worker_set_nfc_data(nfc_playlist->nfc_playlist_worker, file_path);
             nfc_playlist_worker_start(nfc_playlist->nfc_playlist_worker);
             start_blink(nfc_playlist, NfcPlaylistLedState_Normal);
-            while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
-               char popup_text[9];
-               snprintf(popup_text, 9, "%ds", (time_counter_ms/1000));
+            do {
+               char popup_text[10];
+               snprintf(popup_text, 10, "%ds", (time_counter_ms/1000));
                popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop);
                furi_delay_ms(50);
                time_counter_ms -= 50;
-            }
+            } while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
             nfc_playlist_worker_stop(nfc_playlist->nfc_playlist_worker);
+            nfc_playlist_worker_clear_nfc_data(nfc_playlist->nfc_playlist_worker);
          }
+         free(file_path);
       }
       popup_reset(nfc_playlist->popup);
       popup_set_header(nfc_playlist->popup, EmulationState == NfcPlaylistEmulationState_Canceled ? "Emulation stopped" : "Emulation finished", 64, 10, AlignCenter, AlignTop);

+ 2 - 2
scences/main_menu.c

@@ -60,7 +60,7 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
       NfcPlaylistMenuSelection_FileSelect,
       nfc_playlist_main_menu_menu_callback,
       nfc_playlist);
-   
+
    submenu_add_item(
       nfc_playlist->submenu,
       "Edit playlist",
@@ -101,7 +101,7 @@ bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent even
          default:
             break;
       }
-   } 
+   }
    return consumed;
 }