nfc_scene_nfca_read_success.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. void nfc_scene_nfca_read_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_nfca_read_success_on_enter(void* context) {
  14. Nfc* nfc = context;
  15. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  16. // Setup view
  17. FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data;
  18. Widget* widget = nfc->widget;
  19. FuriString* temp_str;
  20. temp_str = furi_string_alloc_set("\e#Unknown ISO tag\n");
  21. notification_message_block(nfc->notifications, &sequence_set_green_255);
  22. char iso_type = FURI_BIT(data->sak, 5) ? '4' : '3';
  23. furi_string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type);
  24. furi_string_cat_printf(temp_str, "UID:");
  25. for(size_t i = 0; i < data->uid_len; i++) {
  26. furi_string_cat_printf(temp_str, " %02X", data->uid[i]);
  27. }
  28. furi_string_cat_printf(temp_str, "\nATQA: %02X %02X ", data->atqa[1], data->atqa[0]);
  29. furi_string_cat_printf(temp_str, " SAK: %02X", data->sak);
  30. widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
  31. furi_string_free(temp_str);
  32. widget_add_button_element(
  33. widget, GuiButtonTypeLeft, "Retry", nfc_scene_nfca_read_success_widget_callback, nfc);
  34. widget_add_button_element(
  35. widget, GuiButtonTypeRight, "More", nfc_scene_nfca_read_success_widget_callback, nfc);
  36. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  37. }
  38. bool nfc_scene_nfca_read_success_on_event(void* context, SceneManagerEvent event) {
  39. Nfc* nfc = context;
  40. bool consumed = false;
  41. if(event.type == SceneManagerEventTypeCustom) {
  42. if(event.event == GuiButtonTypeLeft) {
  43. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  44. consumed = true;
  45. } else if(event.event == GuiButtonTypeRight) {
  46. scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcaMenu);
  47. consumed = true;
  48. }
  49. } else if(event.type == SceneManagerEventTypeBack) {
  50. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  51. consumed = true;
  52. }
  53. return consumed;
  54. }
  55. void nfc_scene_nfca_read_success_on_exit(void* context) {
  56. Nfc* nfc = context;
  57. notification_message_block(nfc->notifications, &sequence_reset_green);
  58. // Clear view
  59. widget_reset(nfc->widget);
  60. }