[FL-1479] New NFC app (#544)
* view: add custom event callback * nfc: rework nfc worker * gui: introduce view navigator * nfc_scences: introduce nfc scenes * nfc: add start scene * lib: add C application scene template * nfc: move nfc views to separate directory * view_dispatcher: add support for view_navigator * nfc views: rework nfc views * nfc scenes: add nfc application scenes * nfc: rework nfc main thread * view_dispatcher: add separate event for search back scene * nfc: set worker result address at worker start * nfc: update read nfc scenes * view_navigator: rework with M-LIB container * view_dispatcher: check that all views were freed * nfc: add debug menu with all functions * nfc read scene: add notification on success * api-hal-nfc: add API for UID emulation * nfc: add nfc emulation UID scene * assets: add NFC assets * nfc: update read and emulate scenes UI * nfc: fix memory leak * rfal: set custom analog configuration
This commit is contained in:
95
applications/nfc/scenes/nfc_scene_card_menu.c
Executable file
95
applications/nfc/scenes/nfc_scene_card_menu.c
Executable file
@@ -0,0 +1,95 @@
|
||||
#include "nfc_scene_card_menu.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexRunApp,
|
||||
SubmenuIndexChooseScript,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexSave,
|
||||
} SubmenuIndex;
|
||||
|
||||
void nfc_scene_card_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, index);
|
||||
}
|
||||
|
||||
const void nfc_scene_card_menu_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Run compatible app",
|
||||
SubmenuIndexRunApp,
|
||||
nfc_scene_card_menu_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Additional reading scripts",
|
||||
SubmenuIndexChooseScript,
|
||||
nfc_scene_card_menu_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Emulate UID", SubmenuIndexEmulate, nfc_scene_card_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Name and save UID", SubmenuIndexSave, nfc_scene_card_menu_submenu_callback, nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_card_menu_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SubmenuIndexRunApp) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexChooseScript) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexEmulate) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_emulate_uid);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexSave) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == ViewNavigatorEventBack) {
|
||||
view_dispatcher_send_back_search_scene_event(
|
||||
nfc->nfc_common.view_dispatcher, NfcSceneStart);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_card_menu_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_card_menu_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneCardMenu;
|
||||
scene->on_enter = nfc_scene_card_menu_on_enter;
|
||||
scene->on_event = nfc_scene_card_menu_on_event;
|
||||
scene->on_exit = nfc_scene_card_menu_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_card_menu_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_card_menu.h
Normal file
7
applications/nfc/scenes/nfc_scene_card_menu.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_card_menu_alloc();
|
||||
|
||||
void nfc_scene_card_menu_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_detect.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_detect.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_detect.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_detect_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewDetect);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_detect_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_detect_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_detect_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugDetect;
|
||||
scene->on_enter = nfc_scene_debug_detect_on_enter;
|
||||
scene->on_event = nfc_scene_debug_detect_on_event;
|
||||
scene->on_exit = nfc_scene_debug_detect_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_detect_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_detect.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_detect.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_detect_alloc();
|
||||
|
||||
void nfc_scene_debug_detect_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_emulate.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_emulate.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_emulate.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_emulate_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewEmulate);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_emulate_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_emulate_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_emulate_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugEmulate;
|
||||
scene->on_enter = nfc_scene_debug_emulate_on_enter;
|
||||
scene->on_event = nfc_scene_debug_emulate_on_event;
|
||||
scene->on_exit = nfc_scene_debug_emulate_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_emulate_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_emulate.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_emulate.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_emulate_alloc();
|
||||
|
||||
void nfc_scene_debug_emulate_free(AppScene* scene);
|
88
applications/nfc/scenes/nfc_scene_debug_menu.c
Executable file
88
applications/nfc/scenes/nfc_scene_debug_menu.c
Executable file
@@ -0,0 +1,88 @@
|
||||
#include "nfc_scene_debug_menu.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexDetect,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexReadEmv,
|
||||
SubmenuIndexReadMifareUl,
|
||||
} SubmenuIndex;
|
||||
|
||||
void nfc_scene_debug_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, index);
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_menu_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Detect", SubmenuIndexDetect, nfc_scene_debug_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_debug_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Read EMV", SubmenuIndexReadEmv, nfc_scene_debug_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Read Mifare Ultralight",
|
||||
SubmenuIndexReadMifareUl,
|
||||
nfc_scene_debug_menu_submenu_callback,
|
||||
nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_menu_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SubmenuIndexDetect) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_detect);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexEmulate) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_emulate);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexReadEmv) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_read_emv);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexReadMifareUl) {
|
||||
view_dispatcher_add_scene(
|
||||
nfc->nfc_common.view_dispatcher, nfc->scene_debug_read_mifare_ul);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_menu_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_menu_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugMenu;
|
||||
scene->on_enter = nfc_scene_debug_menu_on_enter;
|
||||
scene->on_event = nfc_scene_debug_menu_on_event;
|
||||
scene->on_exit = nfc_scene_debug_menu_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_menu_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_menu.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_menu.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_menu_alloc();
|
||||
|
||||
void nfc_scene_debug_menu_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_read_emv.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_read_emv.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_read_emv.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_read_emv_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewEmv);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_read_emv_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_read_emv_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_read_emv_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugReadEmv;
|
||||
scene->on_enter = nfc_scene_debug_read_emv_on_enter;
|
||||
scene->on_event = nfc_scene_debug_read_emv_on_event;
|
||||
scene->on_exit = nfc_scene_debug_read_emv_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_read_emv_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_read_emv.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_read_emv.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_read_emv_alloc();
|
||||
|
||||
void nfc_scene_debug_read_emv_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_read_mifare_ul.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_read_mifare_ul_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMifareUl);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_read_mifare_ul_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_read_mifare_ul_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_read_mifare_ul_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugReadMifareUl;
|
||||
scene->on_enter = nfc_scene_debug_read_mifare_ul_on_enter;
|
||||
scene->on_event = nfc_scene_debug_read_mifare_ul_on_event;
|
||||
scene->on_exit = nfc_scene_debug_read_mifare_ul_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_read_mifare_ul_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_read_mifare_ul_alloc();
|
||||
|
||||
void nfc_scene_debug_read_mifare_ul_free(AppScene* scene);
|
70
applications/nfc/scenes/nfc_scene_emulate_uid.c
Executable file
70
applications/nfc/scenes/nfc_scene_emulate_uid.c
Executable file
@@ -0,0 +1,70 @@
|
||||
#include <nfc/scenes/nfc_scene_emulate_uid.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
const void nfc_scene_emulate_uid_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = nfc->popup;
|
||||
NfcDeviceData* data = &nfc->nfc_common.worker_result.nfc_detect_data;
|
||||
if(data->uid_len == 4) {
|
||||
nfc_set_text_store(
|
||||
nfc, "%02X %02X %02X %02X", data->uid[0], data->uid[1], data->uid[2], data->uid[3]);
|
||||
} else if(data->uid_len == 7) {
|
||||
nfc_set_text_store(
|
||||
nfc,
|
||||
"%02X %02X %02X %02X\n%02X %02X %02X",
|
||||
data->uid[0],
|
||||
data->uid[1],
|
||||
data->uid[2],
|
||||
data->uid[3],
|
||||
data->uid[4],
|
||||
data->uid[5],
|
||||
data->uid[6]);
|
||||
}
|
||||
|
||||
popup_set_icon(popup, 0, 4, I_RFIDDolphinSend_98x60);
|
||||
popup_set_header(popup, "Emulating UID", 56, 31, AlignLeft, AlignTop);
|
||||
popup_set_text(popup, nfc->text_store, 56, 43, AlignLeft, AlignTop);
|
||||
|
||||
// Setup and start worker
|
||||
nfc_worker_set_emulation_params(
|
||||
nfc->nfc_common.worker, &nfc->nfc_common.worker_result.nfc_detect_data);
|
||||
nfc_worker_start(
|
||||
nfc->nfc_common.worker, NfcWorkerStateEmulate, &nfc->nfc_common.worker_result, NULL, nfc);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
|
||||
}
|
||||
|
||||
const bool nfc_scene_emulate_uid_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_emulate_uid_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Stop worker
|
||||
nfc_worker_stop(nfc->nfc_common.worker);
|
||||
|
||||
// Clear view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, I_Empty_1x1);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_emulate_uid_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneEmulateUID;
|
||||
scene->on_enter = nfc_scene_emulate_uid_on_enter;
|
||||
scene->on_event = nfc_scene_emulate_uid_on_event;
|
||||
scene->on_exit = nfc_scene_emulate_uid_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_emulate_uid_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_emulate_uid.h
Normal file
7
applications/nfc/scenes/nfc_scene_emulate_uid.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_emulate_uid_alloc();
|
||||
|
||||
void nfc_scene_emulate_uid_free(AppScene* scene);
|
61
applications/nfc/scenes/nfc_scene_not_implemented.c
Normal file
61
applications/nfc/scenes/nfc_scene_not_implemented.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "nfc_scene_not_implemented.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
void nfc_scene_not_implemented_dialog_callback(DialogExResult result, void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, result);
|
||||
}
|
||||
|
||||
const void nfc_scene_not_implemented_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// TODO Set data from worker
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_header(dialog_ex, "Not implemented", 60, 24, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_context(dialog_ex, nfc);
|
||||
dialog_ex_set_result_callback(dialog_ex, nfc_scene_not_implemented_dialog_callback);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewDialogEx);
|
||||
}
|
||||
|
||||
const bool nfc_scene_not_implemented_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == DialogExResultLeft) {
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventBack);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_not_implemented_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_not_implemented_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneReadCardSuccess;
|
||||
scene->on_enter = nfc_scene_not_implemented_on_enter;
|
||||
scene->on_event = nfc_scene_not_implemented_on_event;
|
||||
scene->on_exit = nfc_scene_not_implemented_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_not_implemented_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_not_implemented.h
Normal file
7
applications/nfc/scenes/nfc_scene_not_implemented.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_not_implemented_alloc();
|
||||
|
||||
void nfc_scene_not_implemented_free(AppScene* scene);
|
70
applications/nfc/scenes/nfc_scene_read_card.c
Executable file
70
applications/nfc/scenes/nfc_scene_read_card.c
Executable file
@@ -0,0 +1,70 @@
|
||||
#include <nfc/scenes/nfc_scene_read_card.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
#include "../views/nfc_detect.h"
|
||||
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
void nfc_read_card_worker_callback(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, NfcEventDetect);
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_header(popup, "Detecting\nNFC card", 70, 34, AlignLeft, AlignTop);
|
||||
popup_set_icon(popup, 0, 4, I_RFIDDolphinReceive_98x60);
|
||||
|
||||
// Start worker
|
||||
nfc_worker_start(
|
||||
nfc->nfc_common.worker,
|
||||
NfcWorkerStateDetect,
|
||||
&nfc->nfc_common.worker_result,
|
||||
nfc_read_card_worker_callback,
|
||||
nfc);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
|
||||
}
|
||||
|
||||
const bool nfc_scene_read_card_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == NfcEventDetect) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_read_card_success);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Stop worker
|
||||
nfc_worker_stop(nfc->nfc_common.worker);
|
||||
|
||||
// Clear view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, I_Empty_1x1);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_read_card_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneReadCard;
|
||||
scene->on_enter = nfc_scene_read_card_on_enter;
|
||||
scene->on_event = nfc_scene_read_card_on_event;
|
||||
scene->on_exit = nfc_scene_read_card_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_read_card_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_read_card.h
Normal file
7
applications/nfc/scenes/nfc_scene_read_card.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_read_card_alloc();
|
||||
|
||||
void nfc_scene_read_card_free(AppScene* scene);
|
109
applications/nfc/scenes/nfc_scene_read_card_success.c
Executable file
109
applications/nfc/scenes/nfc_scene_read_card_success.c
Executable file
@@ -0,0 +1,109 @@
|
||||
#include "nfc_scene_read_card_success.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#define NFC_SCENE_READ_SUCCESS_SHIFT " "
|
||||
|
||||
void nfc_scene_read_card_success_dialog_callback(DialogExResult result, void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, result);
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_success_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Send notification
|
||||
notification_message(nfc->notifications, &sequence_success);
|
||||
|
||||
// Setup view
|
||||
NfcDeviceData* data = (NfcDeviceData*)&nfc->nfc_common.worker_result;
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_header(dialog_ex, nfc_get_dev_type(data->device), 36, 8, AlignLeft, AlignCenter);
|
||||
dialog_ex_set_icon(dialog_ex, 8, 13, I_Medium_chip_22x21);
|
||||
// Display UID
|
||||
if(data->uid_len == 4) {
|
||||
nfc_set_text_store(
|
||||
nfc,
|
||||
NFC_SCENE_READ_SUCCESS_SHIFT "%s\n" NFC_SCENE_READ_SUCCESS_SHIFT
|
||||
"ATQA: %02X%02X SAK: %02X\nUID: %02X %02X %02X %02X",
|
||||
nfc_get_protocol(data->protocol),
|
||||
data->atqa[0],
|
||||
data->atqa[1],
|
||||
data->sak,
|
||||
data->uid[0],
|
||||
data->uid[1],
|
||||
data->uid[2],
|
||||
data->uid[3]);
|
||||
} else if(data->uid_len == 7) {
|
||||
nfc_set_text_store(
|
||||
nfc,
|
||||
NFC_SCENE_READ_SUCCESS_SHIFT
|
||||
"%s\n" NFC_SCENE_READ_SUCCESS_SHIFT
|
||||
"ATQA: %02X%02X SAK: %02X\nUID: %02X %02X %02X %02X %02X %02X %02X",
|
||||
nfc_get_protocol(data->protocol),
|
||||
data->atqa[0],
|
||||
data->atqa[1],
|
||||
data->sak,
|
||||
data->uid[0],
|
||||
data->uid[1],
|
||||
data->uid[2],
|
||||
data->uid[3],
|
||||
data->uid[4],
|
||||
data->uid[5],
|
||||
data->uid[6]);
|
||||
}
|
||||
dialog_ex_set_text(dialog_ex, nfc->text_store, 8, 16, AlignLeft, AlignTop);
|
||||
dialog_ex_set_context(dialog_ex, nfc);
|
||||
dialog_ex_set_result_callback(dialog_ex, nfc_scene_read_card_success_dialog_callback);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewDialogEx);
|
||||
}
|
||||
|
||||
const bool nfc_scene_read_card_success_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == DialogExResultLeft) {
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventBack);
|
||||
return true;
|
||||
} else if(event == DialogExResultRight) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_card_menu);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_success_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_icon(dialog_ex, 0, 0, I_Empty_1x1);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_right_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_read_card_success_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneReadCardSuccess;
|
||||
scene->on_enter = nfc_scene_read_card_success_on_enter;
|
||||
scene->on_event = nfc_scene_read_card_success_on_event;
|
||||
scene->on_exit = nfc_scene_read_card_success_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_read_card_success_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_read_card_success.h
Normal file
7
applications/nfc/scenes/nfc_scene_read_card_success.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_read_card_success_alloc();
|
||||
|
||||
void nfc_scene_read_card_success_free(AppScene* scene);
|
92
applications/nfc/scenes/nfc_scene_start.c
Normal file
92
applications/nfc/scenes/nfc_scene_start.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "nfc_scene_start.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexRead,
|
||||
SubmenuIndexRunScript,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexAddManualy,
|
||||
SubmenuIndexDebug,
|
||||
} SubmenuIndex;
|
||||
|
||||
void nfc_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, index);
|
||||
}
|
||||
|
||||
const void nfc_scene_start_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Read card", SubmenuIndexRead, nfc_scene_start_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Run special action",
|
||||
SubmenuIndexRunScript,
|
||||
nfc_scene_start_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Saved cards", SubmenuIndexSaved, nfc_scene_start_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Add manualy", SubmenuIndexAddManualy, nfc_scene_start_submenu_callback, nfc);
|
||||
submenu_add_item(submenu, "Debug", SubmenuIndexDebug, nfc_scene_start_submenu_callback, nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_start_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SubmenuIndexRead) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_read_card);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexRunScript) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexSaved) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexAddManualy) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexDebug) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_menu);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_start_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_start_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneStart;
|
||||
scene->on_enter = nfc_scene_start_on_enter;
|
||||
scene->on_event = nfc_scene_start_on_event;
|
||||
scene->on_exit = nfc_scene_start_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_start_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_start.h
Normal file
7
applications/nfc/scenes/nfc_scene_start.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_start_alloc();
|
||||
|
||||
void nfc_scene_start_free(AppScene* scene);
|
Reference in New Issue
Block a user