seos_scene_emulate.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. const Iso14443_4aData* data = nfc_device_get_data(seos->nfc_device, NfcProtocolIso14443_4a);
  13. seos->listener = nfc_listener_alloc(seos->nfc, NfcProtocolIso14443_4a, data);
  14. nfc_listener_start(seos->listener, seos_worker_listener_callback, seos);
  15. seos_blink_start(seos);
  16. view_dispatcher_switch_to_view(seos->view_dispatcher, SeosViewPopup);
  17. }
  18. bool seos_scene_emulate_on_event(void* context, SceneManagerEvent event) {
  19. Seos* seos = context;
  20. Popup* popup = seos->popup;
  21. bool consumed = false;
  22. if(event.type == SceneManagerEventTypeCustom) {
  23. if(event.event == SeosCustomEventEmulate) {
  24. popup_set_header(popup, "Emulating", 68, 30, AlignLeft, AlignTop);
  25. } else if(event.event == SeosCustomEventAIDSelected) {
  26. popup_set_header(popup, "AID\nSelected", 68, 30, AlignLeft, AlignTop);
  27. consumed = true;
  28. } else if(event.event == SeosCustomEventADFMatched) {
  29. popup_set_header(popup, "ADF\nMatched", 68, 30, AlignLeft, AlignTop);
  30. consumed = true;
  31. } else if(event.event == SeosCustomEventAuthenticated) {
  32. popup_set_header(popup, "Auth'd", 68, 30, AlignLeft, AlignTop);
  33. consumed = true;
  34. } else if(event.event == SeosCustomEventSIORequested) {
  35. popup_set_header(popup, "SIO\nRequested", 68, 30, AlignLeft, AlignTop);
  36. consumed = true;
  37. }
  38. } else if(event.type == SceneManagerEventTypeBack) {
  39. scene_manager_search_and_switch_to_previous_scene(seos->scene_manager, SeosSceneSavedMenu);
  40. consumed = true;
  41. }
  42. return consumed;
  43. }
  44. void seos_scene_emulate_on_exit(void* context) {
  45. Seos* seos = context;
  46. if(seos->listener) {
  47. nfc_listener_stop(seos->listener);
  48. nfc_listener_free(seos->listener);
  49. seos->listener = NULL;
  50. }
  51. // Clear view
  52. popup_reset(seos->popup);
  53. seos_blink_stop(seos);
  54. }