nfc_scene_read_card.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }
  20. bool nfc_scene_read_card_on_event(void* context, SceneManagerEvent event) {
  21. Nfc* nfc = context;
  22. bool consumed = false;
  23. if(event.type == SceneManagerEventTypeCustom) {
  24. if(event.event == NfcCustomEventWorkerExit) {
  25. scene_manager_next_scene(nfc->scene_manager, NfcSceneReadCardSuccess);
  26. consumed = true;
  27. }
  28. } else if(event.type == SceneManagerEventTypeTick) {
  29. notification_message(nfc->notifications, &sequence_blink_blue_10);
  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. }