nfc_scene_read_card.c 1.5 KB

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