From 8a85ab88a767ab2777f171de2e45b47195f35b0a Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sun, 25 Jan 2026 22:38:11 +0700 Subject: [PATCH] Home to work --- .../drivers/subghz/cc1101_ext/cc1101_ext.c | 2 - .../scenes/subghz_scene_receiver_info.c | 8 ++ .../subghz/scenes/subghz_scene_transmitter.c | 113 +++++++++++------- applications/main/subghz/views/transmitter.c | 28 ++--- 4 files changed, 85 insertions(+), 66 deletions(-) diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index 40cfe0d4a..adcf785f2 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -98,8 +98,6 @@ typedef struct { static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL; -bool subghz_device_cc1101_ext_is_async_tx_complete(void); - static bool subghz_device_cc1101_ext_check_init(void) { furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateInit); subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle; diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index e68b0203d..a34239f6b 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -2,6 +2,8 @@ #include +#include "applications/main/subghz/helpers/subghz_txrx_i.h" + #define TAG "SubGhzSceneReceiverInfo" void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) { @@ -138,6 +140,12 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) return true; } else if(event.event == SubGhzCustomEventSceneReceiverInfoTxStop) { //CC1101 Stop Tx -> Start RX + // #subghz_one_press_send# - keyword to search changes + // when user release OK button we wait until full data packed will send and later stop TX + while(!subghz_devices_is_async_complete_tx(subghz->txrx->radio_device)) { + notification_message(subghz->notifications, &sequence_blink_magenta_10); + } + //# subghz->state_notifications = SubGhzNotificationStateIDLE; widget_reset(subghz->widget); diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index e7514ac92..65d0c7bc6 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -4,8 +4,13 @@ #include #include + +#include "applications/main/subghz/helpers/subghz_txrx_i.h" + #define TAG "SubGhzSceneTransmitter" +static bool tx_stop_called = false; + void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) { furi_assert(context); SubGhz* subghz = context; @@ -66,26 +71,63 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { + // if we recieve event to start transmission (user press OK button) then start/restart TX subghz->state_notifications = SubGhzNotificationStateIDLE; if(subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { subghz->state_notifications = SubGhzNotificationStateTx; subghz_scene_transmitter_update_data_show(subghz); dolphin_deed(DolphinDeedSubGhzSend); - - // #subghz_one_press_send# - keyword to search changes - // #start insert# - - // TODO change while condition to subghz_devices_is_async_complete_tx(subghz->txrx->radio_device); - // while( - // !(furi_hal_subghz_is_async_tx_complete() && - // subghz_device_cc1101_ext_is_async_tx_complete())) { - // notification_message(subghz->notifications, &sequence_blink_magenta_10); - // } - - while(!furi_hal_subghz_is_async_tx_complete()) { - notification_message(subghz->notifications, &sequence_blink_magenta_10); - } + } + return true; + } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) { + // we recieve event to stop tranmission (user release OK button) but + // hardware TX still working now then set flag to stop it after hardware TX will be realy ended + if(!subghz_devices_is_async_complete_tx(subghz->txrx->radio_device)) { + tx_stop_called = true; + return true; + } + // if hardware TX not working now so just stop TX correctly + subghz->state_notifications = SubGhzNotificationStateIDLE; + subghz_txrx_stop(subghz->txrx); + if(subghz_custom_btn_get() != SUBGHZ_CUSTOM_BTN_OK) { + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); + int32_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); + furi_hal_subghz_set_rolling_counter_mult(0); + // Calling restore! + subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx)); + subghz_txrx_stop(subghz->txrx); + // Calling restore 2nd time special for FAAC SLH! + // TODO: Find better way to restore after custom button is used!!! + subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx)); + subghz_txrx_stop(subghz->txrx); + furi_hal_subghz_set_rolling_counter_mult(tmp_counter); + } + return true; + } else if(event.event == SubGhzCustomEventViewTransmitterBack) { + // if user press back button then force stop TX if they was active + if(subghz->state_notifications == SubGhzNotificationStateTx) { + subghz_txrx_stop(subghz->txrx); + } + subghz->state_notifications = SubGhzNotificationStateIDLE; + scene_manager_search_and_switch_to_previous_scene( + subghz->scene_manager, SubGhzSceneStart); + return true; + } else if(event.event == SubGhzCustomEventViewTransmitterError) { + furi_string_set(subghz->error_str, "Protocol not\nfound!"); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); + } + } else if(event.type == SceneManagerEventTypeTick) { + if(subghz->state_notifications == SubGhzNotificationStateTx) { + // if hardware TX still working at this time so we just blink led and do nothing + if(!subghz_devices_is_async_complete_tx(subghz->txrx->radio_device)) { + notification_message(subghz->notifications, &sequence_blink_magenta_10); + return true; + } + // if hardware TX not working now and tx_stop_called = true + // (mean user release OK button early than hardware TX was ended) then we stop TX + if(tx_stop_called) { + tx_stop_called = false; subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); if(subghz_custom_btn_get() != SUBGHZ_CUSTOM_BTN_OK) { @@ -101,39 +143,18 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { subghz_txrx_stop(subghz->txrx); furi_hal_subghz_set_rolling_counter_mult(tmp_counter); } - // #end insert# + return true; + } else { + // if state_notifications == SubGhzNotificationStateTx but hardware TX was ended + // and user still dont release OK button then we repeat transmission + subghz->state_notifications = SubGhzNotificationStateIDLE; + if(subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { + subghz->state_notifications = SubGhzNotificationStateTx; + subghz_scene_transmitter_update_data_show(subghz); + dolphin_deed(DolphinDeedSubGhzSend); + } + return true; } - return true; - // #subghz_one_press_send# - keyword to search changes - // } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) { - // subghz->state_notifications = SubGhzNotificationStateIDLE; - // subghz_txrx_stop(subghz->txrx); - // if(subghz_custom_btn_get() != SUBGHZ_CUSTOM_BTN_OK) { - // subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); - // int32_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); - // furi_hal_subghz_set_rolling_counter_mult(0); - // // Calling restore! - // subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx)); - // subghz_txrx_stop(subghz->txrx); - // // Calling restore 2nd time special for FAAC SLH! - // // TODO: Find better way to restore after custom button is used!!! - // subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx)); - // subghz_txrx_stop(subghz->txrx); - // furi_hal_subghz_set_rolling_counter_mult(tmp_counter); - // } - // return true; - } else if(event.event == SubGhzCustomEventViewTransmitterBack) { - subghz->state_notifications = SubGhzNotificationStateIDLE; - scene_manager_search_and_switch_to_previous_scene( - subghz->scene_manager, SubGhzSceneStart); - return true; - } else if(event.event == SubGhzCustomEventViewTransmitterError) { - furi_string_set(subghz->error_str, "Protocol not\nfound!"); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); - } - } else if(event.type == SceneManagerEventTypeTick) { - if(subghz->state_notifications == SubGhzNotificationStateTx) { - notification_message(subghz->notifications, &sequence_blink_magenta_10); } return true; } diff --git a/applications/main/subghz/views/transmitter.c b/applications/main/subghz/views/transmitter.c index 455ab63a5..9faa703b6 100644 --- a/applications/main/subghz/views/transmitter.c +++ b/applications/main/subghz/views/transmitter.c @@ -6,9 +6,6 @@ #include -#include -#include - struct SubGhzViewTransmitter { View* view; SubGhzViewTransmitterCallback callback; @@ -158,10 +155,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { true); if(can_be_sent) { - // #subghz_one_press_send# - keyword to search changes - bool allow_events = furi_hal_subghz_is_async_tx_complete() && subghz_device_cc1101_ext_is_async_tx_complete (); - // # - if(event->key == InputKeyOk && event->type == InputTypePress && allow_events) { + if(event->key == InputKeyOk && event->type == InputTypePress) { subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); with_view_model( subghz_transmitter->view, @@ -174,11 +168,10 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { subghz_transmitter->callback( SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); return true; - // #subghz_one_press_send# - keyword to search changes - // } else if(event->key == InputKeyOk && event->type == InputTypeRelease) { - // subghz_transmitter->callback( - // SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - // return true; + } else if(event->key == InputKeyOk && event->type == InputTypeRelease) { + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); + return true; } // Finish "OK" key processing if(subghz_custom_btn_is_allowed()) { @@ -196,7 +189,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { return true; } - if(event->type == InputTypePress && allow_events) { + if(event->type == InputTypePress) { with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, @@ -216,11 +209,10 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { subghz_transmitter->callback( SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); return true; - // #subghz_one_press_send# - keyword to search changes - // } else if(event->type == InputTypeRelease) { - // subghz_transmitter->callback( - // SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - // return true; + } else if(event->type == InputTypeRelease) { + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); + return true; } } }