nfc_scene_read_card.c 1.6 KB

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