From 71378246df1cd2ede705e921120363c536cd61e6 Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 15:53:47 +0300 Subject: [PATCH 1/9] Field scene added --- .../main/nfc/scenes/nfc_scene_config.h | 1 + .../main/nfc/scenes/nfc_scene_field.c | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 applications/main/nfc/scenes/nfc_scene_field.c diff --git a/applications/main/nfc/scenes/nfc_scene_config.h b/applications/main/nfc/scenes/nfc_scene_config.h index c3e7d44993b6..1642aee6d1a8 100644 --- a/applications/main/nfc/scenes/nfc_scene_config.h +++ b/applications/main/nfc/scenes/nfc_scene_config.h @@ -16,6 +16,7 @@ ADD_SCENE(nfc, read_success, ReadSuccess) ADD_SCENE(nfc, read_menu, ReadMenu) ADD_SCENE(nfc, emulate, Emulate) ADD_SCENE(nfc, debug, Debug) +ADD_SCENE(nfc, field, Field) ADD_SCENE(nfc, retry_confirm, RetryConfirm) ADD_SCENE(nfc, exit_confirm, ExitConfirm) ADD_SCENE(nfc, card_dump, CardDump) diff --git a/applications/main/nfc/scenes/nfc_scene_field.c b/applications/main/nfc/scenes/nfc_scene_field.c new file mode 100644 index 000000000000..bd7f3a75cde1 --- /dev/null +++ b/applications/main/nfc/scenes/nfc_scene_field.c @@ -0,0 +1,33 @@ +#include "../nfc_app_i.h" + +void nfc_scene_field_on_enter(void* context) { + NfcApp* nfc = context; + + f_hal_nfc_low_power_mode_stop(); + f_hal_nfc_poller_field_on(); + Popup* popup = nfc->popup; + popup_set_header( + popup, + "Field is on\nDon't leave device\nin this mode for too long.", + 64, + 11, + AlignCenter, + AlignTop); + view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup); + + notification_internal_message(nfc->notifications, &sequence_set_blue_255); +} + +bool nfc_scene_field_on_event(void* context, SceneManagerEvent event) { + UNUSED(context); + UNUSED(event); + return false; +} + +void nfc_scene_field_on_exit(void* context) { + NfcApp* nfc = context; + + f_hal_nfc_low_power_mode_start(); + notification_internal_message(nfc->notifications, &sequence_reset_blue); + popup_reset(nfc->popup); +} From f73938783d86436b85b15ca88949ab7bd209a149 Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 15:57:10 +0300 Subject: [PATCH 2/9] Moved 'Debug' scene implementation into protocol support layer --- .../protocol_support/nfc_protocol_support.c | 38 +++++++++++++++ .../nfc_protocol_support_common.h | 1 + .../main/nfc/scenes/nfc_scene_debug.c | 48 ++----------------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c index 7ceeeee62f29..9fcdbbbf38c8 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c @@ -99,6 +99,38 @@ static void nfc_protocol_support_scene_card_dump_on_exit(NfcApp* instance) { furi_string_reset(instance->text_box_store); } +static void nfc_protocol_support_scene_debug_on_enter(NfcApp* instance) { + Submenu* submenu = instance->submenu; + + submenu_add_item( + submenu, + "Field", + SubmenuIndexCommonField, + nfc_protocol_support_common_submenu_callback, + instance); + + view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewMenu); +} + +static bool nfc_protocol_support_scene_debug_on_event(NfcApp* instance, SceneManagerEvent event) { + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubmenuIndexCommonField) { + scene_manager_set_scene_state( + instance->scene_manager, NfcSceneDebug, SubmenuIndexCommonField); + scene_manager_next_scene(instance->scene_manager, NfcSceneField); + consumed = true; + } + } + return consumed; +} + +static void nfc_protocol_support_scene_debug_on_exit(NfcApp* instance) { + Submenu* submenu = instance->submenu; + submenu_reset(submenu); +} + // SceneRead static void nfc_protocol_support_scene_read_on_enter(NfcApp* instance) { popup_set_header( @@ -513,6 +545,12 @@ static const NfcProtocolSupportCommonSceneBase .on_event = nfc_protocol_support_scene_card_dump_on_event, .on_exit = nfc_protocol_support_scene_card_dump_on_exit, }, + [NfcProtocolSupportSceneDebug] = + { + .on_enter = nfc_protocol_support_scene_debug_on_enter, + .on_event = nfc_protocol_support_scene_debug_on_event, + .on_exit = nfc_protocol_support_scene_debug_on_exit, + }, [NfcProtocolSupportSceneRead] = { .on_enter = nfc_protocol_support_scene_read_on_enter, diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h index 50fb3cbde763..6522c00dfe31 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h @@ -24,6 +24,7 @@ typedef enum { NfcProtocolSupportSceneSavedMenu, NfcProtocolSupportSceneEmulate, NfcProtocolSupportSceneCardDump, + NfcProtocolSupportSceneDebug, NfcProtocolSupportSceneCount, } NfcProtocolSupportScene; diff --git a/applications/main/nfc/scenes/nfc_scene_debug.c b/applications/main/nfc/scenes/nfc_scene_debug.c index 85bc901a3429..ccffe95927e6 100644 --- a/applications/main/nfc/scenes/nfc_scene_debug.c +++ b/applications/main/nfc/scenes/nfc_scene_debug.c @@ -1,53 +1,13 @@ -#include "../nfc_app_i.h" - -enum SubmenuDebugIndex { - SubmenuDebugIndexField, - SubmenuDebugIndexApdu, -}; - -void nfc_scene_debug_submenu_callback(void* context, uint32_t index) { - NfcApp* nfc = context; - - view_dispatcher_send_custom_event(nfc->view_dispatcher, index); -} +#include "../helpers/protocol_support/nfc_protocol_support.h" void nfc_scene_debug_on_enter(void* context) { - NfcApp* nfc = context; - Submenu* submenu = nfc->submenu; - - submenu_add_item( - submenu, "Field", SubmenuDebugIndexField, nfc_scene_debug_submenu_callback, nfc); - submenu_add_item( - submenu, "Apdu", SubmenuDebugIndexApdu, nfc_scene_debug_submenu_callback, nfc); - - submenu_set_selected_item( - submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneDebug)); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); + nfc_protocol_support_on_enter(NfcProtocolSupportSceneDebug, context); } bool nfc_scene_debug_on_event(void* context, SceneManagerEvent event) { - NfcApp* nfc = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuDebugIndexField) { - scene_manager_set_scene_state( - nfc->scene_manager, NfcSceneDebug, SubmenuDebugIndexField); - scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); - consumed = true; - } else if(event.event == SubmenuDebugIndexApdu) { - scene_manager_set_scene_state( - nfc->scene_manager, NfcSceneDebug, SubmenuDebugIndexApdu); - scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); - consumed = true; - } - } - return consumed; + return nfc_protocol_support_on_event(NfcProtocolSupportSceneDebug, context, event); } void nfc_scene_debug_on_exit(void* context) { - NfcApp* nfc = context; - - submenu_reset(nfc->submenu); + nfc_protocol_support_on_exit(NfcProtocolSupportSceneDebug, context); } From ab73494a998b06e3514d5164aa458f622fafbfa7 Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 15:58:23 +0300 Subject: [PATCH 3/9] Menu index for Field item added --- .../helpers/protocol_support/nfc_protocol_support_gui_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h index 0f1532bd30d5..134ec799460e 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h @@ -12,6 +12,7 @@ enum { SubmenuIndexCommonRename, SubmenuIndexCommonDelete, SubmenuIndexCommonMax, + SubmenuIndexCommonField }; void nfc_protocol_support_common_submenu_callback(void* context, uint32_t index); From b45961f4509b05523d0d8f6fc578c59663301add Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 15:59:39 +0300 Subject: [PATCH 4/9] Set proper scene and submenu index for 'Debug' button --- applications/main/nfc/scenes/nfc_scene_start.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/applications/main/nfc/scenes/nfc_scene_start.c b/applications/main/nfc/scenes/nfc_scene_start.c index 771e9682e084..88034682237d 100644 --- a/applications/main/nfc/scenes/nfc_scene_start.c +++ b/applications/main/nfc/scenes/nfc_scene_start.c @@ -76,9 +76,8 @@ bool nfc_scene_start_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(nfc->scene_manager, NfcSceneSetType); consumed = true; } else if(event.event == SubmenuIndexDebug) { - scene_manager_set_scene_state( - nfc->scene_manager, NfcSceneStart, NfcSceneNotImplemented); - scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); + scene_manager_set_scene_state(nfc->scene_manager, NfcSceneStart, SubmenuIndexDebug); + scene_manager_next_scene(nfc->scene_manager, NfcSceneDebug); consumed = true; } } From 7acbf25ef6ed8cbe6b59e2366cbe1a52ab5c5113 Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 16:06:07 +0300 Subject: [PATCH 5/9] Fixed issue when returning from 'Add Manually' screen Previously wrong menu item ('Read') was selected when returning from 'Add Manually', now it returns back properly --- applications/main/nfc/scenes/nfc_scene_start.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/main/nfc/scenes/nfc_scene_start.c b/applications/main/nfc/scenes/nfc_scene_start.c index 88034682237d..e03e5e31ada4 100644 --- a/applications/main/nfc/scenes/nfc_scene_start.c +++ b/applications/main/nfc/scenes/nfc_scene_start.c @@ -72,7 +72,8 @@ bool nfc_scene_start_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(nfc->scene_manager, NfcSceneExtraActions); consumed = true; } else if(event.event == SubmenuIndexAddManually) { - scene_manager_set_scene_state(nfc->scene_manager, NfcSceneStart, NfcSceneSetType); + scene_manager_set_scene_state( + nfc->scene_manager, NfcSceneStart, SubmenuIndexAddManually); scene_manager_next_scene(nfc->scene_manager, NfcSceneSetType); consumed = true; } else if(event.event == SubmenuIndexDebug) { From 6b8380ecf81837bb5328291b4d129c8e5e0e30ad Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 16:44:02 +0300 Subject: [PATCH 6/9] Revert "Moved 'Debug' scene implementation into protocol support layer" This reverts commit f73938783d86436b85b15ca88949ab7bd209a149. --- .../protocol_support/nfc_protocol_support.c | 38 --------------- .../nfc_protocol_support_common.h | 1 - .../main/nfc/scenes/nfc_scene_debug.c | 48 +++++++++++++++++-- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c index 9fcdbbbf38c8..7ceeeee62f29 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c @@ -99,38 +99,6 @@ static void nfc_protocol_support_scene_card_dump_on_exit(NfcApp* instance) { furi_string_reset(instance->text_box_store); } -static void nfc_protocol_support_scene_debug_on_enter(NfcApp* instance) { - Submenu* submenu = instance->submenu; - - submenu_add_item( - submenu, - "Field", - SubmenuIndexCommonField, - nfc_protocol_support_common_submenu_callback, - instance); - - view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewMenu); -} - -static bool nfc_protocol_support_scene_debug_on_event(NfcApp* instance, SceneManagerEvent event) { - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexCommonField) { - scene_manager_set_scene_state( - instance->scene_manager, NfcSceneDebug, SubmenuIndexCommonField); - scene_manager_next_scene(instance->scene_manager, NfcSceneField); - consumed = true; - } - } - return consumed; -} - -static void nfc_protocol_support_scene_debug_on_exit(NfcApp* instance) { - Submenu* submenu = instance->submenu; - submenu_reset(submenu); -} - // SceneRead static void nfc_protocol_support_scene_read_on_enter(NfcApp* instance) { popup_set_header( @@ -545,12 +513,6 @@ static const NfcProtocolSupportCommonSceneBase .on_event = nfc_protocol_support_scene_card_dump_on_event, .on_exit = nfc_protocol_support_scene_card_dump_on_exit, }, - [NfcProtocolSupportSceneDebug] = - { - .on_enter = nfc_protocol_support_scene_debug_on_enter, - .on_event = nfc_protocol_support_scene_debug_on_event, - .on_exit = nfc_protocol_support_scene_debug_on_exit, - }, [NfcProtocolSupportSceneRead] = { .on_enter = nfc_protocol_support_scene_read_on_enter, diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h index 6522c00dfe31..50fb3cbde763 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_common.h @@ -24,7 +24,6 @@ typedef enum { NfcProtocolSupportSceneSavedMenu, NfcProtocolSupportSceneEmulate, NfcProtocolSupportSceneCardDump, - NfcProtocolSupportSceneDebug, NfcProtocolSupportSceneCount, } NfcProtocolSupportScene; diff --git a/applications/main/nfc/scenes/nfc_scene_debug.c b/applications/main/nfc/scenes/nfc_scene_debug.c index ccffe95927e6..85bc901a3429 100644 --- a/applications/main/nfc/scenes/nfc_scene_debug.c +++ b/applications/main/nfc/scenes/nfc_scene_debug.c @@ -1,13 +1,53 @@ -#include "../helpers/protocol_support/nfc_protocol_support.h" +#include "../nfc_app_i.h" + +enum SubmenuDebugIndex { + SubmenuDebugIndexField, + SubmenuDebugIndexApdu, +}; + +void nfc_scene_debug_submenu_callback(void* context, uint32_t index) { + NfcApp* nfc = context; + + view_dispatcher_send_custom_event(nfc->view_dispatcher, index); +} void nfc_scene_debug_on_enter(void* context) { - nfc_protocol_support_on_enter(NfcProtocolSupportSceneDebug, context); + NfcApp* nfc = context; + Submenu* submenu = nfc->submenu; + + submenu_add_item( + submenu, "Field", SubmenuDebugIndexField, nfc_scene_debug_submenu_callback, nfc); + submenu_add_item( + submenu, "Apdu", SubmenuDebugIndexApdu, nfc_scene_debug_submenu_callback, nfc); + + submenu_set_selected_item( + submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneDebug)); + + view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); } bool nfc_scene_debug_on_event(void* context, SceneManagerEvent event) { - return nfc_protocol_support_on_event(NfcProtocolSupportSceneDebug, context, event); + NfcApp* nfc = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubmenuDebugIndexField) { + scene_manager_set_scene_state( + nfc->scene_manager, NfcSceneDebug, SubmenuDebugIndexField); + scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); + consumed = true; + } else if(event.event == SubmenuDebugIndexApdu) { + scene_manager_set_scene_state( + nfc->scene_manager, NfcSceneDebug, SubmenuDebugIndexApdu); + scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); + consumed = true; + } + } + return consumed; } void nfc_scene_debug_on_exit(void* context) { - nfc_protocol_support_on_exit(NfcProtocolSupportSceneDebug, context); + NfcApp* nfc = context; + + submenu_reset(nfc->submenu); } From 436f80ee6b691d2ce70729763974956e64291c29 Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 16:52:08 +0300 Subject: [PATCH 7/9] Removed 'Adu' menu item --- applications/main/nfc/scenes/nfc_scene_debug.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/applications/main/nfc/scenes/nfc_scene_debug.c b/applications/main/nfc/scenes/nfc_scene_debug.c index 85bc901a3429..b29ed3484a87 100644 --- a/applications/main/nfc/scenes/nfc_scene_debug.c +++ b/applications/main/nfc/scenes/nfc_scene_debug.c @@ -17,8 +17,6 @@ void nfc_scene_debug_on_enter(void* context) { submenu_add_item( submenu, "Field", SubmenuDebugIndexField, nfc_scene_debug_submenu_callback, nfc); - submenu_add_item( - submenu, "Apdu", SubmenuDebugIndexApdu, nfc_scene_debug_submenu_callback, nfc); submenu_set_selected_item( submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneDebug)); @@ -36,11 +34,6 @@ bool nfc_scene_debug_on_event(void* context, SceneManagerEvent event) { nfc->scene_manager, NfcSceneDebug, SubmenuDebugIndexField); scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); consumed = true; - } else if(event.event == SubmenuDebugIndexApdu) { - scene_manager_set_scene_state( - nfc->scene_manager, NfcSceneDebug, SubmenuDebugIndexApdu); - scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); - consumed = true; } } return consumed; From ffa280b60660c931adfa373d0c4bffd73686ce2f Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 16:52:48 +0300 Subject: [PATCH 8/9] 'Field' button now points to a proper scene --- applications/main/nfc/scenes/nfc_scene_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/main/nfc/scenes/nfc_scene_debug.c b/applications/main/nfc/scenes/nfc_scene_debug.c index b29ed3484a87..97592f2e270e 100644 --- a/applications/main/nfc/scenes/nfc_scene_debug.c +++ b/applications/main/nfc/scenes/nfc_scene_debug.c @@ -32,7 +32,7 @@ bool nfc_scene_debug_on_event(void* context, SceneManagerEvent event) { if(event.event == SubmenuDebugIndexField) { scene_manager_set_scene_state( nfc->scene_manager, NfcSceneDebug, SubmenuDebugIndexField); - scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); + scene_manager_next_scene(nfc->scene_manager, NfcSceneField); consumed = true; } } From ee1e73137bd0c03bcccfa7e05a2713e698665890 Mon Sep 17 00:00:00 2001 From: RebornedBrain Date: Mon, 24 Jul 2023 16:53:43 +0300 Subject: [PATCH 9/9] Revert "Menu index for Field item added" This reverts commit ab73494a998b06e3514d5164aa458f622fafbfa7. --- .../helpers/protocol_support/nfc_protocol_support_gui_common.h | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h index 134ec799460e..0f1532bd30d5 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_gui_common.h @@ -12,7 +12,6 @@ enum { SubmenuIndexCommonRename, SubmenuIndexCommonDelete, SubmenuIndexCommonMax, - SubmenuIndexCommonField }; void nfc_protocol_support_common_submenu_callback(void* context, uint32_t index);