nfc_scene_read_card.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "../nfc_i.h"
  2. void nfc_read_card_worker_callback(void* context) {
  3. Nfc* nfc = (Nfc*)context;
  4. view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, NfcEventDetect);
  5. }
  6. const void nfc_scene_read_card_on_enter(void* context) {
  7. Nfc* nfc = (Nfc*)context;
  8. // Setup view
  9. Popup* popup = nfc->popup;
  10. popup_set_header(popup, "Detecting\nNFC card", 70, 34, AlignLeft, AlignTop);
  11. popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  12. // Start worker
  13. nfc_worker_start(
  14. nfc->nfc_common.worker,
  15. NfcWorkerStateDetect,
  16. &nfc->nfc_common.worker_result,
  17. nfc_read_card_worker_callback,
  18. nfc);
  19. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
  20. }
  21. const bool nfc_scene_read_card_on_event(void* context, SceneManagerEvent event) {
  22. Nfc* nfc = (Nfc*)context;
  23. if(event.type == SceneManagerEventTypeCustom) {
  24. if(event.event == NfcEventDetect) {
  25. nfc->device.data = nfc->nfc_common.worker_result.nfc_detect_data;
  26. scene_manager_next_scene(nfc->scene_manager, NfcSceneReadCardSuccess);
  27. return true;
  28. }
  29. } else if(event.type == SceneManagerEventTypeTick) {
  30. notification_message(nfc->notifications, &sequence_blink_blue_10);
  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, NULL);
  44. }