nfc_scene_rpc.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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", 82, 28, AlignCenter, AlignBottom);
  6. popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);
  7. popup_set_icon(popup, 2, 14, &I_Warning_30x23); // TODO: icon
  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. view_dispatcher_stop(nfc->view_dispatcher);
  26. nfc_blink_stop(nfc);
  27. } else if(event.event == NfcCustomEventRpcSessionClose) {
  28. rpc_system_app_set_callback(nfc->rpc_ctx, NULL, NULL);
  29. nfc->rpc_ctx = NULL;
  30. view_dispatcher_stop(nfc->view_dispatcher);
  31. nfc_blink_stop(nfc);
  32. } else if(event.event == NfcCustomEventRpcLoad) {
  33. bool result = false;
  34. const char* arg = rpc_system_app_get_data(nfc->rpc_ctx);
  35. if((arg) && (nfc->rpc_state == NfcRpcStateIdle)) {
  36. if(nfc_device_load(nfc->dev, arg, false)) {
  37. if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
  38. nfc_worker_start(
  39. nfc->worker,
  40. NfcWorkerStateMfUltralightEmulate,
  41. &nfc->dev->dev_data,
  42. nfc_scene_rpc_emulate_callback,
  43. nfc);
  44. } else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
  45. nfc_worker_start(
  46. nfc->worker,
  47. NfcWorkerStateMfClassicEmulate,
  48. &nfc->dev->dev_data,
  49. nfc_scene_rpc_emulate_callback,
  50. nfc);
  51. } else {
  52. nfc_worker_start(
  53. nfc->worker, NfcWorkerStateUidEmulate, &nfc->dev->dev_data, NULL, nfc);
  54. }
  55. nfc->rpc_state = NfcRpcStateEmulating;
  56. result = true;
  57. nfc_blink_start(nfc);
  58. nfc_text_store_set(nfc, "emulating\n%s", nfc->dev->dev_name);
  59. popup_set_text(popup, nfc->text_store, 82, 32, AlignCenter, AlignTop);
  60. }
  61. }
  62. rpc_system_app_confirm(nfc->rpc_ctx, RpcAppEventLoadFile, result);
  63. }
  64. }
  65. return consumed;
  66. }
  67. void nfc_scene_rpc_on_exit(void* context) {
  68. Nfc* nfc = context;
  69. Popup* popup = nfc->popup;
  70. nfc_blink_stop(nfc);
  71. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  72. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  73. popup_set_icon(popup, 0, 0, NULL);
  74. }