nfc_scene_rpc.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "../nfc_i.h"
  2. void nfc_scene_rpc_on_enter(void* context) {
  3. Nfc* nfc = context;
  4. Popup* popup = nfc->popup;
  5. popup_set_header(popup, "NFC", 89, 42, AlignCenter, AlignBottom);
  6. popup_set_text(popup, "RPC mode", 89, 44, AlignCenter, AlignTop);
  7. popup_set_icon(popup, 0, 12, &I_NFC_dolphin_emulation_47x61);
  8. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  9. notification_message(nfc->notifications, &sequence_display_backlight_on);
  10. }
  11. static bool nfc_scene_rpc_emulate_callback(NfcWorkerEvent event, void* context) {
  12. UNUSED(event);
  13. Nfc* nfc = context;
  14. nfc->rpc_state = NfcRpcStateEmulated;
  15. return true;
  16. }
  17. bool nfc_scene_rpc_on_event(void* context, SceneManagerEvent event) {
  18. Nfc* nfc = context;
  19. Popup* popup = nfc->popup;
  20. bool consumed = false;
  21. if(event.type == SceneManagerEventTypeCustom) {
  22. consumed = true;
  23. if(event.event == NfcCustomEventViewExit) {
  24. rpc_system_app_confirm(nfc->rpc_ctx, RpcAppEventAppExit, true);
  25. scene_manager_stop(nfc->scene_manager);
  26. view_dispatcher_stop(nfc->view_dispatcher);
  27. } else if(event.event == NfcCustomEventRpcSessionClose) {
  28. scene_manager_stop(nfc->scene_manager);
  29. view_dispatcher_stop(nfc->view_dispatcher);
  30. } else if(event.event == NfcCustomEventRpcLoad) {
  31. bool result = false;
  32. const char* arg = rpc_system_app_get_data(nfc->rpc_ctx);
  33. if((arg) && (nfc->rpc_state == NfcRpcStateIdle)) {
  34. if(nfc_device_load(nfc->dev, arg, false)) {
  35. if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
  36. nfc_worker_start(
  37. nfc->worker,
  38. NfcWorkerStateMfUltralightEmulate,
  39. &nfc->dev->dev_data,
  40. nfc_scene_rpc_emulate_callback,
  41. nfc);
  42. } else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
  43. nfc_worker_start(
  44. nfc->worker,
  45. NfcWorkerStateMfClassicEmulate,
  46. &nfc->dev->dev_data,
  47. nfc_scene_rpc_emulate_callback,
  48. nfc);
  49. } else {
  50. nfc_worker_start(
  51. nfc->worker, NfcWorkerStateUidEmulate, &nfc->dev->dev_data, NULL, nfc);
  52. }
  53. nfc->rpc_state = NfcRpcStateEmulating;
  54. result = true;
  55. nfc_blink_emulate_start(nfc);
  56. nfc_text_store_set(nfc, "emulating\n%s", nfc->dev->dev_name);
  57. popup_set_text(popup, nfc->text_store, 89, 44, AlignCenter, AlignTop);
  58. }
  59. }
  60. rpc_system_app_confirm(nfc->rpc_ctx, RpcAppEventLoadFile, result);
  61. }
  62. }
  63. return consumed;
  64. }
  65. void nfc_scene_rpc_on_exit(void* context) {
  66. Nfc* nfc = context;
  67. Popup* popup = nfc->popup;
  68. nfc_blink_stop(nfc);
  69. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  70. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  71. popup_set_icon(popup, 0, 0, NULL);
  72. }