nfc_scene_emulate_mifare_ul.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 = (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 = (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. NfcWorkerStateEmulateMifareUl,
  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 = (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 = (Nfc*)context;
  51. // Clear view
  52. Popup* popup = nfc->popup;
  53. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  54. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  55. popup_set_icon(popup, 0, 0, NULL);
  56. }