Skip to content

Commit

Permalink
Merge pull request #9 from acegoal07/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
acegoal07 authored Feb 20, 2024
2 parents df60e6e + fe37f03 commit 5040683
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 70 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ App(
fap_category="NFC",
fap_author="@acegoal07",
fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main",
fap_version="1.3",
fap_version="1.4",
fap_icon="assets/icon.png",
fap_private_libs=[
Lib(
Expand Down
4 changes: 2 additions & 2 deletions lib/led/nfc_playlist_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const NotificationSequence blink_sequence_error = {
};

void start_blink(NfcPlaylist* nfc_playlist, int state) {
if (nfc_playlist->emulate_led_indicator) {
if (nfc_playlist->settings.emulate_led_indicator) {
if (state == NfcPlaylistLedState_Normal) {
notification_message_block(nfc_playlist->notification, &blink_sequence_normal);
} else if (state == NfcPlaylistLedState_Error) {
Expand All @@ -36,7 +36,7 @@ void start_blink(NfcPlaylist* nfc_playlist, int state) {
}

void stop_blink(NfcPlaylist* nfc_playlist) {
if (nfc_playlist->emulate_led_indicator) {
if (nfc_playlist->settings.emulate_led_indicator) {
notification_message_block(nfc_playlist->notification, &sequence_blink_stop);
}
}
25 changes: 14 additions & 11 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ static NfcPlaylist* nfc_playlist_alloc() {
view_dispatcher_enable_queue(nfc_playlist->view_dispatcher);
nfc_playlist->variable_item_list = variable_item_list_alloc();
nfc_playlist->submenu = submenu_alloc();
nfc_playlist->base_file_path = furi_string_alloc_set_str("/ext/apps_data/nfc_playlist/");
nfc_playlist->file_path = nfc_playlist->base_file_path;
nfc_playlist->file_selected = false;
nfc_playlist->file_selected_check = false;
nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->file_path);

nfc_playlist->settings.base_file_path = furi_string_alloc_set_str("/ext/apps_data/nfc_playlist/");
nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
nfc_playlist->settings.file_selected = false;
nfc_playlist->settings.file_selected_check = false;
nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
nfc_playlist->settings.emulate_delay = default_emulate_delay;
nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;

nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);
nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->settings.file_path);
nfc_playlist->text_input = text_input_alloc();
nfc_playlist->popup = popup_alloc();
nfc_playlist->emulate_timeout = default_emulate_timeout;
nfc_playlist->emulate_delay = default_emulate_delay;
nfc_playlist->emulate_led_indicator = default_emulate_led_indicator;
nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);

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);
Expand Down Expand Up @@ -94,8 +97,8 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
text_input_free(nfc_playlist->text_input);
popup_free(nfc_playlist->popup);
furi_record_close(RECORD_NOTIFICATION);
furi_string_free(nfc_playlist->base_file_path);
furi_string_free(nfc_playlist->file_path);
furi_string_free(nfc_playlist->settings.base_file_path);
furi_string_free(nfc_playlist->settings.file_path);
free(nfc_playlist->playlist_name);
free(nfc_playlist);
}
Expand Down
20 changes: 12 additions & 8 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef enum {
NfcPlaylistView_Popup,
NfcPlaylistView_FileSelect,
NfcPlaylistView_FileEdit,
NfcPlaylistView_TextInput,
NfcPlaylistView_TextInput
} NfcPlayScenesView;

typedef enum {
Expand All @@ -33,6 +33,16 @@ typedef enum {
NfcPlaylistScene_count
} NfcPlaylistScene;

typedef struct {
FuriString* base_file_path;
FuriString* file_path;
bool file_selected;
bool file_selected_check;
uint8_t emulate_timeout;
uint8_t emulate_delay;
bool emulate_led_indicator;
} NfcPlaylistSettings;

typedef struct {
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
Expand All @@ -44,13 +54,7 @@ typedef struct {
NotificationApp* notification;
FuriThread* thread;
NfcPlaylistWorker* nfc_playlist_worker;
FuriString* base_file_path;
bool file_selected;
bool file_selected_check;
uint8_t emulate_timeout;
uint8_t emulate_delay;
bool emulate_led_indicator;
FuriString* file_path;
NfcPlaylistSettings settings;
char* playlist_name;
} NfcPlaylist;

Expand Down
11 changes: 5 additions & 6 deletions scences/emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void nfc_playlist_emulation_scene_on_exit(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();
}
Expand Down Expand Up @@ -62,7 +61,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
popup_set_context(nfc_playlist->popup, nfc_playlist);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);

if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->file_path), FSAM_READ, FSOM_OPEN_EXISTING) && nfc_playlist->file_selected_check) {
if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING) && nfc_playlist->settings.file_selected_check) {
EmulationState = NfcPlaylistEmulationState_Emulating;
int file_position = 0;
while(stream_read_line(stream, line) && EmulationState == NfcPlaylistEmulationState_Emulating) {
Expand All @@ -71,18 +70,18 @@ int32_t nfc_playlist_emulation_task(void* context) {

if (strlen(file_path) <= 1) {continue;}

if (nfc_playlist->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->emulate_delay]*1000);
int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000);
do {
char display_text[10];
snprintf(display_text, 10, "%ds", (time_counter_delay_ms/1000));
popup_set_text(nfc_playlist->popup, display_text, 64, 50, AlignCenter, AlignTop);
furi_delay_ms(50);
time_counter_delay_ms -= 50;
} while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
} else if (nfc_playlist->emulate_delay > 0) {
} else if (nfc_playlist->settings.emulate_delay > 0) {
file_position++;
}

