[FL-1499] NFC App: save and load from SD card (#560)
* nfc: add save name and save success scenes * applications: increase nfc app stack size to 4k * nfc: move nfc device data to separate file * nfc: add nfc device save to SD card * nfc: add file select scene * nfc: add saved key menu scene * nfc: add manual SAK, ATQA, UID enter * nfc: add manual enter * nfc scenes: remove typedef in SubmenuIndex enu * nfc_device: close file_worker after load data Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexRunApp,
|
||||
SubmenuIndexChooseScript,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexSave,
|
||||
} SubmenuIndex;
|
||||
};
|
||||
|
||||
void nfc_scene_card_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
@@ -61,7 +61,7 @@ const bool nfc_scene_card_menu_on_event(void* context, uint32_t 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_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_save_name);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
|
@@ -5,12 +5,12 @@
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexDetect,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexReadEmv,
|
||||
SubmenuIndexReadMifareUl,
|
||||
} SubmenuIndex;
|
||||
};
|
||||
|
||||
void nfc_scene_debug_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
11
applications/nfc/scenes/nfc_scene_emulate_uid.c
Executable file → Normal file
11
applications/nfc/scenes/nfc_scene_emulate_uid.c
Executable file → Normal file
@@ -9,8 +9,11 @@ const void nfc_scene_emulate_uid_on_enter(void* context) {
|
||||
|
||||
// Setup view
|
||||
Popup* popup = nfc->popup;
|
||||
NfcDeviceData* data = &nfc->nfc_common.worker_result.nfc_detect_data;
|
||||
if(data->uid_len == 4) {
|
||||
NfcDeviceData* data = &nfc->device.data;
|
||||
|
||||
if(strcmp(nfc->device.dev_name, "")) {
|
||||
nfc_set_text_store(nfc, "%s", nfc->device.dev_name);
|
||||
} else 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) {
|
||||
@@ -31,8 +34,8 @@ const void nfc_scene_emulate_uid_on_enter(void* context) {
|
||||
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_set_emulation_params(nfc->nfc_common.worker, 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);
|
||||
|
39
applications/nfc/scenes/nfc_scene_file_select.c
Executable file
39
applications/nfc/scenes/nfc_scene_file_select.c
Executable file
@@ -0,0 +1,39 @@
|
||||
#include <nfc/scenes/nfc_scene_file_select.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
const void nfc_scene_file_select_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
// Process file_select return
|
||||
if(nfc_file_select(&nfc->device)) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_saved_menu);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
} else {
|
||||
view_dispatcher_send_back_search_scene_event(
|
||||
nfc->nfc_common.view_dispatcher, NfcSceneStart);
|
||||
}
|
||||
}
|
||||
|
||||
const bool nfc_scene_file_select_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_file_select_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_file_select_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneFileSelect;
|
||||
scene->on_enter = nfc_scene_file_select_on_enter;
|
||||
scene->on_event = nfc_scene_file_select_on_event;
|
||||
scene->on_exit = nfc_scene_file_select_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_file_select_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_file_select.h
Normal file
7
applications/nfc/scenes/nfc_scene_file_select.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_file_select_alloc();
|
||||
|
||||
void nfc_scene_file_select_free(AppScene* scene);
|
@@ -34,6 +34,7 @@ const bool nfc_scene_read_card_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == NfcEventDetect) {
|
||||
nfc->device.data = nfc->nfc_common.worker_result.nfc_detect_data;
|
||||
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);
|
||||
|
@@ -16,6 +16,9 @@ void nfc_scene_read_card_success_dialog_callback(DialogExResult result, void* co
|
||||
const void nfc_scene_read_card_success_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Clear device name
|
||||
nfc_device_set_name(&nfc->device, "");
|
||||
|
||||
// Send notification
|
||||
notification_message(nfc->notifications, &sequence_success);
|
||||
|
||||
|
72
applications/nfc/scenes/nfc_scene_save_name.c
Executable file
72
applications/nfc/scenes/nfc_scene_save_name.c
Executable file
@@ -0,0 +1,72 @@
|
||||
#include <nfc/scenes/nfc_scene_save_name.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
#include "../views/nfc_detect.h"
|
||||
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL)
|
||||
|
||||
void nfc_scene_save_name_text_input_callback(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(
|
||||
nfc->nfc_common.view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT);
|
||||
}
|
||||
|
||||
const void nfc_scene_save_name_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
TextInput* text_input = nfc->text_input;
|
||||
nfc_set_text_store(nfc, "");
|
||||
text_input_set_header_text(text_input, "Name the card");
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
nfc_scene_save_name_text_input_callback,
|
||||
nfc,
|
||||
nfc->text_store,
|
||||
sizeof(nfc->text_store));
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewTextInput);
|
||||
}
|
||||
|
||||
const bool nfc_scene_save_name_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SCENE_SAVE_NAME_CUSTOM_EVENT) {
|
||||
memcpy(&nfc->device.dev_name, nfc->text_store, strlen(nfc->text_store));
|
||||
if(nfc_device_save(&nfc->device, "test")) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_save_success);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
} else {
|
||||
view_dispatcher_send_back_search_scene_event(
|
||||
nfc->nfc_common.view_dispatcher, NfcSceneStart);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_save_name_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Clear view
|
||||
text_input_set_header_text(nfc->text_input, NULL);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_save_name_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneSaveName;
|
||||
scene->on_enter = nfc_scene_save_name_on_enter;
|
||||
scene->on_event = nfc_scene_save_name_on_event;
|
||||
scene->on_exit = nfc_scene_save_name_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_save_name_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_save_name.h
Normal file
7
applications/nfc/scenes/nfc_scene_save_name.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_save_name_alloc();
|
||||
|
||||
void nfc_scene_save_name_free(AppScene* scene);
|
66
applications/nfc/scenes/nfc_scene_save_success.c
Executable file
66
applications/nfc/scenes/nfc_scene_save_success.c
Executable file
@@ -0,0 +1,66 @@
|
||||
#include <nfc/scenes/nfc_scene_save_success.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#define SCENE_SAVE_SUCCESS_CUSTOM_EVENT (0UL)
|
||||
|
||||
void nfc_scene_save_success_popup_callback(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
view_dispatcher_send_custom_event(
|
||||
nfc->nfc_common.view_dispatcher, SCENE_SAVE_SUCCESS_CUSTOM_EVENT);
|
||||
}
|
||||
|
||||
const void nfc_scene_save_success_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_icon(popup, 32, 5, I_DolphinNice_96x59);
|
||||
popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, nfc);
|
||||
popup_set_callback(popup, nfc_scene_save_success_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
|
||||
}
|
||||
|
||||
const bool nfc_scene_save_success_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SCENE_SAVE_SUCCESS_CUSTOM_EVENT) {
|
||||
view_dispatcher_send_back_search_scene_event(
|
||||
nfc->nfc_common.view_dispatcher, NfcSceneStart);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_save_success_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// 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);
|
||||
popup_set_callback(popup, NULL);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_timeout(popup, 0);
|
||||
popup_disable_timeout(popup);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_save_success_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneSaveSuccess;
|
||||
scene->on_enter = nfc_scene_save_success_on_enter;
|
||||
scene->on_event = nfc_scene_save_success_on_event;
|
||||
scene->on_exit = nfc_scene_save_success_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_save_success_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_save_success.h
Normal file
7
applications/nfc/scenes/nfc_scene_save_success.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_save_success_alloc();
|
||||
|
||||
void nfc_scene_save_success_free(AppScene* scene);
|
83
applications/nfc/scenes/nfc_scene_saved_menu.c
Executable file
83
applications/nfc/scenes/nfc_scene_saved_menu.c
Executable file
@@ -0,0 +1,83 @@
|
||||
#include "nfc_scene_saved_menu.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexEdit,
|
||||
SubmenuIndexDelete,
|
||||
SubmenuIndexInfo,
|
||||
};
|
||||
|
||||
void nfc_scene_saved_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_saved_menu_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_saved_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Edit UID and name", SubmenuIndexEdit, nfc_scene_saved_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Delete", SubmenuIndexDelete, nfc_scene_saved_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Info", SubmenuIndexInfo, nfc_scene_saved_menu_submenu_callback, nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_saved_menu_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
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 == SubmenuIndexEdit) {
|
||||
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 == SubmenuIndexDelete) {
|
||||
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 == SubmenuIndexInfo) {
|
||||
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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_saved_menu_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_saved_menu_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneSavedMenu;
|
||||
scene->on_enter = nfc_scene_saved_menu_on_enter;
|
||||
scene->on_event = nfc_scene_saved_menu_on_event;
|
||||
scene->on_exit = nfc_scene_saved_menu_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_saved_menu_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_saved_menu.h
Normal file
7
applications/nfc/scenes/nfc_scene_saved_menu.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_saved_menu_alloc();
|
||||
|
||||
void nfc_scene_saved_menu_free(AppScene* scene);
|
61
applications/nfc/scenes/nfc_scene_set_atqa.c
Executable file
61
applications/nfc/scenes/nfc_scene_set_atqa.c
Executable file
@@ -0,0 +1,61 @@
|
||||
#include <nfc/scenes/nfc_scene_set_atqa.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#define SCENE_SET_ATQA_CUSTOM_EVENT (0UL)
|
||||
|
||||
void nfc_scene_set_atqa_byte_input_callback(void* context, uint8_t* bytes, uint8_t bytes_count) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(
|
||||
nfc->nfc_common.view_dispatcher, SCENE_SET_ATQA_CUSTOM_EVENT);
|
||||
}
|
||||
|
||||
const void nfc_scene_set_atqa_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
ByteInput* byte_input = nfc->byte_input;
|
||||
byte_input_set_header_text(byte_input, "Enter atqa in hex");
|
||||
byte_input_set_result_callback(
|
||||
byte_input, nfc_scene_set_atqa_byte_input_callback, NULL, nfc, nfc->device.data.atqa, 2);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewByteInput);
|
||||
}
|
||||
|
||||
const bool nfc_scene_set_atqa_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SCENE_SET_ATQA_CUSTOM_EVENT) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_set_uid);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_set_atqa_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Clear view
|
||||
byte_input_set_result_callback(nfc->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(nfc->byte_input, "");
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_set_atqa_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneSetAtqa;
|
||||
scene->on_enter = nfc_scene_set_atqa_on_enter;
|
||||
scene->on_event = nfc_scene_set_atqa_on_event;
|
||||
scene->on_exit = nfc_scene_set_atqa_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_set_atqa_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_set_atqa.h
Normal file
7
applications/nfc/scenes/nfc_scene_set_atqa.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_set_atqa_alloc();
|
||||
|
||||
void nfc_scene_set_atqa_free(AppScene* scene);
|
60
applications/nfc/scenes/nfc_scene_set_sak.c
Executable file
60
applications/nfc/scenes/nfc_scene_set_sak.c
Executable file
@@ -0,0 +1,60 @@
|
||||
#include <nfc/scenes/nfc_scene_set_sak.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#define SCENE_SET_SAK_CUSTOM_EVENT (0UL)
|
||||
|
||||
void nfc_scene_set_sak_byte_input_callback(void* context, uint8_t* bytes, uint8_t bytes_count) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, SCENE_SET_SAK_CUSTOM_EVENT);
|
||||
}
|
||||
|
||||
const void nfc_scene_set_sak_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
ByteInput* byte_input = nfc->byte_input;
|
||||
byte_input_set_header_text(byte_input, "Enter SAK in hex");
|
||||
byte_input_set_result_callback(
|
||||
byte_input, nfc_scene_set_sak_byte_input_callback, NULL, nfc, &nfc->device.data.sak, 1);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewByteInput);
|
||||
}
|
||||
|
||||
const bool nfc_scene_set_sak_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SCENE_SET_SAK_CUSTOM_EVENT) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_set_atqa);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_set_sak_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Clear view
|
||||
byte_input_set_result_callback(nfc->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(nfc->byte_input, "");
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_set_sak_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneSetSak;
|
||||
scene->on_enter = nfc_scene_set_sak_on_enter;
|
||||
scene->on_event = nfc_scene_set_sak_on_event;
|
||||
scene->on_exit = nfc_scene_set_sak_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_set_sak_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_set_sak.h
Normal file
7
applications/nfc/scenes/nfc_scene_set_sak.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_set_sak_alloc();
|
||||
|
||||
void nfc_scene_set_sak_free(AppScene* scene);
|
67
applications/nfc/scenes/nfc_scene_set_type.c
Executable file
67
applications/nfc/scenes/nfc_scene_set_type.c
Executable file
@@ -0,0 +1,67 @@
|
||||
#include "nfc_scene_set_type.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexNFCA4,
|
||||
SubmenuIndexNFCA7,
|
||||
};
|
||||
|
||||
void nfc_scene_set_type_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_set_type_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "NFC-A 7-bytes UID", SubmenuIndexNFCA7, nfc_scene_set_type_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "NFC-A 4-bytes UID", SubmenuIndexNFCA4, nfc_scene_set_type_submenu_callback, nfc);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_set_type_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SubmenuIndexNFCA7) {
|
||||
nfc->device.data.uid_len = 7;
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_set_sak);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexNFCA4) {
|
||||
nfc->device.data.uid_len = 4;
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_set_sak);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_set_type_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_set_type_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneSetType;
|
||||
scene->on_enter = nfc_scene_set_type_on_enter;
|
||||
scene->on_event = nfc_scene_set_type_on_event;
|
||||
scene->on_exit = nfc_scene_set_type_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_set_type_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_set_type.h
Normal file
7
applications/nfc/scenes/nfc_scene_set_type.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_set_type_alloc();
|
||||
|
||||
void nfc_scene_set_type_free(AppScene* scene);
|
65
applications/nfc/scenes/nfc_scene_set_uid.c
Executable file
65
applications/nfc/scenes/nfc_scene_set_uid.c
Executable file
@@ -0,0 +1,65 @@
|
||||
#include <nfc/scenes/nfc_scene_set_uid.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#define SCENE_SET_UID_CUSTOM_EVENT (0UL)
|
||||
|
||||
void nfc_scene_set_uid_byte_input_callback(void* context, uint8_t* bytes, uint8_t bytes_count) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, SCENE_SET_UID_CUSTOM_EVENT);
|
||||
}
|
||||
|
||||
const void nfc_scene_set_uid_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
ByteInput* byte_input = nfc->byte_input;
|
||||
byte_input_set_header_text(byte_input, "Enter uid in hex");
|
||||
byte_input_set_result_callback(
|
||||
byte_input,
|
||||
nfc_scene_set_uid_byte_input_callback,
|
||||
NULL,
|
||||
nfc,
|
||||
nfc->device.data.uid,
|
||||
nfc->device.data.uid_len);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewByteInput);
|
||||
}
|
||||
|
||||
const bool nfc_scene_set_uid_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SCENE_SET_UID_CUSTOM_EVENT) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_save_name);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_set_uid_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Clear view
|
||||
byte_input_set_result_callback(nfc->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(nfc->byte_input, "");
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_set_uid_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneSetUid;
|
||||
scene->on_enter = nfc_scene_set_uid_on_enter;
|
||||
scene->on_event = nfc_scene_set_uid_on_event;
|
||||
scene->on_exit = nfc_scene_set_uid_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_set_uid_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_set_uid.h
Normal file
7
applications/nfc/scenes/nfc_scene_set_uid.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_set_uid_alloc();
|
||||
|
||||
void nfc_scene_set_uid_free(AppScene* scene);
|
@@ -5,13 +5,13 @@
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexRead,
|
||||
SubmenuIndexRunScript,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexAddManualy,
|
||||
SubmenuIndexDebug,
|
||||
} SubmenuIndex;
|
||||
};
|
||||
|
||||
void nfc_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
@@ -34,7 +34,7 @@ const void nfc_scene_start_on_enter(void* context) {
|
||||
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 manually", 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);
|
||||
@@ -54,12 +54,12 @@ const bool nfc_scene_start_on_event(void* context, uint32_t 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_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_file_select);
|
||||
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_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_set_type);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user