nfc_scene_read_card.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, 4, I_RFIDDolphinReceive_98x60);
  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. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_read_card_success);
  29. view_dispatcher_send_navigation_event(
  30. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  31. return true;
  32. }
  33. return false;
  34. }
  35. const void nfc_scene_read_card_on_exit(void* context) {
  36. Nfc* nfc = (Nfc*)context;
  37. // Stop worker
  38. nfc_worker_stop(nfc->nfc_common.worker);
  39. // Clear view
  40. Popup* popup = nfc->popup;
  41. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  42. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  43. popup_set_icon(popup, 0, 0, I_Empty_1x1);
  44. }
  45. AppScene* nfc_scene_read_card_alloc() {
  46. AppScene* scene = furi_alloc(sizeof(AppScene));
  47. scene->id = NfcSceneReadCard;
  48. scene->on_enter = nfc_scene_read_card_on_enter;
  49. scene->on_event = nfc_scene_read_card_on_event;
  50. scene->on_exit = nfc_scene_read_card_on_exit;
  51. return scene;
  52. }
  53. void nfc_scene_read_card_free(AppScene* scene) {
  54. free(scene);
  55. }