Skip to content

Commit

Permalink
Moving settings
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed Feb 9, 2024
1 parent d852cc8 commit 42ce380
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 404 deletions.
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);
}
}
153 changes: 78 additions & 75 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,105 @@
#include "nfc_playlist_i.h"

static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
nfc_playlist_main_menu_scene_on_enter,
nfc_playlist_settings_scene_on_enter,
nfc_playlist_emulation_scene_on_enter,
nfc_playlist_file_select_scene_on_enter,
nfc_playlist_file_edit_scene_on_enter,
nfc_playlist_text_input_scene_on_enter
nfc_playlist_main_menu_scene_on_enter,
nfc_playlist_settings_scene_on_enter,
nfc_playlist_emulation_scene_on_enter,
nfc_playlist_file_select_scene_on_enter,
nfc_playlist_file_edit_scene_on_enter,
nfc_playlist_text_input_scene_on_enter
};

static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
nfc_playlist_main_menu_scene_on_event,
nfc_playlist_settings_scene_on_event,
nfc_playlist_emulation_scene_on_event,
nfc_playlist_file_select_scene_on_event,
nfc_playlist_file_edit_scene_on_event,
nfc_playlist_text_input_scene_on_event
nfc_playlist_main_menu_scene_on_event,
nfc_playlist_settings_scene_on_event,
nfc_playlist_emulation_scene_on_event,
nfc_playlist_file_select_scene_on_event,
nfc_playlist_file_edit_scene_on_event,
nfc_playlist_text_input_scene_on_event
};

static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
nfc_playlist_main_menu_scene_on_exit,
nfc_playlist_settings_scene_on_exit,
nfc_playlist_emulation_scene_on_exit,
nfc_playlist_file_select_scene_on_exit,
nfc_playlist_file_edit_scene_on_exit,
nfc_playlist_text_input_scene_on_exit
nfc_playlist_main_menu_scene_on_exit,
nfc_playlist_settings_scene_on_exit,
nfc_playlist_emulation_scene_on_exit,
nfc_playlist_file_select_scene_on_exit,
nfc_playlist_file_edit_scene_on_exit,
nfc_playlist_text_input_scene_on_exit
};

static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
.on_enter_handlers = nfc_playlist_scene_on_enter_handlers,
.on_event_handlers = nfc_playlist_scene_on_event_handlers,
.on_exit_handlers = nfc_playlist_scene_on_exit_handlers,
.scene_num = NfcPlaylistScene_count,
.on_enter_handlers = nfc_playlist_scene_on_enter_handlers,
.on_event_handlers = nfc_playlist_scene_on_event_handlers,
.on_exit_handlers = nfc_playlist_scene_on_exit_handlers,
.scene_num = NfcPlaylistScene_count
};

static bool nfc_playlist_custom_callback(void* context, uint32_t custom_event) {
furi_assert(context);
NfcPlaylist* nfc_playlist = context;
return scene_manager_handle_custom_event(nfc_playlist->scene_manager, custom_event);
furi_assert(context);
NfcPlaylist* nfc_playlist = context;
return scene_manager_handle_custom_event(nfc_playlist->scene_manager, custom_event);
}

static bool nfc_playlist_back_event_callback(void* context) {
furi_assert(context);
NfcPlaylist* nfc_playlist = context;
return scene_manager_handle_back_event(nfc_playlist->scene_manager);
furi_assert(context);
NfcPlaylist* nfc_playlist = context;
return scene_manager_handle_back_event(nfc_playlist->scene_manager);
}

static NfcPlaylist* nfc_playlist_alloc() {
NfcPlaylist* nfc_playlist = malloc(sizeof(NfcPlaylist));
furi_assert(nfc_playlist);
nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_manager_handlers, nfc_playlist);
nfc_playlist->view_dispatcher = view_dispatcher_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->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);
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings, variable_item_list_get_view(nfc_playlist->variable_item_list));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect, file_browser_get_view(nfc_playlist->file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input));
return nfc_playlist;
NfcPlaylist* nfc_playlist = malloc(sizeof(NfcPlaylist));
furi_assert(nfc_playlist);
nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_manager_handlers, nfc_playlist);
nfc_playlist->view_dispatcher = view_dispatcher_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->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();

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);
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings, variable_item_list_get_view(nfc_playlist->variable_item_list));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect, file_browser_get_view(nfc_playlist->file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input));
return nfc_playlist;
}

static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
furi_assert(nfc_playlist);
scene_manager_free(nfc_playlist->scene_manager);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
view_dispatcher_free(nfc_playlist->view_dispatcher);
variable_item_list_free(nfc_playlist->variable_item_list);
submenu_free(nfc_playlist->submenu);
file_browser_free(nfc_playlist->file_browser);
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);
free(nfc_playlist->playlist_name);
free(nfc_playlist);
furi_assert(nfc_playlist);
scene_manager_free(nfc_playlist->scene_manager);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
view_dispatcher_free(nfc_playlist->view_dispatcher);
variable_item_list_free(nfc_playlist->variable_item_list);
submenu_free(nfc_playlist->submenu);
file_browser_free(nfc_playlist->file_browser);
text_input_free(nfc_playlist->text_input);
popup_free(nfc_playlist->popup);
furi_record_close(RECORD_NOTIFICATION);
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);
}

int32_t nfc_playlist_main(void* p) {
Expand Down
18 changes: 11 additions & 7 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 42ce380

Please sign in to comment.