nfc_scene_mf_classic_emulate.c 2.0 KB

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