nfc_scene_read_card_success.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "../nfc_i.h"
  2. void nfc_scene_read_card_success_widget_callback(
  3. GuiButtonType result,
  4. InputType type,
  5. void* context) {
  6. furi_assert(context);
  7. Nfc* nfc = context;
  8. if(type == InputTypeShort) {
  9. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  10. }
  11. }
  12. void nfc_scene_read_card_success_on_enter(void* context) {
  13. Nfc* nfc = (Nfc*)context;
  14. string_t data_str;
  15. string_t uid_str;
  16. string_init(data_str);
  17. string_init(uid_str);
  18. // Send notification
  19. notification_message(nfc->notifications, &sequence_success);
  20. // Setup view
  21. NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data;
  22. Widget* widget = nfc->widget;
  23. string_set_str(data_str, nfc_get_dev_type(data->device));
  24. string_set_str(uid_str, "UID:");
  25. for(uint8_t i = 0; i < data->uid_len; i++) {
  26. string_cat_printf(uid_str, " %02X", data->uid[i]);
  27. }
  28. widget_add_button_element(
  29. widget, GuiButtonTypeLeft, "Retry", nfc_scene_read_card_success_widget_callback, nfc);
  30. if(data->device == NfcDeviceNfca) {
  31. widget_add_button_element(
  32. widget, GuiButtonTypeRight, "More", nfc_scene_read_card_success_widget_callback, nfc);
  33. widget_add_icon_element(widget, 8, 13, &I_Medium_chip_22x21);
  34. string_cat_printf(data_str, " may be:");
  35. widget_add_string_element(
  36. widget, 37, 12, AlignLeft, AlignBottom, FontPrimary, string_get_cstr(data_str));
  37. string_printf(
  38. data_str,
  39. "%s\nATQA: %02X%02X SAK: %02X",
  40. nfc_guess_protocol(data->protocol),
  41. data->atqa[0],
  42. data->atqa[1],
  43. data->sak);
  44. widget_add_string_multiline_element(
  45. widget, 37, 16, AlignLeft, AlignTop, FontSecondary, string_get_cstr(data_str));
  46. widget_add_string_element(
  47. widget, 64, 46, AlignCenter, AlignBottom, FontSecondary, string_get_cstr(uid_str));
  48. } else {
  49. widget_add_string_element(
  50. widget, 64, 12, AlignCenter, AlignBottom, FontPrimary, string_get_cstr(data_str));
  51. widget_add_string_element(
  52. widget, 64, 32, AlignCenter, AlignCenter, FontSecondary, string_get_cstr(uid_str));
  53. }
  54. string_clear(data_str);
  55. string_clear(uid_str);
  56. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  57. }
  58. bool nfc_scene_read_card_success_on_event(void* context, SceneManagerEvent event) {
  59. Nfc* nfc = (Nfc*)context;
  60. NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data;
  61. bool consumed = false;
  62. if(event.type == SceneManagerEventTypeCustom) {
  63. if(event.event == GuiButtonTypeLeft) {
  64. consumed = scene_manager_previous_scene(nfc->scene_manager);
  65. } else if(data->device == NfcDeviceNfca && event.event == GuiButtonTypeRight) {
  66. // Clear device name
  67. nfc_device_set_name(nfc->dev, "");
  68. scene_manager_next_scene(nfc->scene_manager, NfcSceneCardMenu);
  69. consumed = true;
  70. }
  71. }
  72. return consumed;
  73. }
  74. void nfc_scene_read_card_success_on_exit(void* context) {
  75. Nfc* nfc = (Nfc*)context;
  76. widget_clear(nfc->widget);
  77. }