seos_scene_emulate.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. }
  39. return consumed;
  40. }
  41. void seos_scene_emulate_on_exit(void* context) {
  42. Seos* seos = context;
  43. if(seos->listener) {
  44. nfc_listener_stop(seos->listener);
  45. nfc_listener_free(seos->listener);
  46. seos->listener = NULL;
  47. }
  48. // Clear view
  49. popup_reset(seos->popup);
  50. seos_blink_stop(seos);
  51. }