nfc_scene_read_card.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "../nfc_i.h"
  2. #define NFC_READ_CARD_CUSTOM_EVENT (0UL)
  3. void nfc_read_card_worker_callback(void* context) {
  4. Nfc* nfc = (Nfc*)context;
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, NFC_READ_CARD_CUSTOM_EVENT);
  6. }
  7. const void nfc_scene_read_card_on_enter(void* context) {
  8. Nfc* nfc = (Nfc*)context;
  9. // Setup view
  10. Popup* popup = nfc->popup;
  11. popup_set_header(popup, "Detecting\nNFC card", 70, 34, AlignLeft, AlignTop);
  12. popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  13. // Start worker
  14. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  15. nfc_worker_start(
  16. nfc->worker, NfcWorkerStateDetect, &nfc->dev.dev_data, nfc_read_card_worker_callback, nfc);
  17. }
  18. const bool nfc_scene_read_card_on_event(void* context, SceneManagerEvent event) {
  19. Nfc* nfc = (Nfc*)context;
  20. if(event.type == SceneManagerEventTypeCustom) {
  21. if(event.event == NFC_READ_CARD_CUSTOM_EVENT) {
  22. scene_manager_next_scene(nfc->scene_manager, NfcSceneReadCardSuccess);
  23. return true;
  24. }
  25. } else if(event.type == SceneManagerEventTypeTick) {
  26. notification_message(nfc->notifications, &sequence_blink_blue_10);
  27. return true;
  28. }
  29. return false;
  30. }
  31. const void nfc_scene_read_card_on_exit(void* context) {
  32. Nfc* nfc = (Nfc*)context;
  33. // Stop worker
  34. nfc_worker_stop(nfc->worker);
  35. // Clear view
  36. Popup* popup = nfc->popup;
  37. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  38. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  39. popup_set_icon(popup, 0, 0, NULL);
  40. }