Expand All @@ -93,7 +92,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
strcpy(file_name, full_file_name);
strtok(file_name, ".");
char const* file_ext = &strrchr(file_path, '.')[1];
int time_counter_ms = (options_emulate_timeout[nfc_playlist->emulate_timeout]*1000);
int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000);

if (storage_file_exists(storage, file_path) == false) {
int popup_header_text_size = strlen(file_name) + 18;
Expand Down
2 changes: 1 addition & 1 deletion scences/emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ int32_t nfc_playlist_emulation_task(void* context);
typedef enum NfcPlaylistEmulationState {
NfcPlaylistEmulationState_Emulating,
NfcPlaylistEmulationState_Stopped,
NfcPlaylistEmulationState_Canceled,
NfcPlaylistEmulationState_Canceled
} NfcPlaylistEmulationState;
12 changes: 6 additions & 6 deletions scences/file_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ void nfc_playlist_file_edit_menu_callback(void* context, uint32_t index) {
Storage* storage = furi_record_open(RECORD_STORAGE);
switch(index) {
case NfcPlaylistMenuSelection_DeletePlaylist: {
storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->file_path));
nfc_playlist->file_selected = false;
nfc_playlist->file_selected_check = false;
nfc_playlist->file_path = nfc_playlist->base_file_path;
storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path));
nfc_playlist->settings.file_selected = false;
nfc_playlist->settings.file_selected_check = false;
nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
scene_manager_previous_scene(nfc_playlist->scene_manager);
break;
}
Expand Down Expand Up @@ -43,7 +43,7 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_DeletePlaylist,
nfc_playlist_file_edit_menu_callback,
nfc_playlist,
!nfc_playlist->file_selected_check,
!nfc_playlist->settings.file_selected_check,
"No\nplaylist\nselected");

submenu_add_lockable_item(
Expand All @@ -52,7 +52,7 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_RenamePlaylist,
nfc_playlist_file_edit_menu_callback,
nfc_playlist,
!nfc_playlist->file_selected_check,
!nfc_playlist->settings.file_selected_check,
"No\nplaylist\nselected");

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
Expand Down
6 changes: 3 additions & 3 deletions scences/file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

void nfc_playlist_file_select_menu_callback(void* context) {
NfcPlaylist* nfc_playlist = context;
nfc_playlist->file_selected_check = true;
nfc_playlist->settings.file_selected_check = true;
scene_manager_previous_scene(nfc_playlist->scene_manager);
}

Expand All @@ -12,14 +12,14 @@ void nfc_playlist_file_select_scene_on_enter(void* context) {
file_browser_configure(
nfc_playlist->file_browser,
".txt",
furi_string_get_cstr(nfc_playlist->base_file_path),
furi_string_get_cstr(nfc_playlist->settings.base_file_path),
true,
true,
&I_sub1_10px,
true);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect);
file_browser_set_callback(nfc_playlist->file_browser, nfc_playlist_file_select_menu_callback, nfc_playlist);
file_browser_start(nfc_playlist->file_browser, nfc_playlist->base_file_path);
file_browser_start(nfc_playlist->file_browser, nfc_playlist->settings.base_file_path);
}

