nfc_scene_read_mifare_desfire.c 1.7 KB

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