Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed May 23, 2024
1 parent 416e22f commit 6fa0239
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 31 deletions.
6 changes: 3 additions & 3 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#include <toolbox/stream/stream.h>
#include <toolbox/stream/file_stream.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 PLAYLIST_NAME_LEN 100
#define PLAYLIST_NAME_LEN 50

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

Expand Down
3 changes: 1 addition & 2 deletions scenes/nfc_playlist_scene_confirm_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ 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);
FuriString* temp_str = furi_string_alloc_printf("\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path);
furi_string_replace(temp_str, ".txt", "");

widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false);
Expand Down
29 changes: 20 additions & 9 deletions scenes/nfc_playlist_scene_emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ int32_t nfc_playlist_emulation_task(void* context) {
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
furi_delay_ms(50);
time_counter_delay_ms -= 50;
furi_string_reset(tmp_counter_str);
};
furi_string_reset(tmp_counter_str);
} else if (nfc_playlist->settings.emulate_delay > 0) {
skip_delay = false;
file_position++;
Expand All @@ -70,6 +72,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
furi_delay_ms(50);
time_counter_ms -= 50;
furi_string_reset(tmp_counter_str);
};
} else if(!storage_file_exists(storage, file_path)) {
if(nfc_playlist->settings.skip_error) {
Expand All @@ -84,25 +87,33 @@ int32_t nfc_playlist_emulation_task(void* context) {
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
furi_delay_ms(50);
time_counter_ms -= 50;
furi_string_reset(tmp_counter_str);
};
} else {
furi_string_printf(tmp_header_str, "Emulating:\n%s", file_name);
popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop);
nfc_playlist_worker_set_nfc_data(nfc_playlist->nfc_playlist_worker, file_path);
nfc_playlist_worker_start(nfc_playlist->nfc_playlist_worker);
nfc_playlist_emulation_worker_set_nfc_data(nfc_playlist->nfc_playlist_emulation_worker, file_path);
nfc_playlist_emulation_worker_start(nfc_playlist->nfc_playlist_emulation_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) {
while(nfc_playlist_emulation_worker_is_emulating(nfc_playlist->nfc_playlist_emulation_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000));
popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
furi_delay_ms(50);
time_counter_ms -= 50;
furi_string_reset(tmp_counter_str);
};
nfc_playlist_worker_stop(nfc_playlist->nfc_playlist_worker);
nfc_playlist_worker_clear_nfc_data(nfc_playlist->nfc_playlist_worker);
nfc_playlist_emulation_worker_stop(nfc_playlist->nfc_playlist_emulation_worker);
nfc_playlist_emulation_worker_clear_nfc_data(nfc_playlist->nfc_playlist_emulation_worker);
}
furi_string_reset(tmp_header_str);
furi_string_reset(tmp_counter_str);
}
popup_reset(nfc_playlist->popup);
popup_set_header(nfc_playlist->popup, EmulationState == NfcPlaylistEmulationState_Canceled ? "Emulation stopped" : "Emulation finished", 64, 10, AlignCenter, AlignTop);
if (nfc_playlist->settings.playlist_length == 0) {
popup_set_header(nfc_playlist->popup, "Empty playlist", 64, 10, AlignCenter, AlignTop);
} else {
popup_set_header(nfc_playlist->popup, EmulationState == NfcPlaylistEmulationState_Canceled ? "Emulation stopped" : "Emulation finished", 64, 10, AlignCenter, AlignTop);
}
popup_set_text(nfc_playlist->popup, "Press back", 64, 50, AlignCenter, AlignTop);
stop_blink(nfc_playlist);

