nfc_scene_nfca_read_success.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. string_t temp_str;
  20. string_init_set_str(temp_str, "\e#Unknown ISO tag\n");
  21. char iso_type = FURI_BIT(data->sak, 5) ? '4' : '3';
  22. string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type);
  23. string_cat_printf(temp_str, "UID:");
  24. for(size_t i = 0; i < data->uid_len; i++) {
  25. string_cat_printf(temp_str, " %02X", data->uid[i]);
  26. }
  27. string_cat_printf(temp_str, "\nATQA: %02X %02X ", data->atqa[1], data->atqa[0]);
  28. string_cat_printf(temp_str, " SAK: %02X", data->sak);
  29. widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
  30. string_clear(temp_str);
  31. widget_add_button_element(
  32. widget, GuiButtonTypeLeft, "Retry", nfc_scene_nfca_read_success_widget_callback, nfc);
  33. widget_add_button_element(
  34. widget, GuiButtonTypeRight, "More", nfc_scene_nfca_read_success_widget_callback, nfc);
  35. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  36. }
  37. bool nfc_scene_nfca_read_success_on_event(void* context, SceneManagerEvent event) {
  38. Nfc* nfc = context;
  39. bool consumed = false;
  40. if(event.type == SceneManagerEventTypeCustom) {
  41. if(event.event == GuiButtonTypeLeft) {
  42. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  43. consumed = true;
  44. } else if(event.event == GuiButtonTypeRight) {
  45. scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcaMenu);
  46. consumed = true;
  47. }
  48. } else if(event.type == SceneManagerEventTypeBack) {
  49. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  50. consumed = true;
  51. }
  52. return consumed;
  53. }
  54. void nfc_scene_nfca_read_success_on_exit(void* context) {
  55. Nfc* nfc = context;
  56. // Clear view
  57. widget_reset(nfc->widget);
  58. }