nfc_scene_read_emv_app_success.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "../nfc_i.h"
  2. #define NFC_SCENE_READ_SUCCESS_SHIFT " "
  3. void nfc_scene_read_emv_app_success_dialog_callback(DialogExResult result, void* context) {
  4. Nfc* nfc = (Nfc*)context;
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  6. }
  7. void nfc_scene_read_emv_app_success_on_enter(void* context) {
  8. Nfc* nfc = (Nfc*)context;
  9. // Setup view
  10. NfcDeviceCommomData* nfc_data = &nfc->dev.dev_data.nfc_data;
  11. NfcEmvData* emv_data = &nfc->dev.dev_data.emv_data;
  12. DialogEx* dialog_ex = nfc->dialog_ex;
  13. dialog_ex_set_left_button_text(dialog_ex, "Retry");
  14. dialog_ex_set_right_button_text(dialog_ex, "Run app");
  15. dialog_ex_set_header(dialog_ex, "Found EMV App", 36, 8, AlignLeft, AlignCenter);
  16. dialog_ex_set_icon(dialog_ex, 8, 13, &I_Medium_chip_22x21);
  17. // Display UID and AID
  18. string_t aid;
  19. string_init_printf(aid, "AID:");
  20. for(uint8_t i = 0; i < emv_data->aid_len; i++) {
  21. string_cat_printf(aid, " %02X", emv_data->aid[i]);
  22. }
  23. nfc_text_store_set(
  24. nfc,
  25. NFC_SCENE_READ_SUCCESS_SHIFT "UID: %02X %02X %02X %02X \n\n%s",
  26. nfc_data->uid[0],
  27. nfc_data->uid[1],
  28. nfc_data->uid[2],
  29. nfc_data->uid[3],
  30. string_get_cstr(aid));
  31. string_clear(aid);
  32. dialog_ex_set_text(dialog_ex, nfc->text_store, 8, 16, AlignLeft, AlignTop);
  33. dialog_ex_set_context(dialog_ex, nfc);
  34. dialog_ex_set_result_callback(dialog_ex, nfc_scene_read_emv_app_success_dialog_callback);
  35. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
  36. }
  37. const bool nfc_scene_read_emv_app_success_on_event(void* context, SceneManagerEvent event) {
  38. Nfc* nfc = (Nfc*)context;
  39. if(event.type == SceneManagerEventTypeCustom) {
  40. if(event.event == DialogExResultLeft) {
  41. return scene_manager_previous_scene(nfc->scene_manager);
  42. } else if(event.event == DialogExResultRight) {
  43. scene_manager_next_scene(nfc->scene_manager, NfcSceneRunEmvAppConfirm);
  44. return true;
  45. }
  46. }
  47. return false;
  48. }
  49. const void nfc_scene_read_emv_app_success_on_exit(void* context) {
  50. Nfc* nfc = (Nfc*)context;
  51. DialogEx* dialog_ex = nfc->dialog_ex;
  52. dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
  53. dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
  54. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  55. dialog_ex_set_left_button_text(dialog_ex, NULL);
  56. dialog_ex_set_right_button_text(dialog_ex, NULL);
  57. dialog_ex_set_result_callback(dialog_ex, NULL);
  58. dialog_ex_set_context(dialog_ex, NULL);
  59. }