[FL-1448], [FL-1529] Introducing Scene Manager, NFC App refactoring and bug fixes (#575)
* gui: refactore ViewNavigator -> SceneManager * view_dispatcher: remove scene controller, add custom and navigation cb * scene_manager: rework scene controller, move AppScene from lib * nfc: rework nfc scenes with new scene controller API * view_dispatcher: crash on free if not all views were freed * nfc: introduce scene declaration * scene_manager: allocate and configure application scenes * nfc: rework nfc with new Scene Manager API * scene_manager: remove dublicated scene handlers allocation * nfc: rework nfc app with new scene manager API * view_dispatcher: add tick event * scene_manager: add tick event type and handler * nfc: rework notifications with tick event * scene_manager: remove scene id from scene structure * scene_manager: rename array -> stack, add documentation * api-hal-nfc: remove listen activation processing * nfc_scene_start: shorter submenu call * nfc: fix nfc file name * nfc: fix Retry in mifare ul success read * nfc_cli: fix read timeout in nfc_detect CLI command Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,14 +1,38 @@
|
||||
#include "nfc_i.h"
|
||||
#include "api-hal-nfc.h"
|
||||
#include "app_scene.h"
|
||||
|
||||
bool nfc_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
return scene_manager_handle_custom_event(nfc->scene_manager, event);
|
||||
}
|
||||
|
||||
bool nfc_navigation_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
return scene_manager_handle_navigation_event(nfc->scene_manager);
|
||||
}
|
||||
|
||||
void nfc_tick_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
scene_manager_handle_tick_event(nfc->scene_manager);
|
||||
}
|
||||
|
||||
Nfc* nfc_alloc() {
|
||||
Nfc* nfc = furi_alloc(sizeof(Nfc));
|
||||
|
||||
nfc->nfc_common.worker = nfc_worker_alloc();
|
||||
nfc->nfc_common.view_dispatcher = view_dispatcher_alloc();
|
||||
nfc->scene_manager = scene_manager_alloc(&nfc_scene_handlers, nfc);
|
||||
view_dispatcher_enable_queue(nfc->nfc_common.view_dispatcher);
|
||||
view_dispatcher_enable_navigation(nfc->nfc_common.view_dispatcher, nfc);
|
||||
view_dispatcher_set_event_callback_context(nfc->nfc_common.view_dispatcher, nfc);
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
nfc->nfc_common.view_dispatcher, nfc_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
nfc->nfc_common.view_dispatcher, nfc_navigation_event_callback);
|
||||
view_dispatcher_set_tick_event_callback(
|
||||
nfc->nfc_common.view_dispatcher, nfc_tick_event_callback, 300);
|
||||
|
||||
// Open GUI record
|
||||
nfc->gui = furi_record_open("gui");
|
||||
@@ -71,32 +95,8 @@ Nfc* nfc_alloc() {
|
||||
NfcViewMifareUl,
|
||||
nfc_mifare_ul_get_view(nfc->nfc_mifare_ul));
|
||||
|
||||
// Scene allocation
|
||||
nfc->scene_start = nfc_scene_start_alloc();
|
||||
nfc->scene_read_card = nfc_scene_read_card_alloc();
|
||||
nfc->scene_read_card_success = nfc_scene_read_card_success_alloc();
|
||||
nfc->scene_card_menu = nfc_scene_card_menu_alloc();
|
||||
nfc->scene_not_implemented = nfc_scene_not_implemented_alloc();
|
||||
nfc->scene_debug_menu = nfc_scene_debug_menu_alloc();
|
||||
nfc->scene_debug_detect = nfc_scene_debug_detect_alloc();
|
||||
nfc->scene_debug_emulate = nfc_scene_debug_emulate_alloc();
|
||||
nfc->scene_debug_read_emv = nfc_scene_debug_read_emv_alloc();
|
||||
nfc->scene_debug_read_mifare_ul = nfc_scene_debug_read_mifare_ul_alloc();
|
||||
nfc->scene_emulate_uid = nfc_scene_emulate_uid_alloc();
|
||||
nfc->scene_save_name = nfc_scene_save_name_alloc();
|
||||
nfc->scene_save_success = nfc_scene_save_success_alloc();
|
||||
nfc->scene_file_select = nfc_scene_file_select_alloc();
|
||||
nfc->scene_saved_menu = nfc_scene_saved_menu_alloc();
|
||||
nfc->scene_set_type = nfc_scene_set_type_alloc();
|
||||
nfc->scene_set_sak = nfc_scene_set_sak_alloc();
|
||||
nfc->scene_set_atqa = nfc_scene_set_atqa_alloc();
|
||||
nfc->scene_set_uid = nfc_scene_set_uid_alloc();
|
||||
nfc->scene_scripts_menu = nfc_scene_scripts_menu_alloc();
|
||||
nfc->scene_read_mifare_ul = nfc_scene_read_mifare_ul_alloc();
|
||||
nfc->scene_read_mifare_ul_success = nfc_scene_read_mifare_ul_success_alloc();
|
||||
nfc->scene_mifare_ul_menu = nfc_scene_mifare_ul_menu_alloc();
|
||||
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_start);
|
||||
// Run first scene
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneStart);
|
||||
|
||||
return nfc;
|
||||
}
|
||||
@@ -149,34 +149,12 @@ void nfc_free(Nfc* nfc) {
|
||||
nfc_worker_stop(nfc->nfc_common.worker);
|
||||
nfc_worker_free(nfc->nfc_common.worker);
|
||||
|
||||
// Scenes
|
||||
nfc_scene_start_free(nfc->scene_start);
|
||||
nfc_scene_read_card_free(nfc->scene_read_card);
|
||||
nfc_scene_read_card_success_free(nfc->scene_read_card_success);
|
||||
nfc_scene_card_menu_free(nfc->scene_card_menu);
|
||||
nfc_scene_not_implemented_free(nfc->scene_not_implemented);
|
||||
nfc_scene_debug_menu_free(nfc->scene_debug_menu);
|
||||
nfc_scene_debug_detect_free(nfc->scene_debug_detect);
|
||||
nfc_scene_debug_emulate_free(nfc->scene_debug_emulate);
|
||||
nfc_scene_debug_read_emv_free(nfc->scene_debug_read_emv);
|
||||
nfc_scene_debug_read_mifare_ul_free(nfc->scene_debug_read_mifare_ul);
|
||||
nfc_scene_emulate_uid_free(nfc->scene_emulate_uid);
|
||||
nfc_scene_save_name_free(nfc->scene_save_name);
|
||||
nfc_scene_save_success_free(nfc->scene_save_success);
|
||||
nfc_scene_file_select_free(nfc->scene_file_select);
|
||||
nfc_scene_saved_menu_free(nfc->scene_saved_menu);
|
||||
nfc_scene_set_type_free(nfc->scene_set_type);
|
||||
nfc_scene_set_sak_free(nfc->scene_set_sak);
|
||||
nfc_scene_set_atqa_free(nfc->scene_set_atqa);
|
||||
nfc_scene_set_uid_free(nfc->scene_set_uid);
|
||||
nfc_scene_scripts_menu_free(nfc->scene_scripts_menu);
|
||||
nfc_scene_read_mifare_ul_free(nfc->scene_read_mifare_ul);
|
||||
nfc_scene_read_mifare_ul_success_free(nfc->scene_read_mifare_ul_success);
|
||||
nfc_scene_mifare_ul_menu_free(nfc->scene_mifare_ul_menu);
|
||||
|
||||
// View Dispatcher
|
||||
view_dispatcher_free(nfc->nfc_common.view_dispatcher);
|
||||
|
||||
// Scene Manager
|
||||
scene_manager_free(nfc->scene_manager);
|
||||
|
||||
// GUI
|
||||
furi_record_close("gui");
|
||||
nfc->gui = NULL;
|
||||
@@ -198,7 +176,7 @@ int32_t nfc_task(void* p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nfc_set_text_store(Nfc* nfc, const char* text, ...) {
|
||||
void nfc_text_store_set(Nfc* nfc, const char* text, ...) {
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
|
||||
@@ -206,3 +184,7 @@ void nfc_set_text_store(Nfc* nfc, const char* text, ...) {
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void nfc_text_store_clear(Nfc* nfc) {
|
||||
memset(nfc->text_store, 0, sizeof(nfc->text_store));
|
||||
}
|
||||
|
Reference in New Issue
Block a user