nfc_scene_read_mifare_ul.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. void nfc_read_mifare_ul_worker_callback(void* context) {
  4. Nfc* nfc = (Nfc*)context;
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventWorkerExit);
  6. }
  7. void nfc_scene_read_mifare_ul_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, "Detecting\nultralight", 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. // Start worker
  16. nfc_worker_start(
  17. nfc->worker,
  18. NfcWorkerStateReadMifareUl,
  19. &nfc->dev->dev_data,
  20. nfc_read_mifare_ul_worker_callback,
  21. nfc);
  22. }
  23. bool nfc_scene_read_mifare_ul_on_event(void* context, SceneManagerEvent event) {
  24. Nfc* nfc = (Nfc*)context;
  25. if(event.type == SceneManagerEventTypeCustom) {
  26. if(event.event == NfcCustomEventWorkerExit) {
  27. scene_manager_next_scene(nfc->scene_manager, NfcSceneReadMifareUlSuccess);
  28. return true;
  29. }
  30. } else if(event.type == SceneManagerEventTypeTick) {
  31. notification_message(nfc->notifications, &sequence_blink_blue_10);
  32. return true;
  33. }
  34. return false;
  35. }
  36. void nfc_scene_read_mifare_ul_on_exit(void* context) {
  37. Nfc* nfc = (Nfc*)context;
  38. // Stop worker
  39. nfc_worker_stop(nfc->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. }