nfc_scene_read_mifare_ul.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <nfc/scenes/nfc_scene_read_mifare_ul.h>
  2. #include <furi.h>
  3. #include "../nfc_i.h"
  4. void nfc_read_mifare_ul_worker_callback(void* context) {
  5. Nfc* nfc = (Nfc*)context;
  6. view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, NfcEventMifareUl);
  7. }
  8. const void nfc_scene_read_mifare_ul_on_enter(void* context) {
  9. Nfc* nfc = (Nfc*)context;
  10. // Setup view
  11. Popup* popup = nfc->popup;
  12. popup_set_header(popup, "Detecting\nultralight", 70, 34, AlignLeft, AlignTop);
  13. popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  14. // Start worker
  15. nfc_worker_start(
  16. nfc->nfc_common.worker,
  17. NfcWorkerStateReadMfUltralight,
  18. &nfc->nfc_common.worker_result,
  19. nfc_read_mifare_ul_worker_callback,
  20. nfc);
  21. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
  22. }
  23. const bool nfc_scene_read_mifare_ul_on_event(void* context, uint32_t event) {
  24. Nfc* nfc = (Nfc*)context;
  25. if(event == NfcEventMifareUl) {
  26. nfc->device.data = nfc->nfc_common.worker_result.nfc_detect_data;
  27. view_dispatcher_add_scene(
  28. nfc->nfc_common.view_dispatcher, nfc->scene_read_mifare_ul_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_mifare_ul_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, NULL);
  44. }
  45. AppScene* nfc_scene_read_mifare_ul_alloc() {
  46. AppScene* scene = furi_alloc(sizeof(AppScene));
  47. scene->id = NfcSceneReadMifareUl;
  48. scene->on_enter = nfc_scene_read_mifare_ul_on_enter;
  49. scene->on_event = nfc_scene_read_mifare_ul_on_event;
  50. scene->on_exit = nfc_scene_read_mifare_ul_on_exit;
  51. return scene;
  52. }
  53. void nfc_scene_read_mifare_ul_free(AppScene* scene) {
  54. free(scene);
  55. }