2022-07-04 13:09:46 +00:00
|
|
|
#include "../subghz_i.h"
|
2023-04-01 18:37:04 +00:00
|
|
|
|
|
|
|
#include <lib/subghz/blocks/custom_btn.h>
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-08-11 15:37:23 +00:00
|
|
|
typedef enum {
|
|
|
|
SubGhzRpcStateIdle,
|
|
|
|
SubGhzRpcStateLoaded,
|
2023-05-09 17:06:22 +00:00
|
|
|
SubGhzRpcStateTx,
|
2022-08-11 15:37:23 +00:00
|
|
|
} SubGhzRpcState;
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
void subghz_scene_rpc_on_enter(void* context) {
|
|
|
|
SubGhz* subghz = context;
|
2022-07-25 14:16:45 +00:00
|
|
|
Popup* popup = subghz->popup;
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-08-11 15:37:23 +00:00
|
|
|
popup_set_header(popup, "Sub-GHz", 89, 42, AlignCenter, AlignBottom);
|
|
|
|
popup_set_text(popup, "RPC mode", 89, 44, AlignCenter, AlignTop);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-08-11 15:37:23 +00:00
|
|
|
popup_set_icon(popup, 0, 12, &I_RFIDDolphinSend_97x61);
|
2022-07-25 14:16:45 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-08-11 15:37:23 +00:00
|
|
|
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateIdle);
|
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
notification_message(subghz->notifications, &sequence_display_backlight_on);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
SubGhz* subghz = context;
|
2022-07-25 14:16:45 +00:00
|
|
|
Popup* popup = subghz->popup;
|
2022-07-04 13:09:46 +00:00
|
|
|
bool consumed = false;
|
2022-08-11 15:37:23 +00:00
|
|
|
SubGhzRpcState state = scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneRpc);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
consumed = true;
|
|
|
|
if(event.event == SubGhzCustomEventSceneExit) {
|
2022-08-11 15:37:23 +00:00
|
|
|
scene_manager_stop(subghz->scene_manager);
|
2022-07-04 13:09:46 +00:00
|
|
|
view_dispatcher_stop(subghz->view_dispatcher);
|
2022-08-02 12:54:12 +00:00
|
|
|
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventAppExit, true);
|
|
|
|
} else if(event.event == SubGhzCustomEventSceneRpcSessionClose) {
|
2022-08-11 15:37:23 +00:00
|
|
|
scene_manager_stop(subghz->scene_manager);
|
|
|
|
view_dispatcher_stop(subghz->view_dispatcher);
|
2022-08-02 12:54:12 +00:00
|
|
|
} else if(event.event == SubGhzCustomEventSceneRpcButtonPress) {
|
|
|
|
bool result = false;
|
2023-05-09 17:06:22 +00:00
|
|
|
if((state == SubGhzRpcStateLoaded)) {
|
2023-05-31 12:59:12 +00:00
|
|
|
switch(
|
|
|
|
subghz_txrx_tx_start(subghz->txrx, subghz_txrx_get_fff_data(subghz->txrx))) {
|
|
|
|
case SubGhzTxRxStartTxStateErrorOnlyRx:
|
|
|
|
rpc_system_app_set_error_code(subghz->rpc_ctx, SubGhzErrorTypeOnlyRX);
|
|
|
|
rpc_system_app_set_error_text(
|
|
|
|
subghz->rpc_ctx,
|
2023-05-31 14:16:24 +00:00
|
|
|
"Transmission on this frequency is restricted in your settings");
|
2023-05-31 12:59:12 +00:00
|
|
|
break;
|
|
|
|
case SubGhzTxRxStartTxStateErrorParserOthers:
|
|
|
|
rpc_system_app_set_error_code(subghz->rpc_ctx, SubGhzErrorTypeParserOthers);
|
|
|
|
rpc_system_app_set_error_text(
|
|
|
|
subghz->rpc_ctx, "Error in protocol parameters description");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: //if(SubGhzTxRxStartTxStateOk)
|
|
|
|
result = true;
|
|
|
|
subghz_blink_start(subghz);
|
|
|
|
state = SubGhzRpcStateTx;
|
|
|
|
break;
|
|
|
|
}
|
2022-12-08 05:49:54 +00:00
|
|
|
}
|
2022-08-02 12:54:12 +00:00
|
|
|
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result);
|
|
|
|
} else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) {
|
|
|
|
bool result = false;
|
2023-05-09 17:06:22 +00:00
|
|
|
if(state == SubGhzRpcStateTx) {
|
2023-05-09 09:07:36 +00:00
|
|
|
subghz_txrx_stop(subghz->txrx);
|
2022-08-02 12:54:12 +00:00
|
|
|
subghz_blink_stop(subghz);
|
|
|
|
result = true;
|
|
|
|
}
|
2023-05-31 12:59:12 +00:00
|
|
|
state = SubGhzRpcStateIdle;
|
2022-08-02 12:54:12 +00:00
|
|
|
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonRelease, result);
|
2022-07-25 14:16:45 +00:00
|
|
|
} else if(event.event == SubGhzCustomEventSceneRpcLoad) {
|
2022-08-02 12:54:12 +00:00
|
|
|
bool result = false;
|
|
|
|
const char* arg = rpc_system_app_get_data(subghz->rpc_ctx);
|
2022-08-11 15:37:23 +00:00
|
|
|
if(arg && (state == SubGhzRpcStateIdle)) {
|
2022-08-02 12:54:12 +00:00
|
|
|
if(subghz_key_load(subghz, arg, false)) {
|
2022-08-11 15:37:23 +00:00
|
|
|
scene_manager_set_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateLoaded);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(subghz->file_path, arg);
|
2022-08-02 12:54:12 +00:00
|
|
|
result = true;
|
2023-05-05 00:51:16 +00:00
|
|
|
FuriString* file_name = furi_string_alloc();
|
2022-08-02 12:54:12 +00:00
|
|
|
path_extract_filename(subghz->file_path, file_name, true);
|
|
|
|
|
|
|
|
snprintf(
|
|
|
|
subghz->file_name_tmp,
|
|
|
|
SUBGHZ_MAX_LEN_NAME,
|
|
|
|
"loaded\n%s",
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(file_name));
|
2022-08-11 15:37:23 +00:00
|
|
|
popup_set_text(popup, subghz->file_name_tmp, 89, 44, AlignCenter, AlignTop);
|
2022-08-02 12:54:12 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(file_name);
|
2022-12-08 05:49:54 +00:00
|
|
|
} else {
|
|
|
|
rpc_system_app_set_error_code(subghz->rpc_ctx, SubGhzErrorTypeParseFile);
|
|
|
|
rpc_system_app_set_error_text(subghz->rpc_ctx, "Cannot parse file");
|
2022-08-02 12:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventLoadFile, result);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_scene_rpc_on_exit(void* context) {
|
|
|
|
SubGhz* subghz = context;
|
2022-08-11 15:37:23 +00:00
|
|
|
|
2023-05-09 17:06:22 +00:00
|
|
|
SubGhzRpcState state = scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneRpc);
|
2023-05-31 12:59:12 +00:00
|
|
|
if(state == SubGhzRpcStateTx) {
|
2023-05-09 09:07:36 +00:00
|
|
|
subghz_txrx_stop(subghz->txrx);
|
2022-08-11 15:37:23 +00:00
|
|
|
subghz_blink_stop(subghz);
|
|
|
|
}
|
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
Popup* popup = subghz->popup;
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
|
|
|
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
|
|
|
popup_set_icon(popup, 0, 0, NULL);
|
2022-10-03 15:21:18 +00:00
|
|
|
|
2023-05-30 19:21:47 +00:00
|
|
|
subghz_txrx_reset_dynamic_and_custom_btns(subghz->txrx);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|