subghz_scene_rpc.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "../subghz_i.h"
  2. typedef enum {
  3. SubGhzRpcStateIdle,
  4. SubGhzRpcStateLoaded,
  5. } SubGhzRpcState;
  6. void subghz_scene_rpc_on_enter(void* context) {
  7. SubGhz* subghz = context;
  8. Popup* popup = subghz->popup;
  9. popup_set_header(popup, "Sub-GHz", 89, 42, AlignCenter, AlignBottom);
  10. popup_set_text(popup, "RPC mode", 89, 44, AlignCenter, AlignTop);
  11. popup_set_icon(popup, 0, 12, &I_RFIDDolphinSend_97x61);
  12. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
  13. scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateIdle);
  14. notification_message(subghz->notifications, &sequence_display_backlight_on);
  15. }
  16. bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) {
  17. SubGhz* subghz = context;
  18. Popup* popup = subghz->popup;
  19. bool consumed = false;
  20. SubGhzRpcState state = scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneRpc);
  21. if(event.type == SceneManagerEventTypeCustom) {
  22. consumed = true;
  23. if(event.event == SubGhzCustomEventSceneExit) {
  24. scene_manager_stop(subghz->scene_manager);
  25. view_dispatcher_stop(subghz->view_dispatcher);
  26. rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventAppExit, true);
  27. } else if(event.event == SubGhzCustomEventSceneRpcSessionClose) {
  28. scene_manager_stop(subghz->scene_manager);
  29. view_dispatcher_stop(subghz->view_dispatcher);
  30. } else if(event.event == SubGhzCustomEventSceneRpcButtonPress) {
  31. bool result = false;
  32. if((subghz->txrx->txrx_state == SubGhzTxRxStateSleep) &&
  33. (state == SubGhzRpcStateLoaded)) {
  34. result = subghz_tx_start(subghz, subghz->txrx->fff_data);
  35. if(result) subghz_blink_start(subghz);
  36. }
  37. if(!result) {
  38. rpc_system_app_set_error_code(subghz->rpc_ctx, SubGhzErrorTypeOnlyRX);
  39. rpc_system_app_set_error_text(
  40. subghz->rpc_ctx,
  41. "Transmission on this frequency is restricted in your region");
  42. }
  43. rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result);
  44. } else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) {
  45. bool result = false;
  46. if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
  47. subghz_blink_stop(subghz);
  48. subghz_tx_stop(subghz);
  49. subghz_sleep(subghz);
  50. result = true;
  51. }
  52. rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonRelease, result);
  53. } else if(event.event == SubGhzCustomEventSceneRpcLoad) {
  54. bool result = false;
  55. const char* arg = rpc_system_app_get_data(subghz->rpc_ctx);
  56. if(arg && (state == SubGhzRpcStateIdle)) {
  57. if(subghz_key_load(subghz, arg, false)) {
  58. scene_manager_set_scene_state(
  59. subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateLoaded);
  60. furi_string_set(subghz->file_path, arg);
  61. result = true;
  62. FuriString* file_name;
  63. file_name = furi_string_alloc();
  64. path_extract_filename(subghz->file_path, file_name, true);
  65. snprintf(
  66. subghz->file_name_tmp,
  67. SUBGHZ_MAX_LEN_NAME,
  68. "loaded\n%s",
  69. furi_string_get_cstr(file_name));
  70. popup_set_text(popup, subghz->file_name_tmp, 89, 44, AlignCenter, AlignTop);
  71. furi_string_free(file_name);
  72. } else {
  73. rpc_system_app_set_error_code(subghz->rpc_ctx, SubGhzErrorTypeParseFile);
  74. rpc_system_app_set_error_text(subghz->rpc_ctx, "Cannot parse file");
  75. }
  76. }
  77. rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventLoadFile, result);
  78. }
  79. }
  80. return consumed;
  81. }
  82. void subghz_scene_rpc_on_exit(void* context) {
  83. SubGhz* subghz = context;
  84. if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
  85. subghz_tx_stop(subghz);
  86. subghz_sleep(subghz);
  87. subghz_blink_stop(subghz);
  88. }
  89. Popup* popup = subghz->popup;
  90. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  91. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  92. popup_set_icon(popup, 0, 0, NULL);
  93. }