Skip to content

Commit

Permalink
Merge pull request #29 from acegoal07/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
acegoal07 authored Jun 3, 2024
2 parents 5d211f4 + c65c6e7 commit 29da8eb
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 211 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ As i know these firmwares are supported and working if you know any more please
- Add NFC Item (Adds the selected nfc item to the currently selected playlist)
- Remove NFC Item (Opens a menu allowing you to select a line to remove from the playlist)
- View playlist content (Allows you to view the contents of the playlist)
## Development plans/ideas:
Things i would like to add:
- Ability to remove cards from the playlist

These features are not guaranteed to be added but are being looked at as features to add
## Known issues
### Renaming/creating playlist
I know of an issue with these functions that can cause them to lock the viewport if you put in a name that is very long im looking into fixing this and finding a solution

Any feedback is welcome and would be very much appreciated
4 changes: 2 additions & 2 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ App(
fap_category="NFC",
fap_author="@acegoal07",
fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main",
fap_version="2.1",
fap_version="2.2",
fap_icon="assets/icon.png",
fap_private_libs=[
Lib(
name="worker",
name="emulation_worker",
),
],
)
73 changes: 73 additions & 0 deletions lib/emulation_worker/nfc_playlist_emulation_worker.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "nfc_playlist_emulation_worker.h"

NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker_alloc() {
NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker = malloc(sizeof(NfcPlaylistEmulationWorker));
nfc_playlist_emulation_worker->thread = furi_thread_alloc_ex("NfcPlaylistEmulationWorker", 4096, nfc_playlist_emulation_worker_task, nfc_playlist_emulation_worker);
nfc_playlist_emulation_worker->state = NfcPlaylistEmulationWorkerState_Stopped;
nfc_playlist_emulation_worker->nfc = nfc_alloc();
nfc_playlist_emulation_worker->nfc_device = nfc_device_alloc();
return nfc_playlist_emulation_worker;
}

void nfc_playlist_emulation_worker_free(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker) {
furi_assert(nfc_playlist_emulation_worker);
furi_thread_free(nfc_playlist_emulation_worker->thread);
nfc_free(nfc_playlist_emulation_worker->nfc);
nfc_device_free(nfc_playlist_emulation_worker->nfc_device);
free(nfc_playlist_emulation_worker);
}

void nfc_playlist_emulation_worker_stop(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker) {
furi_assert(nfc_playlist_emulation_worker);
if (nfc_playlist_emulation_worker->state != NfcPlaylistEmulationWorkerState_Stopped) {
nfc_playlist_emulation_worker->state = NfcPlaylistEmulationWorkerState_Stopped;
furi_thread_join(nfc_playlist_emulation_worker->thread);
}
}

void nfc_playlist_emulation_worker_start(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker) {
furi_assert(nfc_playlist_emulation_worker);
nfc_playlist_emulation_worker->state = NfcPlaylistEmulationWorkerState_Emulating;
furi_thread_start(nfc_playlist_emulation_worker->thread);
}

int32_t nfc_playlist_emulation_worker_task(void* context) {
NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker = context;

if (nfc_playlist_emulation_worker->state == NfcPlaylistEmulationWorkerState_Emulating) {

nfc_playlist_emulation_worker->nfc_listener =
nfc_listener_alloc(nfc_playlist_emulation_worker->nfc,
nfc_playlist_emulation_worker->nfc_protocol,
nfc_device_get_data(nfc_playlist_emulation_worker->nfc_device, nfc_playlist_emulation_worker->nfc_protocol)
);
nfc_listener_start(nfc_playlist_emulation_worker->nfc_listener, NULL, NULL);

while(nfc_playlist_emulation_worker->state == NfcPlaylistEmulationWorkerState_Emulating) {
furi_delay_ms(50);
}

nfc_listener_stop(nfc_playlist_emulation_worker->nfc_listener);
nfc_listener_free(nfc_playlist_emulation_worker->nfc_listener);
}

nfc_playlist_emulation_worker->state = NfcPlaylistEmulationWorkerState_Stopped;

return 0;
}

bool nfc_playlist_emulation_worker_is_emulating(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker) {
furi_assert(nfc_playlist_emulation_worker);
return nfc_playlist_emulation_worker->state == NfcPlaylistEmulationWorkerState_Emulating;
}

void nfc_playlist_emulation_worker_set_nfc_data(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker, char* file_path) {
furi_assert(nfc_playlist_emulation_worker);
nfc_device_load(nfc_playlist_emulation_worker->nfc_device, file_path);
nfc_playlist_emulation_worker->nfc_protocol = nfc_device_get_protocol(nfc_playlist_emulation_worker->nfc_device);
}

void nfc_playlist_emulation_worker_clear_nfc_data(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker) {
furi_assert(nfc_playlist_emulation_worker);
nfc_device_clear(nfc_playlist_emulation_worker->nfc_device);
}
31 changes: 31 additions & 0 deletions lib/emulation_worker/nfc_playlist_emulation_worker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#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 NfcPlaylistEmulationWorkerState {
NfcPlaylistEmulationWorkerState_Emulating,
NfcPlaylistEmulationWorkerState_Stopped
} NfcPlaylistEmulationWorkerState;

