nfc_scene_read_emv_data.c 1.9 KB

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