nfc_scene_read_card.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. void nfc_read_card_worker_callback(NfcWorkerEvent event, void* context) {
  4. Nfc* 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 = (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 = (Nfc*)context;
  21. if(event.type == SceneManagerEventTypeCustom) {
  22. if(event.event == NfcCustomEventWorkerExit) {
  23. scene_manager_next_scene(nfc->scene_manager, NfcSceneReadCardSuccess);
  24. return true;
  25. }
  26. } else if(event.type == SceneManagerEventTypeTick) {
  27. notification_message(nfc->notifications, &sequence_blink_blue_10);
  28. return true;
  29. }
  30. return false;
  31. }
  32. void nfc_scene_read_card_on_exit(void* context) {
  33. Nfc* nfc = (Nfc*)context;
  34. // Stop worker
  35. nfc_worker_stop(nfc->worker);
  36. // Clear view
  37. Popup* popup = nfc->popup;
  38. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  39. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  40. popup_set_icon(popup, 0, 0, NULL);
  41. }