typedef struct NfcPlaylistEmulationWorker {
FuriThread* thread;
NfcPlaylistEmulationWorkerState state;
NfcListener* nfc_listener;
NfcDevice* nfc_device;
NfcProtocol nfc_protocol;
Nfc* nfc;
} NfcPlaylistEmulationWorker;

NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker_alloc();
void nfc_playlist_emulation_worker_free(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker);
void nfc_playlist_emulation_worker_stop(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker);
void nfc_playlist_emulation_worker_start(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker);

int32_t nfc_playlist_emulation_worker_task(void* context);

bool nfc_playlist_emulation_worker_is_emulating(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker);
void nfc_playlist_emulation_worker_set_nfc_data(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker, char* file_path);
void nfc_playlist_emulation_worker_clear_nfc_data(NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker);
73 changes: 0 additions & 73 deletions lib/worker/nfc_playlist_worker.c

This file was deleted.

31 changes: 0 additions & 31 deletions lib/worker/nfc_playlist_worker.h

This file was deleted.

9 changes: 4 additions & 5 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ static NfcPlaylist* nfc_playlist_alloc() {
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input));

Storage* storage = furi_record_open(RECORD_STORAGE);
if (!storage_common_exists(storage, PLAYLIST_DIR)) {
storage_common_mkdir(storage, PLAYLIST_DIR);
}
storage_simply_mkdir(storage, PLAYLIST_DIR);

furi_record_close(RECORD_STORAGE);

return nfc_playlist;
Expand All @@ -68,11 +67,11 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {

scene_manager_free(nfc_playlist->scene_manager);
view_dispatcher_free(nfc_playlist->view_dispatcher);
furi_record_close(RECORD_NOTIFICATION);

variable_item_list_free(nfc_playlist->variable_item_list);
submenu_free(nfc_playlist->submenu);
widget_free(nfc_playlist->widget);

furi_record_close(RECORD_NOTIFICATION);
file_browser_free(nfc_playlist->file_browser);
text_input_free(nfc_playlist->text_input);
popup_free(nfc_playlist->popup);
Expand Down
13 changes: 7 additions & 6 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@

#include <toolbox/stream/stream.h>
#include <toolbox/stream/file_stream.h>
#include <toolbox/path.h>

#include "lib/worker/nfc_playlist_worker.h"
#include "lib/emulation_worker/nfc_playlist_emulation_worker.h"

#include "scenes/nfc_playlist_scene.h"

#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"
#define MAX_PLAYLIST_NAME_LEN 50

typedef enum {
NfcPlaylistView_Submenu,
NfcPlaylistView_Popup,
Expand Down Expand Up @@ -60,8 +65,7 @@ typedef struct {
char* text_input_output;
NotificationApp* notification;
FuriThread* thread;
FuriString* temp_furi_string;
NfcPlaylistWorker* nfc_playlist_worker;
NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker;
NfcPlaylistSettings settings;
} NfcPlaylist;

Expand All @@ -72,9 +76,6 @@ static const int default_emulate_delay = 0;
static const bool default_emulate_led_indicator = true;
static const bool default_skip_error = false;

#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"

typedef enum NfcPlaylistLedState {
NfcPlaylistLedState_Normal,
NfcPlaylistLedState_Error
Expand Down
17 changes: 9 additions & 8 deletions scenes/nfc_playlist_scene_confirm_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ void nfc_playlist_confirm_delete_menu_callback(GuiButtonType result, InputType t
void nfc_playlist_confirm_delete_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;

FuriString* temp_str = furi_string_alloc();
char* file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.playlist_path);
furi_string_printf(temp_str, "\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path);
furi_string_replace(temp_str, ".txt", "");
FuriString* file_name = furi_string_alloc();
path_extract_filename_no_ext(furi_string_get_cstr(nfc_playlist->settings.playlist_path), file_name);
FuriString* temp_str = furi_string_alloc_printf("\e#Delete %s?\e#", furi_string_get_cstr(file_name));

widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false);
widget_add_button_element(nfc_playlist->widget, GuiButtonTypeLeft, "Cancel", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);
widget_add_button_element(nfc_playlist->widget, GuiButtonTypeRight, "Delete", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);

furi_string_free(temp_str);
furi_string_free(file_name);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
}
Expand All @@ -31,12 +31,13 @@ bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent
switch(event.event) {
case GuiButtonTypeRight:
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.playlist_path));
nfc_playlist->settings.playlist_selected = false;
furi_string_reset(nfc_playlist->settings.playlist_path);
if (storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.playlist_path))) {
nfc_playlist->settings.playlist_selected = false;
furi_string_reset(nfc_playlist->settings.playlist_path);
}
furi_record_close(RECORD_STORAGE);
consumed = true;
scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
consumed = true;
break;
default:
scene_manager_previous_scene(nfc_playlist->scene_manager);
Expand Down
Loading

0 comments on commit 29da8eb

Please sign in to comment.