From 0eae6030b0f173ec1e8edc06ce0f7abef06d0bcd Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 30 Jan 2026 21:43:05 +0700 Subject: [PATCH] work to home --- .../scenes/subghz_scene_signal_settings.c | 66 +++++++++++++++---- .../subghz/scenes/subghz_scene_transmitter.c | 61 ++++++++++++++++- lib/subghz/blocks/generic.h | 7 ++ lib/subghz/protocols/alutech_at_4n.c | 2 +- lib/subghz/protocols/ansonic.c | 4 +- 5 files changed, 124 insertions(+), 16 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_signal_settings.c b/applications/main/subghz/scenes/subghz_scene_signal_settings.c index e74219a28..c8a0cf2a6 100644 --- a/applications/main/subghz/scenes/subghz_scene_signal_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_signal_settings.c @@ -11,10 +11,15 @@ static uint32_t counter_mode = 0xff; static uint32_t counter32 = 0x0; static uint16_t counter16 = 0x0; -static uint8_t byte_count = 0; -static uint8_t* byte_ptr = NULL; +static uint8_t cnt_byte_count = 0; +static uint8_t* cnt_byte_ptr = NULL; + static FuriString* byte_input_text; +static uint8_t button = 0x0; +static uint8_t btn_byte_count = 1; +static uint8_t* btn_byte_ptr = NULL; + #define COUNTER_MODE_COUNT 7 static const char* const counter_mode_text[COUNTER_MODE_COUNT] = { "System", @@ -79,8 +84,25 @@ void subghz_scene_signal_settings_variable_item_list_enter_callback(void* contex subghz_scene_signal_settings_byte_input_callback, NULL, subghz, - byte_ptr, - byte_count); + cnt_byte_ptr, + cnt_byte_count); + view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); + } + // when we click OK on "Edit button" item + if(index == 2) { + furi_string_cat_str(byte_input_text, " button number in HEX"); + + // Setup byte_input view + ByteInput* byte_input = subghz->byte_input; + byte_input_set_header_text(byte_input, furi_string_get_cstr(byte_input_text)); + + byte_input_set_result_callback( + byte_input, + subghz_scene_signal_settings_byte_input_callback, + NULL, + subghz, + btn_byte_ptr, + btn_byte_count); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); } } @@ -130,9 +152,10 @@ void subghz_scene_signal_settings_on_enter(void* context) { flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); - // ### Counter edit section ### byte_input_text = furi_string_alloc_set_str("Enter "); bool counter_not_available = true; + bool button_not_available = true; + SubGhzProtocolDecoderBase* decoder = subghz_txrx_get_decoder(subghz->txrx); // deserialaze and decode loaded sugbhz file and push data to subghz_block_generic_global variable @@ -143,6 +166,8 @@ void subghz_scene_signal_settings_on_enter(void* context) { FURI_LOG_E(TAG, "Cant deserialize this subghz file"); } + // ### Counter edit section ### + if(!subghz_block_generic_global.cnt_is_available) { counter_mode = 0xff; FURI_LOG_D(TAG, "Counter mode and edit not available for this protocol"); @@ -155,19 +180,31 @@ void subghz_scene_signal_settings_on_enter(void* context) { counter32 = subghz_block_generic_global.current_cnt; furi_string_printf(tmp_text, "%lX", counter32); counter32 = __bswap32(counter32); - byte_ptr = (uint8_t*)&counter32; - byte_count = 4; + cnt_byte_ptr = (uint8_t*)&counter32; + cnt_byte_count = 4; } else { counter16 = subghz_block_generic_global.current_cnt; furi_string_printf(tmp_text, "%X", counter16); counter16 = __bswap16(counter16); - byte_ptr = (uint8_t*)&counter16; - byte_count = 2; + cnt_byte_ptr = (uint8_t*)&counter16; + cnt_byte_count = 2; } } - furi_assert(byte_ptr); - furi_assert(byte_count > 0); + // ### Button edit section ### + + if(!subghz_block_generic_global.btn_is_available) { + FURI_LOG_D(TAG, "Button edit not available for this protocol"); + } else { + button_not_available = false; + button = subghz_block_generic_global.current_btn; + furi_string_printf(tmp_text, "%X", button); + btn_byte_ptr = (uint8_t*)&button; + } + + furi_assert(cnt_byte_ptr); + furi_assert(cnt_byte_count > 0); + furi_assert(btn_byte_ptr); //Create and Enable/Disable variable_item_list depending on current values VariableItemList* variable_item_list = subghz->variable_item_list; @@ -196,6 +233,11 @@ void subghz_scene_signal_settings_on_enter(void* context) { variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_text)); variable_item_set_locked(item, (counter_not_available), "Not available\nfor this\nprotocol !"); + item = variable_item_list_add(variable_item_list, "Edit Button", 1, NULL, subghz); + variable_item_set_current_value_index(item, 0); + variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_text)); + variable_item_set_locked(item, (button_not_available), "Not available\nfor this\nprotocol !"); + furi_string_free(tmp_text); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList); @@ -206,7 +248,7 @@ bool subghz_scene_signal_settings_on_event(void* context, SceneManagerEvent even if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventByteInputDone) { - switch(byte_count) { + switch(cnt_byte_count) { case 2: // set new cnt value and override_flag to global variable and call transmit to generate and save subghz signal counter16 = __bswap16(counter16); diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index ebd69059f..b27d88da0 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -3,7 +3,14 @@ #include #include +<<<<<<< HEAD +======= +#include + +#include "applications/main/subghz/helpers/subghz_txrx_i.h" +#include "lib/subghz/blocks/generic.h" +>>>>>>> cf35909c8 (work to home) #define TAG "SubGhzSceneTransmitter" void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) { @@ -67,7 +74,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { subghz->state_notifications = SubGhzNotificationStateIDLE; - + FURI_LOG_D("000000", "PRESS"); if(subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { subghz->state_notifications = SubGhzNotificationStateTx; subghz_scene_transmitter_update_data_show(subghz); @@ -75,8 +82,23 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { } return true; } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) { +<<<<<<< HEAD +======= + FURI_LOG_D("111111", "RELEASE"); + + // if 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)) { + subghz_block_generic_global.endless_tx = true; + tx_stop_called = true; + FURI_LOG_D("111111", "STOP CALLED"); + return true; + } + // if hardware TX not working now so just stop TX correctly +>>>>>>> cf35909c8 (work to home) subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); + subghz_block_generic_global.endless_tx = false; 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(); @@ -90,6 +112,8 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { subghz_txrx_stop(subghz->txrx); furi_hal_subghz_set_rolling_counter_mult(tmp_counter); } + FURI_LOG_D("111111", "JUST STOP"); + return true; } else if(event.event == SubGhzCustomEventViewTransmitterBack) { subghz->state_notifications = SubGhzNotificationStateIDLE; @@ -102,7 +126,42 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { } } else if(event.type == SceneManagerEventTypeTick) { if(subghz->state_notifications == SubGhzNotificationStateTx) { +<<<<<<< HEAD notification_message(subghz->notifications, &sequence_blink_magenta_10); +======= + // 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) { + FURI_LOG_D("22222222", "STOP BY CALL"); + + // tx_stop_called = false; + // subghz->state_notifications = SubGhzNotificationStateIDLE; + // subghz_txrx_stop(subghz->txrx); + // // subghz_block_generic_global.endless_tx = false; + // 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; + } + subghz_block_generic_global.endless_tx = true; + FURI_LOG_D("22222222", "ENDELSS TX ON"); + } +>>>>>>> cf35909c8 (work to home) } return true; } diff --git a/lib/subghz/blocks/generic.h b/lib/subghz/blocks/generic.h index 1e72c5a5e..daed68b07 100644 --- a/lib/subghz/blocks/generic.h +++ b/lib/subghz/blocks/generic.h @@ -35,6 +35,13 @@ struct SubGhzBlockGenericGlobal { bool cnt_need_override; // flag for protocols to override signals counter inside of protocols uint8_t cnt_length_bit; // counter length in bytes (used in counter editor giu) bool cnt_is_available; // is there counter available for protocol (used in counter editor giu) + + uint8_t current_btn; // global counter value; + uint8_t new_btn; // global counter value; + bool btn_need_override; // flag for protocols to override signals counter inside of protocols + bool btn_is_available; // is there counter available for protocol (used in counter editor giu) + + bool endless_tx; // used for endless/breakless transmission in subghz protols (when user not release OK button) }; extern SubGhzBlockGenericGlobal subghz_block_generic_global; //global structure for subghz diff --git a/lib/subghz/protocols/alutech_at_4n.c b/lib/subghz/protocols/alutech_at_4n.c index 687a1e930..5ebe1eb43 100644 --- a/lib/subghz/protocols/alutech_at_4n.c +++ b/lib/subghz/protocols/alutech_at_4n.c @@ -135,7 +135,7 @@ LevelDuration subghz_protocol_encoder_alutech_at_4n_yield(void* context) { instance->encoder.repeat--; instance->encoder.front = 0; } - + FURI_LOG_D("ALLLLLLL", "REPEAT - %i ", instance->encoder.repeat); return ret; } diff --git a/lib/subghz/protocols/ansonic.c b/lib/subghz/protocols/ansonic.c index 75f803370..1a9a69828 100644 --- a/lib/subghz/protocols/ansonic.c +++ b/lib/subghz/protocols/ansonic.c @@ -82,7 +82,7 @@ void* subghz_protocol_encoder_ansonic_alloc(SubGhzEnvironment* environment) { instance->base.protocol = &subghz_protocol_ansonic; instance->generic.protocol_name = instance->base.protocol->name; - instance->encoder.repeat = 10; + instance->encoder.repeat = 30; instance->encoder.size_upload = 52; instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration)); instance->encoder.is_running = false; @@ -183,7 +183,7 @@ LevelDuration subghz_protocol_encoder_ansonic_yield(void* context) { instance->encoder.repeat--; instance->encoder.front = 0; } - +FURI_LOG_D("ANNNN", "REPEAT - %i ",instance->encoder.repeat); return ret; }