nfc_scene_read_emv_data.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define NFC_READ_EMV_DATA_CUSTOM_EVENT (10UL)
  4. void nfc_read_emv_data_worker_callback(void* context) {
  5. Nfc* nfc = (Nfc*)context;
  6. view_dispatcher_send_custom_event(nfc->view_dispatcher, NFC_READ_EMV_DATA_CUSTOM_EVENT);
  7. }
  8. void nfc_scene_read_emv_data_on_enter(void* context) {
  9. Nfc* nfc = (Nfc*)context;
  10. DOLPHIN_DEED(DolphinDeedNfcRead);
  11. // Setup view
  12. Popup* popup = nfc->popup;
  13. popup_set_header(popup, "Reading\nbank card", 70, 34, AlignLeft, AlignTop);
  14. popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  15. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  16. // Clear emv data
  17. memset(&nfc->dev->dev_data.emv_data, 0, sizeof(nfc->dev->dev_data.emv_data));
  18. // Start worker
  19. nfc_worker_start(
  20. nfc->worker,
  21. NfcWorkerStateReadEMV,
  22. &nfc->dev->dev_data,
  23. nfc_read_emv_data_worker_callback,
  24. nfc);
  25. }
  26. bool nfc_scene_read_emv_data_on_event(void* context, SceneManagerEvent event) {
  27. Nfc* nfc = (Nfc*)context;
  28. if(event.type == SceneManagerEventTypeCustom) {
  29. if(event.event == NFC_READ_EMV_DATA_CUSTOM_EVENT) {
  30. scene_manager_set_scene_state(
  31. nfc->scene_manager, NfcSceneReadEmvDataSuccess, NFC_SEND_NOTIFICATION_TRUE);
  32. scene_manager_next_scene(nfc->scene_manager, NfcSceneReadEmvDataSuccess);
  33. return true;
  34. }
  35. } else if(event.type == SceneManagerEventTypeTick) {
  36. notification_message(nfc->notifications, &sequence_blink_blue_10);
  37. return true;
  38. }
  39. return false;
  40. }
  41. void nfc_scene_read_emv_data_on_exit(void* context) {
  42. Nfc* nfc = (Nfc*)context;
  43. // Stop worker
  44. nfc_worker_stop(nfc->worker);
  45. // Clear view
  46. Popup* popup = nfc->popup;
  47. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  48. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  49. popup_set_icon(popup, 0, 0, NULL);
  50. }