nfc_scene_mf_classic_emulate.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "../nfc_i.h"
  2. #define NFC_MF_CLASSIC_DATA_NOT_CHANGED (0UL)
  3. #define NFC_MF_CLASSIC_DATA_CHANGED (1UL)
  4. bool nfc_mf_classic_emulate_worker_callback(NfcWorkerEvent event, void* context) {
  5. UNUSED(event);
  6. Nfc* nfc = context;
  7. scene_manager_set_scene_state(
  8. nfc->scene_manager, NfcSceneMfClassicEmulate, NFC_MF_CLASSIC_DATA_CHANGED);
  9. return true;
  10. }
  11. void nfc_scene_mf_classic_emulate_on_enter(void* context) {
  12. Nfc* nfc = context;
  13. // Setup view
  14. Popup* popup = nfc->popup;
  15. popup_set_header(popup, "Emulating", 67, 13, AlignLeft, AlignTop);
  16. if(strcmp(nfc->dev->dev_name, "") != 0) {
  17. nfc_text_store_set(nfc, "%s", nfc->dev->dev_name);
  18. } else {
  19. nfc_text_store_set(nfc, "MIFARE\nClassic");
  20. }
  21. popup_set_icon(popup, 0, 3, &I_NFC_dolphin_emulation_47x61);
  22. popup_set_text(popup, nfc->text_store, 90, 28, AlignCenter, AlignTop);
  23. // Setup and start worker
  24. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  25. nfc_worker_start(
  26. nfc->worker,
  27. NfcWorkerStateMfClassicEmulate,
  28. &nfc->dev->dev_data,
  29. nfc_mf_classic_emulate_worker_callback,
  30. nfc);
  31. nfc_blink_emulate_start(nfc);
  32. }
  33. bool nfc_scene_mf_classic_emulate_on_event(void* context, SceneManagerEvent event) {
  34. Nfc* nfc = context;
  35. bool consumed = false;
  36. if(event.type == SceneManagerEventTypeBack) {
  37. // Stop worker
  38. nfc_worker_stop(nfc->worker);
  39. // Check if data changed and save in shadow file
  40. if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfClassicEmulate) ==
  41. NFC_MF_CLASSIC_DATA_CHANGED) {
  42. scene_manager_set_scene_state(
  43. nfc->scene_manager, NfcSceneMfClassicEmulate, NFC_MF_CLASSIC_DATA_NOT_CHANGED);
  44. // Save shadow file
  45. if(furi_string_size(nfc->dev->load_path)) {
  46. nfc_device_save_shadow(nfc->dev, furi_string_get_cstr(nfc->dev->load_path));
  47. }
  48. }
  49. consumed = false;
  50. }
  51. return consumed;
  52. }
  53. void nfc_scene_mf_classic_emulate_on_exit(void* context) {
  54. Nfc* nfc = context;
  55. // Clear view
  56. popup_reset(nfc->popup);
  57. nfc_blink_stop(nfc);
  58. }