nfc_scene_emulate_mifare_ul.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. UNUSED(event);
  7. Nfc* nfc = context;
  8. scene_manager_set_scene_state(
  9. nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_DATA_CHANGED);
  10. }
  11. void nfc_scene_emulate_mifare_ul_on_enter(void* context) {
  12. Nfc* nfc = context;
  13. DOLPHIN_DEED(DolphinDeedNfcEmulate);
  14. // Setup view
  15. Popup* popup = nfc->popup;
  16. if(strcmp(nfc->dev->dev_name, "")) {
  17. nfc_text_store_set(nfc, "%s", nfc->dev->dev_name);
  18. }
  19. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  20. popup_set_header(popup, "Emulating\nMf Ultralight", 56, 31, AlignLeft, AlignTop);
  21. // Setup and start worker
  22. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  23. nfc_worker_start(
  24. nfc->worker,
  25. NfcWorkerStateEmulateMifareUltralight,
  26. &nfc->dev->dev_data,
  27. nfc_emulate_mifare_ul_worker_callback,
  28. nfc);
  29. }
  30. bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent event) {
  31. Nfc* nfc = context;
  32. bool consumed = false;
  33. if(event.type == SceneManagerEventTypeTick) {
  34. notification_message(nfc->notifications, &sequence_blink_blue_10);
  35. consumed = true;
  36. } else 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, NfcSceneEmulateMifareUl) ==
  41. NFC_MF_UL_DATA_CHANGED) {
  42. scene_manager_set_scene_state(
  43. nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_DATA_NOT_CHANGED);
  44. nfc_device_save_shadow(nfc->dev, nfc->dev->dev_name);
  45. }
  46. consumed = false;
  47. }
  48. return consumed;
  49. }
  50. void nfc_scene_emulate_mifare_ul_on_exit(void* context) {
  51. Nfc* nfc = context;
  52. // Clear view
  53. popup_reset(nfc->popup);
  54. }