nfc_scene_read_card.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <nfc/scenes/nfc_scene_read_card.h>
  2. #include <furi.h>
  3. #include "../nfc_i.h"
  4. #include "../views/nfc_detect.h"
  5. #include <gui/view_dispatcher.h>
  6. void nfc_read_card_worker_callback(void* context) {
  7. Nfc* nfc = (Nfc*)context;
  8. view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, NfcEventDetect);
  9. }
  10. const void nfc_scene_read_card_on_enter(void* context) {
  11. Nfc* nfc = (Nfc*)context;
  12. // Setup view
  13. Popup* popup = nfc->popup;
  14. popup_set_header(popup, "Detecting\nNFC card", 70, 34, AlignLeft, AlignTop);
  15. popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  16. // Start worker
  17. nfc_worker_start(
  18. nfc->nfc_common.worker,
  19. NfcWorkerStateDetect,
  20. &nfc->nfc_common.worker_result,
  21. nfc_read_card_worker_callback,
  22. nfc);
  23. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
  24. }
  25. const bool nfc_scene_read_card_on_event(void* context, uint32_t event) {
  26. Nfc* nfc = (Nfc*)context;
  27. if(event == NfcEventDetect) {
  28. nfc->device.data = nfc->nfc_common.worker_result.nfc_detect_data;
  29. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_read_card_success);
  30. view_dispatcher_send_navigation_event(
  31. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  32. return true;
  33. }
  34. return false;
  35. }
  36. const void nfc_scene_read_card_on_exit(void* context) {
  37. Nfc* nfc = (Nfc*)context;
  38. // Stop worker
  39. nfc_worker_stop(nfc->nfc_common.worker);
  40. // Clear view
  41. Popup* popup = nfc->popup;
  42. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  43. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  44. popup_set_icon(popup, 0, 0, NULL);
  45. }
  46. AppScene* nfc_scene_read_card_alloc() {
  47. AppScene* scene = furi_alloc(sizeof(AppScene));
  48. scene->id = NfcSceneReadCard;
  49. scene->on_enter = nfc_scene_read_card_on_enter;
  50. scene->on_event = nfc_scene_read_card_on_event;
  51. scene->on_exit = nfc_scene_read_card_on_exit;
  52. return scene;
  53. }
  54. void nfc_scene_read_card_free(AppScene* scene) {
  55. free(scene);
  56. }