bool nfc_playlist_file_select_scene_on_event(void* context, SceneManagerEvent event) {
Expand Down
19 changes: 9 additions & 10 deletions scences/main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void nfc_playlist_main_menu_menu_callback(void* context, uint32_t index) {

void nfc_playlist_main_menu_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;
if (!nfc_playlist->file_selected) {
nfc_playlist->file_selected = true;
if (!nfc_playlist->settings.file_selected) {
nfc_playlist->settings.file_selected = true;
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileSelect);
return;
}
Expand All @@ -51,7 +51,7 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_Start,
nfc_playlist_main_menu_menu_callback,
nfc_playlist,
!nfc_playlist->file_selected_check,
!nfc_playlist->settings.file_selected_check,
"No\nplaylist\nselected");

submenu_add_item(
Expand All @@ -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",
Expand All @@ -74,14 +74,13 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_Settings,
nfc_playlist_main_menu_menu_callback,
nfc_playlist);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu);
}

bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent event) {
NfcPlaylist* nfc_playlist = context;
bool consumed = false;
if (event.type == SceneManagerEventTypeCustom) {
NfcPlaylist* nfc_playlist = context;
bool consumed = false;
if (event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case NfcPlaylistEvent_ShowEmulatingPopup:
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_EmulatingPopup);
Expand All @@ -102,8 +101,8 @@ bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent even
default:
break;
}
}
return consumed;
}
return consumed;
}

void nfc_playlist_main_menu_scene_on_exit(void* context) {
Expand Down
38 changes: 19 additions & 19 deletions scences/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ typedef enum {
void nfc_playlist_settings_menu_callback(void* context, uint32_t index) {
NfcPlaylist* nfc_playlist = context;
if (index == NfcPlaylistSettings_Reset) {
nfc_playlist->emulate_timeout = default_emulate_timeout;
nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
VariableItem* emulation_timeout_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Timeout);
variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->emulate_timeout);
variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout);
char emulation_timeout_settings_text[3];
snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->emulate_timeout]);
snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);

nfc_playlist->emulate_delay = default_emulate_delay;
nfc_playlist->settings.emulate_delay = default_emulate_delay;
VariableItem* emulation_delay_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Delay);
variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->emulate_delay);
variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay);
char emulation_delay_settings_text[3];
snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->emulate_delay]);
snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);

nfc_playlist->emulate_led_indicator = default_emulate_led_indicator;
nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator);
variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator);
variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator ? "ON" : "OFF");
variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
}
}

Expand All @@ -40,22 +40,22 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) {

switch(current_option) {
case NfcPlaylistSettings_Timeout: {
nfc_playlist->emulate_timeout = option_value_index;
nfc_playlist->settings.emulate_timeout = option_value_index;
char emulate_timeout_text[3];
snprintf(emulate_timeout_text, 3, "%ds", options_emulate_timeout[option_value_index]);
variable_item_set_current_value_text(item, (char*)emulate_timeout_text);
break;
}
case NfcPlaylistSettings_Delay: {
nfc_playlist->emulate_delay = option_value_index;
nfc_playlist->settings.emulate_delay = option_value_index;
char emulate_delay_text[3];
snprintf(emulate_delay_text, 3, "%ds", options_emulate_delay[option_value_index]);
variable_item_set_current_value_text(item, (char*)emulate_delay_text);
break;
}
case NfcPlaylistSettings_LedIndicator:
nfc_playlist->emulate_led_indicator = option_value_index;
variable_item_set_current_value_text(item, nfc_playlist->emulate_led_indicator ? "ON" : "OFF");
nfc_playlist->settings.emulate_led_indicator = option_value_index;
variable_item_set_current_value_text(item, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
break;
default:
break;
Expand All @@ -73,9 +73,9 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
(sizeof(options_emulate_timeout)/sizeof(options_emulate_timeout[0])),
nfc_playlist_settings_options_change_callback,
nfc_playlist);
variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->emulate_timeout);
variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout);
char emulation_timeout_settings_text[3];
snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->emulate_timeout]);
snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);

VariableItem* emulation_delay_settings = variable_item_list_add(
Expand All @@ -84,9 +84,9 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
(sizeof(options_emulate_delay)/sizeof(options_emulate_delay[0])),
nfc_playlist_settings_options_change_callback,
nfc_playlist);
variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->emulate_delay);
variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay);
char emulation_delay_settings_text[3];
snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->emulate_delay]);
snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);

VariableItem* emulation_led_indicator_settings = variable_item_list_add(
Expand All @@ -95,8 +95,8 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
2,
nfc_playlist_settings_options_change_callback,
nfc_playlist);
variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator);
variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator ? "ON" : "OFF");
variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");

variable_item_list_add(nfc_playlist->variable_item_list, "Reset settings", 0, NULL, NULL);

Expand Down
Loading

0 comments on commit 5040683

Please sign in to comment.