nfc_scene_read_card.c 1.4 KB

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