nfc_scene_emulate_mifare_ul.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define NFC_MF_UL_DATA_NOT_CHANGED (0UL)
  4. #define NFC_MF_UL_DATA_CHANGED (1UL)
  5. void nfc_emulate_mifare_ul_worker_callback(NfcWorkerEvent event, void* context) {
  6. Nfc* nfc = context;
  7. scene_manager_set_scene_state(
  8. nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_DATA_CHANGED);
  9. }
  10. void nfc_scene_emulate_mifare_ul_on_enter(void* context) {
  11. Nfc* nfc = context;
  12. DOLPHIN_DEED(DolphinDeedNfcEmulate);
  13. // Setup view
  14. Popup* popup = nfc->popup;
  15. if(strcmp(nfc->dev->dev_name, "")) {
  16. nfc_text_store_set(nfc, "%s", nfc->dev->dev_name);
  17. }
  18. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  19. popup_set_header(popup, "Emulating\nMf Ultralight", 56, 31, AlignLeft, AlignTop);
  20. // Setup and start worker
  21. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  22. nfc_worker_start(
  23. nfc->worker,
  24. NfcWorkerStateEmulateMifareUltralight,
  25. &nfc->dev->dev_data,
  26. nfc_emulate_mifare_ul_worker_callback,
  27. nfc);
  28. }
  29. bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent event) {
  30. Nfc* nfc = context;
  31. bool consumed = false;
  32. if(event.type == SceneManagerEventTypeTick) {
  33. notification_message(nfc->notifications, &sequence_blink_blue_10);
  34. consumed = true;
  35. } else 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, NfcSceneEmulateMifareUl) ==
  40. NFC_MF_UL_DATA_CHANGED) {
  41. scene_manager_set_scene_state(
  42. nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_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_emulate_mifare_ul_on_exit(void* context) {
  50. Nfc* nfc = context;
  51. // Clear view
  52. popup_reset(nfc->popup);
  53. }