nfc_scene_emulate_mifare_ul.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "../nfc_i.h"
  2. #define NFC_MF_UL_DATA_NOT_CHANGED (0UL)
  3. #define NFC_MF_UL_DATA_CHANGED (1UL)
  4. void nfc_emulate_mifare_ul_worker_callback(void* context) {
  5. Nfc* nfc = (Nfc*)context;
  6. scene_manager_set_scene_state(
  7. nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_DATA_CHANGED);
  8. }
  9. void nfc_scene_emulate_mifare_ul_on_enter(void* context) {
  10. Nfc* nfc = (Nfc*)context;
  11. // Setup view
  12. Popup* popup = nfc->popup;
  13. if(strcmp(nfc->dev.dev_name, "")) {
  14. nfc_text_store_set(nfc, "%s", nfc->dev.dev_name);
  15. }
  16. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  17. popup_set_header(popup, "Emulating\nMf Ultralight", 56, 31, AlignLeft, AlignTop);
  18. // Setup and start worker
  19. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  20. nfc_worker_start(
  21. nfc->worker,
  22. NfcWorkerStateEmulateMifareUl,
  23. &nfc->dev.dev_data,
  24. nfc_emulate_mifare_ul_worker_callback,
  25. nfc);
  26. }
  27. bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent event) {
  28. Nfc* nfc = (Nfc*)context;
  29. bool consumed = false;
  30. if(event.type == SceneManagerEventTypeTick) {
  31. notification_message(nfc->notifications, &sequence_blink_blue_10);
  32. consumed = true;
  33. } else if(event.type == SceneManagerEventTypeBack) {
  34. // Stop worker
  35. nfc_worker_stop(nfc->worker);
  36. // Check if data changed and save in shadow file
  37. if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneEmulateMifareUl) ==
  38. NFC_MF_UL_DATA_CHANGED) {
  39. scene_manager_set_scene_state(
  40. nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_DATA_NOT_CHANGED);
  41. nfc_device_save_shadow(&nfc->dev, nfc->dev.dev_name);
  42. }
  43. consumed = false;
  44. }
  45. return consumed;
  46. }
  47. void nfc_scene_emulate_mifare_ul_on_exit(void* context) {
  48. Nfc* nfc = (Nfc*)context;
  49. // Clear view
  50. Popup* popup = nfc->popup;
  51. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  52. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  53. popup_set_icon(popup, 0, 0, NULL);
  54. }