nfc_scene_read_card_success.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // Setup view
  21. FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data;
  22. Widget* widget = nfc->widget;
  23. string_set_str(data_str, nfc_get_dev_type(data->type));
  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->type == FuriHalNfcTypeA) {
  31. widget_add_button_element(
  32. widget, GuiButtonTypeRight, "Save", nfc_scene_read_card_success_widget_callback, nfc);
  33. widget_add_icon_element(widget, 8, 13, &I_Medium_chip_22x21);
  34. widget_add_string_element(
  35. widget, 37, 12, AlignLeft, AlignBottom, FontPrimary, string_get_cstr(data_str));
  36. string_printf(
  37. data_str, "ATQA: %02X%02X\nSAK: %02X", data->atqa[0], data->atqa[1], data->sak);
  38. widget_add_string_multiline_element(
  39. widget, 37, 16, AlignLeft, AlignTop, FontSecondary, string_get_cstr(data_str));
  40. widget_add_string_element(
  41. widget, 64, 46, AlignCenter, AlignBottom, FontSecondary, string_get_cstr(uid_str));
  42. } else {
  43. widget_add_string_element(
  44. widget, 64, 12, AlignCenter, AlignBottom, FontPrimary, string_get_cstr(data_str));
  45. widget_add_string_element(
  46. widget, 64, 32, AlignCenter, AlignCenter, FontSecondary, string_get_cstr(uid_str));
  47. }
  48. string_clear(data_str);
  49. string_clear(uid_str);
  50. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  51. }
  52. bool nfc_scene_read_card_success_on_event(void* context, SceneManagerEvent event) {
  53. Nfc* nfc = context;
  54. bool consumed = false;
  55. if(event.type == SceneManagerEventTypeCustom) {
  56. if(event.event == GuiButtonTypeLeft) {
  57. consumed = scene_manager_previous_scene(nfc->scene_manager);
  58. } else if(event.event == GuiButtonTypeRight) {
  59. nfc->dev->format = NfcDeviceSaveFormatUid;
  60. nfc_device_set_name(nfc->dev, "");
  61. scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
  62. consumed = true;
  63. }
  64. }
  65. return consumed;
  66. }
  67. void nfc_scene_read_card_success_on_exit(void* context) {
  68. Nfc* nfc = context;
  69. // Clear view
  70. widget_reset(nfc->widget);
  71. }