Expand All @@ -125,15 +136,15 @@ int32_t nfc_playlist_emulation_task(void* context) {
void nfc_playlist_emulation_setup(void* context) {
NfcPlaylist* nfc_playlist = context;
nfc_playlist->thread = furi_thread_alloc_ex("NfcPlaylistEmulationWorker", 8192, nfc_playlist_emulation_task, nfc_playlist);
nfc_playlist->nfc_playlist_worker = nfc_playlist_worker_alloc();
nfc_playlist->nfc_playlist_emulation_worker = nfc_playlist_emulation_worker_alloc();
}

void nfc_playlist_emulation_free(NfcPlaylist* nfc_playlist) {
furi_assert(nfc_playlist);
furi_thread_free(nfc_playlist->thread);
nfc_playlist_worker_free(nfc_playlist->nfc_playlist_worker);
nfc_playlist_emulation_worker_free(nfc_playlist->nfc_playlist_emulation_worker);
nfc_playlist->thread = NULL;
nfc_playlist->nfc_playlist_worker = NULL;
nfc_playlist->nfc_playlist_emulation_worker = NULL;
}

void nfc_playlist_emulation_start(NfcPlaylist* nfc_playlist) {
Expand Down
7 changes: 3 additions & 4 deletions scenes/nfc_playlist_scene_main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
return;
}

FuriString* tmp_str = furi_string_alloc();
furi_string_printf(tmp_str, "NFC Playlist v%s", FAP_VERSION);
submenu_set_header(nfc_playlist->submenu, furi_string_get_cstr(tmp_str));
furi_string_free(tmp_str);
FuriString* header = furi_string_alloc_printf("NFC Playlist v%s", FAP_VERSION);
submenu_set_header(nfc_playlist->submenu, furi_string_get_cstr(header));
furi_string_free(header);

submenu_add_lockable_item(
nfc_playlist->submenu,
Expand Down
13 changes: 6 additions & 7 deletions scenes/nfc_playlist_scene_nfc_remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void nfc_playlist_nfc_remove_options_change_callback(VariableItem* item) {

void nfc_playlist_nfc_remove_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;
FuriString* tmp_str = furi_string_alloc();

selected_line = nfc_playlist->settings.playlist_length;

Expand All @@ -45,15 +44,17 @@ void nfc_playlist_nfc_remove_scene_on_enter(void* context) {
nfc_playlist_nfc_remove_options_change_callback,
nfc_playlist);
variable_item_set_current_value_index(Line_selector, nfc_playlist->settings.playlist_length - 1);
furi_string_printf(tmp_str, "%d", selected_line);

FuriString* tmp_str = furi_string_alloc_printf("%d", selected_line);
variable_item_set_current_value_text(Line_selector, furi_string_get_cstr(tmp_str));
furi_string_free(tmp_str);

variable_item_set_locked(Line_selector, nfc_playlist->settings.playlist_length == 0 ? true : false, "Playlist\nis empty");

variable_item_list_add(nfc_playlist->variable_item_list, "Remove Line", 0, NULL, NULL);
variable_item_set_locked(variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_RemoveLine), nfc_playlist->settings.playlist_length == 0 ? true : false, "Playlist\nis empty");

variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_nfc_remove_menu_callback, nfc_playlist);
furi_string_free(tmp_str);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_VariableItemList);
}
Expand Down Expand Up @@ -97,14 +98,12 @@ bool nfc_playlist_nfc_remove_scene_on_event(void* context, SceneManagerEvent eve
if (selected_line == 0) {
scene_manager_previous_scene(nfc_playlist->scene_manager);
} else {
FuriString* tmp_str = furi_string_alloc();

VariableItem* Line_selector = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LineSelector);
variable_item_set_values_count(Line_selector, nfc_playlist->settings.playlist_length);
variable_item_set_current_value_index(Line_selector, selected_line - 1);
furi_string_printf(tmp_str, "%d", selected_line);
variable_item_set_current_value_text(Line_selector, furi_string_get_cstr(tmp_str));

FuriString* tmp_str = furi_string_alloc_printf("%d", selected_line);
variable_item_set_current_value_text(Line_selector, furi_string_get_cstr(tmp_str));
furi_string_free(tmp_str);
}

Expand Down
12 changes: 7 additions & 5 deletions scenes/nfc_playlist_scene_playlist_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void nfc_playlist_playlist_edit_scene_on_enter(void* context) {

submenu_set_header(nfc_playlist->submenu, "Edit Playlist");

bool playlist_path_empty = furi_string_empty(nfc_playlist->settings.playlist_path);

submenu_add_item(
nfc_playlist->submenu,
"Create Playlist",
Expand All @@ -32,7 +34,7 @@ void nfc_playlist_playlist_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_DeletePlaylist,
nfc_playlist_playlist_edit_menu_callback,
nfc_playlist,
furi_string_empty(nfc_playlist->settings.playlist_path),
playlist_path_empty,
"No\nplaylist\nselected");

submenu_add_lockable_item(
Expand All @@ -41,7 +43,7 @@ void nfc_playlist_playlist_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_RenamePlaylist,
nfc_playlist_playlist_edit_menu_callback,
nfc_playlist,
furi_string_empty(nfc_playlist->settings.playlist_path),
playlist_path_empty,
"No\nplaylist\nselected");

submenu_add_lockable_item(
Expand All @@ -50,7 +52,7 @@ void nfc_playlist_playlist_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_AddNfcItem,
nfc_playlist_playlist_edit_menu_callback,
nfc_playlist,
furi_string_empty(nfc_playlist->settings.playlist_path),
playlist_path_empty,
"No\nplaylist\nselected");

submenu_add_lockable_item(
Expand All @@ -59,7 +61,7 @@ void nfc_playlist_playlist_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_RemoveNfcItem,
nfc_playlist_playlist_edit_menu_callback,
nfc_playlist,
furi_string_empty(nfc_playlist->settings.playlist_path),
playlist_path_empty,
"No\nplaylist\nselected");

submenu_add_lockable_item(
Expand All @@ -68,7 +70,7 @@ void nfc_playlist_playlist_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_ViewPlaylistContent,
nfc_playlist_playlist_edit_menu_callback,
nfc_playlist,
furi_string_empty(nfc_playlist->settings.playlist_path),
playlist_path_empty,
"No\nplaylist\nselected");

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Submenu);
Expand Down
3 changes: 2 additions & 1 deletion scenes/nfc_playlist_scene_playlist_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ void nfc_playlist_playlist_rename_menu_callback(void* context) {
furi_string_cat_str(new_file_path, ".txt");

Storage* storage = furi_record_open(RECORD_STORAGE);

if (!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) {
storage_common_rename(storage, old_file_path, furi_string_get_cstr(new_file_path));
furi_string_swap(nfc_playlist->settings.playlist_path, new_file_path);
}
furi_record_close(RECORD_STORAGE);

furi_record_close(RECORD_STORAGE);
furi_string_free(new_file_path);

scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
Expand Down

0 comments on commit 6fa0239

Please sign in to comment.