seos_scene_emulate.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "../seos_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define TAG "SeosSceneEmulate"
  4. void seos_scene_emulate_on_enter(void* context) {
  5. Seos* seos = context;
  6. dolphin_deed(DolphinDeedNfcEmulate);
  7. // Setup view
  8. Popup* popup = seos->popup;
  9. popup_set_header(popup, "Emulating", 68, 30, AlignLeft, AlignTop);
  10. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  11. nfc_device_load(seos->nfc_device, APP_ASSETS_PATH("seos.nfc"));
  12. FURI_LOG_I(TAG, "file loaded");
  13. const Iso14443_4aData* data = nfc_device_get_data(seos->nfc_device, NfcProtocolIso14443_4a);
  14. seos->listener = nfc_listener_alloc(seos->nfc, NfcProtocolIso14443_4a, data);
  15. nfc_listener_start(seos->listener, seos_worker_listener_callback, seos);
  16. seos_blink_start(seos);
  17. view_dispatcher_switch_to_view(seos->view_dispatcher, SeosViewPopup);
  18. }
  19. bool seos_scene_emulate_on_event(void* context, SceneManagerEvent event) {
  20. Seos* seos = context;
  21. Popup* popup = seos->popup;
  22. bool consumed = false;
  23. if(event.type == SceneManagerEventTypeCustom) {
  24. if(event.event == SeosCustomEventEmulate) {
  25. popup_set_header(popup, "Emulating", 68, 30, AlignLeft, AlignTop);
  26. } else if(event.event == SeosCustomEventAIDSelected) {
  27. popup_set_header(popup, "AID\nSelected", 68, 30, AlignLeft, AlignTop);
  28. consumed = true;
  29. } else if(event.event == SeosCustomEventADFMatched) {
  30. popup_set_header(popup, "ADF\nMatched", 68, 30, AlignLeft, AlignTop);
  31. consumed = true;
  32. } else if(event.event == SeosCustomEventAuthenticated) {
  33. popup_set_header(popup, "Auth'd", 68, 30, AlignLeft, AlignTop);
  34. consumed = true;
  35. } else if(event.event == SeosCustomEventSIORequested) {
  36. popup_set_header(popup, "SIO\nRequested", 68, 30, AlignLeft, AlignTop);
  37. consumed = true;
  38. }
  39. } else if(event.type == SceneManagerEventTypeBack) {
  40. scene_manager_search_and_switch_to_previous_scene(seos->scene_manager, SeosSceneSavedMenu);
  41. consumed = true;
  42. }
  43. return consumed;
  44. }
  45. void seos_scene_emulate_on_exit(void* context) {
  46. Seos* seos = context;
  47. if(seos->listener) {
  48. nfc_listener_stop(seos->listener);
  49. nfc_listener_free(seos->listener);
  50. seos->listener = NULL;
  51. }
  52. // Clear view
  53. popup_reset(seos->popup);
  54. seos_blink_stop(seos);
  55. }