nfc_scene_read_card_success.c 3.2 KB

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