|
@@ -1,42 +1,4 @@
|
|
|
#include "nfc_playlist.h"
|
|
#include "nfc_playlist.h"
|
|
|
-#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_file_rename_scene_on_enter,
|
|
|
|
|
- nfc_playlist_confirm_delete_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_file_rename_scene_on_event,
|
|
|
|
|
- nfc_playlist_confirm_delete_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_file_rename_scene_on_exit,
|
|
|
|
|
- nfc_playlist_confirm_delete_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
|
|
|
|
|
-};
|
|
|
|
|
|
|
|
|
|
static bool nfc_playlist_custom_callback(void* context, uint32_t custom_event) {
|
|
static bool nfc_playlist_custom_callback(void* context, uint32_t custom_event) {
|
|
|
furi_assert(context);
|
|
furi_assert(context);
|
|
@@ -53,40 +15,40 @@ static bool nfc_playlist_back_event_callback(void* context) {
|
|
|
static NfcPlaylist* nfc_playlist_alloc() {
|
|
static NfcPlaylist* nfc_playlist_alloc() {
|
|
|
NfcPlaylist* nfc_playlist = malloc(sizeof(NfcPlaylist));
|
|
NfcPlaylist* nfc_playlist = malloc(sizeof(NfcPlaylist));
|
|
|
furi_assert(nfc_playlist);
|
|
furi_assert(nfc_playlist);
|
|
|
- nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_manager_handlers, nfc_playlist);
|
|
|
|
|
|
|
+ nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_handlers, nfc_playlist);
|
|
|
nfc_playlist->view_dispatcher = view_dispatcher_alloc();
|
|
nfc_playlist->view_dispatcher = view_dispatcher_alloc();
|
|
|
view_dispatcher_enable_queue(nfc_playlist->view_dispatcher);
|
|
view_dispatcher_enable_queue(nfc_playlist->view_dispatcher);
|
|
|
nfc_playlist->variable_item_list = variable_item_list_alloc();
|
|
nfc_playlist->variable_item_list = variable_item_list_alloc();
|
|
|
nfc_playlist->submenu = submenu_alloc();
|
|
nfc_playlist->submenu = submenu_alloc();
|
|
|
nfc_playlist->widget= widget_alloc();
|
|
nfc_playlist->widget= widget_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.file_path = furi_string_alloc();
|
|
|
|
|
+ nfc_playlist->file_browser_output = furi_string_alloc();
|
|
|
|
|
+ nfc_playlist->settings.playlist_selected = false;
|
|
|
nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
|
|
nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
|
|
|
nfc_playlist->settings.emulate_delay = default_emulate_delay;
|
|
nfc_playlist->settings.emulate_delay = default_emulate_delay;
|
|
|
nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
|
|
nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
|
|
|
|
|
|
|
|
nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);
|
|
nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);
|
|
|
- nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->settings.file_path);
|
|
|
|
|
|
|
+ nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->file_browser_output);
|
|
|
|
|
+
|
|
|
nfc_playlist->text_input = text_input_alloc();
|
|
nfc_playlist->text_input = text_input_alloc();
|
|
|
nfc_playlist->popup = popup_alloc();
|
|
nfc_playlist->popup = popup_alloc();
|
|
|
|
|
|
|
|
view_dispatcher_set_event_callback_context(nfc_playlist->view_dispatcher, nfc_playlist);
|
|
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_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_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_Submenu, submenu_get_view(nfc_playlist->submenu));
|
|
|
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_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_FileRename, text_input_get_view(nfc_playlist->text_input));
|
|
|
|
|
- view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete, widget_get_view(nfc_playlist->widget));
|
|
|
|
|
|
|
+ view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget, widget_get_view(nfc_playlist->widget));
|
|
|
|
|
+ view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_VariableItemList, variable_item_list_get_view(nfc_playlist->variable_item_list));
|
|
|
|
|
+ view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileBrowser, file_browser_get_view(nfc_playlist->file_browser));
|
|
|
|
|
+ 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);
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
- if (!storage_common_exists(storage, "/ext/apps_data/nfc_playlist")) {
|
|
|
|
|
- storage_common_mkdir(storage, "/ext/apps_data/nfc_playlist");
|
|
|
|
|
|
|
+ if (!storage_common_exists(storage, PLAYLIST_DIR)) {
|
|
|
|
|
+ storage_common_mkdir(storage, PLAYLIST_DIR);
|
|
|
}
|
|
}
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
|
@@ -96,13 +58,12 @@ static NfcPlaylist* nfc_playlist_alloc() {
|
|
|
static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
|
|
static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
|
|
|
furi_assert(nfc_playlist);
|
|
furi_assert(nfc_playlist);
|
|
|
|
|
|
|
|
- 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_Submenu);
|
|
|
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);
|
|
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_FileRename);
|
|
|
|
|
- view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete);
|
|
|
|
|
|
|
+ view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
|
|
|
|
|
+ view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_VariableItemList);
|
|
|
|
|
+ view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileBrowser);
|
|
|
|
|
+ view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
|
|
|
|
|
|
|
|
scene_manager_free(nfc_playlist->scene_manager);
|
|
scene_manager_free(nfc_playlist->scene_manager);
|
|
|
view_dispatcher_free(nfc_playlist->view_dispatcher);
|
|
view_dispatcher_free(nfc_playlist->view_dispatcher);
|
|
@@ -115,8 +76,8 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
|
|
|
text_input_free(nfc_playlist->text_input);
|
|
text_input_free(nfc_playlist->text_input);
|
|
|
popup_free(nfc_playlist->popup);
|
|
popup_free(nfc_playlist->popup);
|
|
|
|
|
|
|
|
- furi_string_free(nfc_playlist->settings.base_file_path);
|
|
|
|
|
furi_string_free(nfc_playlist->settings.file_path);
|
|
furi_string_free(nfc_playlist->settings.file_path);
|
|
|
|
|
+ furi_string_free(nfc_playlist->file_browser_output);
|
|
|
free(nfc_playlist);
|
|
free(nfc_playlist);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -144,4 +105,45 @@ int32_t nfc_playlist_main(void* p) {
|
|
|
nfc_playlist_free(nfc_playlist);
|
|
nfc_playlist_free(nfc_playlist);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+NotificationMessage blink_message_normal = {
|
|
|
|
|
+ .type = NotificationMessageTypeLedBlinkStart,
|
|
|
|
|
+ .data.led_blink.color = LightBlue | LightGreen,
|
|
|
|
|
+ .data.led_blink.on_time = 10,
|
|
|
|
|
+ .data.led_blink.period = 100
|
|
|
|
|
+};
|
|
|
|
|
+const NotificationSequence blink_sequence_normal = {
|
|
|
|
|
+ &blink_message_normal,
|
|
|
|
|
+ &message_do_not_reset,
|
|
|
|
|
+ NULL
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+NotificationMessage blink_message_error = {
|
|
|
|
|
+ .type = NotificationMessageTypeLedBlinkStart,
|
|
|
|
|
+ .data.led_blink.color = LightRed,
|
|
|
|
|
+ .data.led_blink.on_time = 10,
|
|
|
|
|
+ .data.led_blink.period = 100
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const NotificationSequence blink_sequence_error = {
|
|
|
|
|
+ &blink_message_error,
|
|
|
|
|
+ &message_do_not_reset,
|
|
|
|
|
+ NULL
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+void start_blink(NfcPlaylist* nfc_playlist, int state) {
|
|
|
|
|
+ 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) {
|
|
|
|
|
+ notification_message_block(nfc_playlist->notification, &blink_sequence_error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void stop_blink(NfcPlaylist* nfc_playlist) {
|
|
|
|
|
+ if (nfc_playlist->settings.emulate_led_indicator) {
|
|
|
|
|
+ notification_message_block(nfc_playlist->notification, &sequence_blink_stop);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|