11#include "../subghz_i.h"
22
33#include <lib/subghz/blocks/custom_btn.h>
4+ #include <lib/subghz/blocks/generic.h>
5+ #include "applications/main/subghz/helpers/subghz_txrx_i.h"
46
57typedef enum {
68 SubGhzRpcStateIdle ,
@@ -52,16 +54,21 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) {
5254 } else if (event .event == SubGhzCustomEventSceneRpcButtonPress ) {
5355 bool result = false;
5456 if (state == SubGhzRpcStateLoaded ) {
57+ // START endless TX until user release button
58+ // variable used in protocol yield for endless TX
59+ subghz_block_generic_global .endless_tx = true;
5560 switch (
5661 subghz_txrx_tx_start (subghz -> txrx , subghz_txrx_get_fff_data (subghz -> txrx ))) {
5762 case SubGhzTxRxStartTxStateErrorOnlyRx :
63+ subghz_block_generic_global .endless_tx = false;
5864 rpc_system_app_set_error_code (
5965 subghz -> rpc_ctx , RpcAppSystemErrorCodeRegionLock );
6066 rpc_system_app_set_error_text (
6167 subghz -> rpc_ctx ,
6268 "Transmission on this frequency is restricted in your settings" );
6369 break ;
6470 case SubGhzTxRxStartTxStateErrorParserOthers :
71+ subghz_block_generic_global .endless_tx = false;
6572 rpc_system_app_set_error_code (
6673 subghz -> rpc_ctx , RpcAppSystemErrorCodeInternalParse );
6774 rpc_system_app_set_error_text (
@@ -80,50 +87,53 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) {
8087 } else if (event .event == SubGhzCustomEventSceneRpcButtonRelease ) {
8188 bool result = false;
8289 if (state == SubGhzRpcStateTx ) {
83- subghz_txrx_stop (subghz -> txrx );
84- subghz_blink_stop (subghz );
90+ // user release button
91+ // set endless TX to OFF and switch off TX in section event.type == SceneManagerEventTypeTick
92+ subghz_block_generic_global .endless_tx = false;
8593 result = true;
8694 }
87- scene_manager_set_scene_state (
88- subghz -> scene_manager , SubGhzSceneRpc , SubGhzRpcStateIdle );
95+ // scene_manager_set_scene_state(
96+ // subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateIdle);
8997 rpc_system_app_confirm (subghz -> rpc_ctx , result );
90- } else if (event .event == SubGhzCustomEventSceneRpcButtonPressRelease ) {
91- bool result = false;
92- if (state == SubGhzRpcStateLoaded ) {
93- switch (
94- subghz_txrx_tx_start (subghz -> txrx , subghz_txrx_get_fff_data (subghz -> txrx ))) {
95- case SubGhzTxRxStartTxStateErrorOnlyRx :
96- rpc_system_app_set_error_code (
97- subghz -> rpc_ctx , RpcAppSystemErrorCodeRegionLock );
98- rpc_system_app_set_error_text (
99- subghz -> rpc_ctx ,
100- "Transmission on this frequency is restricted in your region" );
101- break ;
102- case SubGhzTxRxStartTxStateErrorParserOthers :
103- rpc_system_app_set_error_code (
104- subghz -> rpc_ctx , RpcAppSystemErrorCodeInternalParse );
105- rpc_system_app_set_error_text (
106- subghz -> rpc_ctx , "Error in protocol parameters description" );
107- break ;
10898
109- default : //if(SubGhzTxRxStartTxStateOk)
110- result = true;
111- subghz_blink_start (subghz );
112- scene_manager_set_scene_state (
113- subghz -> scene_manager , SubGhzSceneRpc , SubGhzRpcStateTx );
114- break ;
115- }
116- }
117-
118- // Stop transmission
119- if (state == SubGhzRpcStateTx ) {
120- subghz_txrx_stop (subghz -> txrx );
121- subghz_blink_stop (subghz );
122- result = true;
123- }
124- scene_manager_set_scene_state (
125- subghz -> scene_manager , SubGhzSceneRpc , SubGhzRpcStateIdle );
126- rpc_system_app_confirm (subghz -> rpc_ctx , result );
99+ // USELESS PART
100+ // } else if(event.event == SubGhzCustomEventSceneRpcButtonPressRelease) {
101+ // bool result = false;
102+ // if(state == SubGhzRpcStateLoaded) {
103+ // switch(
104+ // subghz_txrx_tx_start(subghz->txrx, subghz_txrx_get_fff_data(subghz->txrx))) {
105+ // case SubGhzTxRxStartTxStateErrorOnlyRx:
106+ // rpc_system_app_set_error_code(
107+ // subghz->rpc_ctx, RpcAppSystemErrorCodeRegionLock);
108+ // rpc_system_app_set_error_text(
109+ // subghz->rpc_ctx,
110+ // "Transmission on this frequency is restricted in your region");
111+ // break;
112+ // case SubGhzTxRxStartTxStateErrorParserOthers:
113+ // rpc_system_app_set_error_code(
114+ // subghz->rpc_ctx, RpcAppSystemErrorCodeInternalParse);
115+ // rpc_system_app_set_error_text(
116+ // subghz->rpc_ctx, "Error in protocol parameters description");
117+ // break;
118+
119+ // default: //if(SubGhzTxRxStartTxStateOk)
120+ // result = true;
121+ // subghz_blink_start(subghz);
122+ // scene_manager_set_scene_state(
123+ // subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateTx);
124+ // break;
125+ // }
126+ // }
127+
128+ // // Stop transmission
129+ // if(state == SubGhzRpcStateTx) {
130+ // subghz_txrx_stop(subghz->txrx);
131+ // subghz_blink_stop(subghz);
132+ // result = true;
133+ // }
134+ // scene_manager_set_scene_state(
135+ // subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateIdle);
136+ // rpc_system_app_confirm(subghz->rpc_ctx, result);
127137 } else if (event .event == SubGhzCustomEventSceneRpcLoad ) {
128138 bool result = false;
129139 if (state == SubGhzRpcStateIdle ) {
@@ -139,6 +149,19 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) {
139149 }
140150 rpc_system_app_confirm (subghz -> rpc_ctx , result );
141151 }
152+ } else if (event .type == SceneManagerEventTypeTick ) {
153+ // if hardware TX finished then stop TX correctly
154+ if (subghz_devices_is_async_complete_tx (subghz -> txrx -> radio_device )) {
155+ bool result = false;
156+ if (state == SubGhzRpcStateTx ) {
157+ subghz_txrx_stop (subghz -> txrx );
158+ subghz_blink_stop (subghz );
159+ result = true;
160+ }
161+ scene_manager_set_scene_state (
162+ subghz -> scene_manager , SubGhzSceneRpc , SubGhzRpcStateIdle );
163+ rpc_system_app_confirm (subghz -> rpc_ctx , result );
164+ }
142165 }
143166 return consumed ;
144167}
0 commit comments