nfc_scene_mf_classic_emulate.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. if(strcmp(nfc->dev->dev_name, "")) {
  16. nfc_text_store_set(nfc, "Emulating\n%s", nfc->dev->dev_name);
  17. } else {
  18. nfc_text_store_set(nfc, "Emulating\nMf Classic", nfc->dev->dev_name);
  19. }
  20. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  21. popup_set_header(popup, nfc->text_store, 56, 31, AlignLeft, AlignTop);
  22. // Setup and start worker
  23. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  24. nfc_worker_start(
  25. nfc->worker,
  26. NfcWorkerStateMfClassicEmulate,
  27. &nfc->dev->dev_data,
  28. nfc_mf_classic_emulate_worker_callback,
  29. nfc);
  30. nfc_blink_emulate_start(nfc);
  31. }
  32. bool nfc_scene_mf_classic_emulate_on_event(void* context, SceneManagerEvent event) {
  33. Nfc* nfc = context;
  34. bool consumed = false;
  35. if(event.type == SceneManagerEventTypeBack) {
  36. // Stop worker
  37. nfc_worker_stop(nfc->worker);
  38. // Check if data changed and save in shadow file
  39. if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfClassicEmulate) ==
  40. NFC_MF_CLASSIC_DATA_CHANGED) {
  41. scene_manager_set_scene_state(
  42. nfc->scene_manager, NfcSceneMfClassicEmulate, NFC_MF_CLASSIC_DATA_NOT_CHANGED);
  43. nfc_device_save_shadow(nfc->dev, nfc->dev->dev_name);
  44. }
  45. consumed = false;
  46. }
  47. return consumed;
  48. }
  49. void nfc_scene_mf_classic_emulate_on_exit(void* context) {
  50. Nfc* nfc = context;
  51. // Clear view
  52. popup_reset(nfc->popup);
  53. nfc_blink_stop(nfc);
  54. }