nfc_scene_read_mifare_desfire.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. void nfc_read_mifare_desfire_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_mifare_desfire_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, "Reading\nDESFire", 70, 34, AlignLeft, AlignTop);
  14. popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  15. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  16. // Start worker
  17. nfc_worker_start(
  18. nfc->worker,
  19. NfcWorkerStateReadMifareDesfire,
  20. &nfc->dev->dev_data,
  21. nfc_read_mifare_desfire_worker_callback,
  22. nfc);
  23. }
  24. bool nfc_scene_read_mifare_desfire_on_event(void* context, SceneManagerEvent event) {
  25. Nfc* nfc = context;
  26. bool consumed = false;
  27. if(event.type == SceneManagerEventTypeCustom) {
  28. if(event.event == NfcCustomEventWorkerExit) {
  29. notification_message(nfc->notifications, &sequence_success);
  30. scene_manager_next_scene(nfc->scene_manager, NfcSceneReadMifareDesfireSuccess);
  31. consumed = true;
  32. }
  33. } else if(event.type == SceneManagerEventTypeTick) {
  34. notification_message(nfc->notifications, &sequence_blink_blue_10);
  35. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  36. consumed = true;
  37. }
  38. return consumed;
  39. }
  40. void nfc_scene_read_mifare_desfire_on_exit(void* context) {
  41. Nfc* nfc = context;
  42. // Stop worker
  43. nfc_worker_stop(nfc->worker);
  44. // Clear view
  45. popup_reset(nfc->popup);
  46. }