btn_is_available = true

This commit is contained in:
Dmitry422
2026-02-02 01:22:39 +07:00
parent 0eae6030b0
commit 1d32d1de5c
61 changed files with 675 additions and 332 deletions

View File

@@ -2,6 +2,9 @@
#include <lib/subghz/blocks/custom_btn.h>
#include "applications/main/subghz/helpers/subghz_txrx_i.h"
#include <lib/subghz/blocks/generic.h>
#define TAG "SubGhzSceneReceiverInfo"
void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
@@ -133,25 +136,22 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
subghz_txrx_hopper_unpause(subghz->txrx);
subghz->state_notifications = SubGhzNotificationStateRx;
} else {
// key concept: we start endless TX until user release OK button, and after this we send last
// protocols repeats - this guarantee that one press OK will
// be guarantee send the required minimum protocol data packets
// for all of this we use subghz_block_generic_global.endless_tx in protocols _yield function.
subghz->state_notifications = SubGhzNotificationStateTx;
subghz_block_generic_global.endless_tx = true;
}
return true;
} else if(event.event == SubGhzCustomEventSceneReceiverInfoTxStop) {
//CC1101 Stop Tx -> Start RX
//CC1101 Stop Tx -> next tick event Start RX
// user release OK
// we switch off endless_tx - that mean protocols yield finish endless transmission,
// send upload "repeat=xx" times, and after will be stoped by the tick event down in this code
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz_block_generic_global.endless_tx = false;
widget_reset(subghz->widget);
subghz_scene_receiver_info_draw_widget(subghz);
subghz_txrx_stop(subghz->txrx);
if(!scene_manager_has_previous_scene(subghz->scene_manager, SubGhzSceneDecodeRAW)) {
subghz_txrx_rx_start(subghz->txrx);
subghz_txrx_hopper_unpause(subghz->txrx);
if(!subghz_history_get_text_space_left(subghz->history, NULL)) {
subghz->state_notifications = SubGhzNotificationStateRx;
}
}
return true;
} else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) {
//CC1101 Stop RX -> Save
@@ -188,6 +188,25 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
notification_message(subghz->notifications, &sequence_blink_green_100);
subghz->state_notifications = SubGhzNotificationStateRx;
break;
case SubGhzNotificationStateIDLE:
// we wait until hardware TX finished and after stop TX and start RX, else just blink led
if(!subghz_devices_is_async_complete_tx(subghz->txrx->radio_device)) {
notification_message(subghz->notifications, &sequence_blink_magenta_10);
} else {
subghz_txrx_stop(subghz->txrx);
// update screen
widget_reset(subghz->widget);
subghz_scene_receiver_info_draw_widget(subghz);
if(!scene_manager_has_previous_scene(subghz->scene_manager, SubGhzSceneDecodeRAW)) {
subghz_txrx_rx_start(subghz->txrx);
subghz_txrx_hopper_unpause(subghz->txrx);
if(!subghz_history_get_text_space_left(subghz->history, NULL)) {
subghz->state_notifications = SubGhzNotificationStateRx;
}
}
}
break;
default:
break;
}

View File

