flipperzero-firmware/applications/nfc/scenes/nfc_scene_delete.c
gornekich 49af516ec7
[FL-1547], [FL-1500] NFC app v1 (#593)
* nfc: remove mifare read debug view and scene
* nfc: change mifare ultralight data structure
* mifare_ultralight: add more commands
* nfc: add emulate mifare ul scene
* nfc: rework data structures, remove debug scenes and views
* nfc: add read emv scenes
* nfc: mifare emulation wip
* nfc cli: increase detecting time
* nfc: save nfc files with new format
* nfc: store Mifare Ultralight
* nfc: start loading mifare ultralight
* nfc: add delete scenes
* nfc: add edit UID and name
* nfc: finish parsing uid and mifare ul data
* nfc: delete success fix
* gui_widget: introduce GuiWidget
* gui_widget: add string element
* gui_widget: add button element
* gui_widget: move free elements into gui_widget
* nfc: rework info scene with GuiWidget
* nfc: rework device info scene
* nfc: rework delete scene gui
* nfc: add compatible script support
* nfc: rework emv reading scenes
* nfc: rework bank card save
* nfc: add bank card custom view
* gui_widget: add icon element
* nfc: add icon to bank card
* nfc: start worker after switching view

Co-authored-by: あく <alleteam@gmail.com>
2021-07-22 09:05:07 +03:00

96 lines
3.2 KiB
C

#include "../nfc_i.h"
void nfc_scene_delete_widget_callback(GuiButtonType result, void* context) {
Nfc* nfc = (Nfc*)context;
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
}
void nfc_scene_delete_on_enter(void* context) {
Nfc* nfc = (Nfc*)context;
// Setup Custom Widget view
char delete_str[64];
snprintf(delete_str, sizeof(delete_str), "Delete %s", nfc->dev.dev_name);
gui_widget_add_string_element(
nfc->widget, 64, 6, AlignCenter, AlignTop, FontPrimary, delete_str);
gui_widget_add_button_element(
nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_delete_widget_callback, nfc);
gui_widget_add_button_element(
nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc);
char uid_str[32];
NfcDeviceCommomData* data = &nfc->dev.dev_data.nfc_data;
if(data->uid_len == 4) {
snprintf(
uid_str,
sizeof(uid_str),
"UID: %02X %02X %02X %02X",
data->uid[0],
data->uid[1],
data->uid[2],
data->uid[3]);
} else if(data->uid_len == 7) {
snprintf(
uid_str,
sizeof(uid_str),
"UID: %02X %02X %02X %02X %02X %02X %02X",
data->uid[0],
data->uid[1],
data->uid[2],
data->uid[3],
data->uid[4],
data->uid[5],
data->uid[6]);
}
gui_widget_add_string_element(
nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str);
if(data->protocol > NfcDeviceProtocolUnknown) {
gui_widget_add_string_element(
nfc->widget,
10,
32,
AlignLeft,
AlignTop,
FontSecondary,
nfc_get_protocol(data->protocol));
}
// TODO change dinamically
gui_widget_add_string_element(
nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A");
char sak_str[16];
snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak);
gui_widget_add_string_element(
nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str);
char atqa_str[16];
snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
gui_widget_add_string_element(
nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
}
const bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = (Nfc*)context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GuiButtonTypeLeft) {
return scene_manager_previous_scene(nfc->scene_manager);
} else if(event.event == GuiButtonTypeRight) {
if(nfc_device_delete(&nfc->dev)) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDeleteSuccess);
} else {
scene_manager_search_previous_scene(nfc->scene_manager, NfcSceneStart);
}
return true;
}
}
return false;
}
const void nfc_scene_delete_on_exit(void* context) {
Nfc* nfc = (Nfc*)context;
gui_widget_clear(nfc->widget);
}