nfc_scene_delete.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "../nfc_i.h"
  2. void nfc_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
  3. Nfc* nfc = (Nfc*)context;
  4. if(type == InputTypeShort) {
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  6. }
  7. }
  8. void nfc_scene_delete_on_enter(void* context) {
  9. Nfc* nfc = (Nfc*)context;
  10. // Setup Custom Widget view
  11. char delete_str[64];
  12. snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", nfc->dev->dev_name);
  13. widget_add_text_box_element(nfc->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str);
  14. widget_add_button_element(
  15. nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_delete_widget_callback, nfc);
  16. widget_add_button_element(
  17. nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc);
  18. char uid_str[32];
  19. NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data;
  20. if(data->uid_len == 4) {
  21. snprintf(
  22. uid_str,
  23. sizeof(uid_str),
  24. "UID: %02X %02X %02X %02X",
  25. data->uid[0],
  26. data->uid[1],
  27. data->uid[2],
  28. data->uid[3]);
  29. } else if(data->uid_len == 7) {
  30. snprintf(
  31. uid_str,
  32. sizeof(uid_str),
  33. "UID: %02X %02X %02X %02X %02X %02X %02X",
  34. data->uid[0],
  35. data->uid[1],
  36. data->uid[2],
  37. data->uid[3],
  38. data->uid[4],
  39. data->uid[5],
  40. data->uid[6]);
  41. }
  42. widget_add_string_element(nfc->widget, 64, 23, AlignCenter, AlignTop, FontSecondary, uid_str);
  43. const char* protocol_name = NULL;
  44. if(data->protocol == NfcDeviceProtocolEMV) {
  45. protocol_name = nfc_guess_protocol(data->protocol);
  46. } else if(data->protocol == NfcDeviceProtocolMifareUl) {
  47. protocol_name = nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, false);
  48. }
  49. if(protocol_name) {
  50. widget_add_string_element(
  51. nfc->widget, 10, 33, AlignLeft, AlignTop, FontSecondary, protocol_name);
  52. }
  53. // TODO change dinamically
  54. widget_add_string_element(nfc->widget, 118, 33, AlignRight, AlignTop, FontSecondary, "NFC-A");
  55. char sak_str[16];
  56. snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak);
  57. widget_add_string_element(nfc->widget, 10, 43, AlignLeft, AlignTop, FontSecondary, sak_str);
  58. char atqa_str[16];
  59. snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
  60. widget_add_string_element(nfc->widget, 118, 43, AlignRight, AlignTop, FontSecondary, atqa_str);
  61. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  62. }
  63. bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
  64. Nfc* nfc = (Nfc*)context;
  65. if(event.type == SceneManagerEventTypeCustom) {
  66. if(event.event == GuiButtonTypeLeft) {
  67. return scene_manager_previous_scene(nfc->scene_manager);
  68. } else if(event.event == GuiButtonTypeRight) {
  69. if(nfc_device_delete(nfc->dev)) {
  70. scene_manager_next_scene(nfc->scene_manager, NfcSceneDeleteSuccess);
  71. } else {
  72. scene_manager_search_and_switch_to_previous_scene(
  73. nfc->scene_manager, NfcSceneStart);
  74. }
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80. void nfc_scene_delete_on_exit(void* context) {
  81. Nfc* nfc = (Nfc*)context;
  82. widget_reset(nfc->widget);
  83. }