@@ -20,6 +20,8 @@ static uint8_t button = 0x0;
static uint8_t btn_byte_count = 1;
static uint8_t* btn_byte_ptr = NULL;
static uint8_t submenu_called = 0;
#define COUNTER_MODE_COUNT 7
static const char* const counter_mode_text[COUNTER_MODE_COUNT] = {
"System",
@@ -72,6 +74,7 @@ void subghz_scene_signal_settings_variable_item_list_enter_callback(void* contex
// when we click OK on "Edit counter" item
if(index == 1) {
submenu_called = 1;
furi_string_cat_printf(byte_input_text, "%i", subghz_block_generic_global.cnt_length_bit);
furi_string_cat_str(byte_input_text, "-bits counter in HEX");
@@ -90,7 +93,9 @@ void subghz_scene_signal_settings_variable_item_list_enter_callback(void* contex
}
// when we click OK on "Edit button" item
if(index == 2) {
furi_string_cat_str(byte_input_text, " button number in HEX");
submenu_called = 2;
furi_string_cat_printf(byte_input_text, "%i", subghz_block_generic_global.btn_length_bit);
furi_string_cat_str(byte_input_text, "-bits button in HEX");
// Setup byte_input view
ByteInput* byte_input = subghz->byte_input;
@@ -156,6 +161,28 @@ void subghz_scene_signal_settings_on_enter(void* context) {
bool counter_not_available = true;
bool button_not_available = true;
//Create and Enable/Disable variable_item_list depending on current values
VariableItemList* variable_item_list = subghz->variable_item_list;
int32_t value_index;
VariableItem* item;
variable_item_list_set_enter_callback(
variable_item_list,
subghz_scene_signal_settings_variable_item_list_enter_callback,
subghz);
item = variable_item_list_add(
variable_item_list,
"Counter Mode",
mode_count,
subghz_scene_signal_settings_counter_mode_changed,
subghz);
value_index = value_index_int32(counter_mode, counter_mode_value, mode_count);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, counter_mode_text[value_index]);
variable_item_set_locked(item, (counter_mode == 0xff), "Not available\nfor this\nprotocol !");
//
SubGhzProtocolDecoderBase* decoder = subghz_txrx_get_decoder(subghz->txrx);
// deserialaze and decode loaded sugbhz file and push data to subghz_block_generic_global variable
@@ -191,6 +218,12 @@ void subghz_scene_signal_settings_on_enter(void* context) {
}
}
item = variable_item_list_add(variable_item_list, "Edit Counter", 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, (counter_not_available), "Not available\nfor this\nprotocol !");
//
// ### Button edit section ###
if(!subghz_block_generic_global.btn_is_available) {
@@ -202,41 +235,15 @@ void subghz_scene_signal_settings_on_enter(void* context) {
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;
int32_t value_index;
VariableItem* item;
variable_item_list_set_enter_callback(
variable_item_list,
subghz_scene_signal_settings_variable_item_list_enter_callback,
subghz);
item = variable_item_list_add(
variable_item_list,
"Counter Mode",
mode_count,
subghz_scene_signal_settings_counter_mode_changed,
subghz);
value_index = value_index_int32(counter_mode, counter_mode_value, mode_count);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, counter_mode_text[value_index]);
variable_item_set_locked(item, (counter_mode == 0xff), "Not available\nfor this\nprotocol !");
item = variable_item_list_add(variable_item_list, "Edit Counter", 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, (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_assert(cnt_byte_ptr);
furi_assert(cnt_byte_count > 0);
furi_assert(btn_byte_ptr);
furi_string_free(tmp_text);
@@ -248,21 +255,40 @@ bool subghz_scene_signal_settings_on_event(void* context, SceneManagerEvent even
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventByteInputDone) {
switch(cnt_byte_count) {
switch(submenu_called) {
// edit counter
case 1:
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);
subghz_block_generic_global_counter_override_set(counter16);
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
subghz_txrx_stop(subghz->txrx);
break;
case 4:
// the same for 32 bit Counter
counter32 = __bswap32(counter32);
subghz_block_generic_global_counter_override_set(counter32);
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
subghz_txrx_stop(subghz->txrx);
break;
default:
break;
}
break;
// edit button
case 2:
// set new cnt value and override_flag to global variable and call transmit to generate and save subghz signal
counter16 = __bswap16(counter16);
subghz_block_generic_global_counter_override_set(counter16);
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
subghz_txrx_stop(subghz->txrx);
break;
case 4:
// the same for 32 bit Counter
counter32 = __bswap32(counter32);
subghz_block_generic_global_counter_override_set(counter32);
subghz_block_generic_global_button_override_set(button);
// save counter mult to rewrite subghz singnal without changing counter
int32_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult();
furi_hal_subghz_set_rolling_counter_mult(0);
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
subghz_txrx_stop(subghz->txrx);
// restore counter mult
furi_hal_subghz_set_rolling_counter_mult(tmp_counter);
break;
default:
break;
}

View File

@@ -3,14 +3,11 @@
#include <dolphin/dolphin.h>
#include <lib/subghz/blocks/custom_btn.h>
<<<<<<< HEAD
=======
#include <lib/subghz/devices/devices.c>
#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) {
@@ -70,11 +67,16 @@ void subghz_scene_transmitter_on_enter(void* context) {
}
bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
// key concept: we start endless TX until user release OK button, and after this we send last
// protocols repeats - this guarantee that one press OK will
// be guarantee send the required minimum protocol data packets
// for all of this we use subghz_block_generic_global.endless_tx in protocols _yield function.
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventViewTransmitterSendStart) {
// user press OK - start endless TX
subghz->state_notifications = SubGhzNotificationStateIDLE;
FURI_LOG_D("000000", "PRESS");
subghz_block_generic_global.endless_tx = true;
if(subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) {
subghz->state_notifications = SubGhzNotificationStateTx;
subghz_scene_transmitter_update_data_show(subghz);
@@ -82,41 +84,12 @@ 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);
// user release OK
// we switch off endless_tx - that mean protocols yield finish endless transmission,
// send upload "repeat=xx" times, and after will be stoped by tick event down this code.
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);
}
FURI_LOG_D("111111", "JUST STOP");
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;
@@ -126,42 +99,28 @@ 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 hardware TX still working at this time so we just blink led and return
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;
// if hardware TX was stoped so we stop TX correctly
} else {
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);
}
subghz_block_generic_global.endless_tx = true;
FURI_LOG_D("22222222", "ENDELSS TX ON");
}
>>>>>>> cf35909c8 (work to home)
}
return true;
}