SubGhz: refactoring

This commit is contained in:
gid9798 2023-05-09 15:11:54 +03:00
parent f71900694b
commit 07203f0989
14 changed files with 162 additions and 127 deletions

View file

@ -278,7 +278,7 @@ SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* cont
furi_thread_set_callback(instance->thread, subghz_frequency_analyzer_worker_thread);
SubGhz* subghz = context;
instance->setting = subghz->txrx->setting;
instance->setting = subghz_txrx_get_setting(subghz->txrx);
instance->trigger_level = subghz->last_settings->frequency_analyzer_trigger;
//instance->trigger_level = SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD;
return instance;

View file

@ -25,7 +25,7 @@
static void subghz_scene_receiver_update_statusbar(void* context) {
SubGhz* subghz = context;
FuriString* history_stat_str = furi_string_alloc();
if(!subghz_history_get_text_space_left(subghz->txrx->history, history_stat_str)) {
if(!subghz_history_get_text_space_left(subghz->history, history_stat_str)) {
FuriString* frequency_str = furi_string_alloc();
FuriString* modulation_str = furi_string_alloc();
@ -60,21 +60,22 @@ static void subghz_scene_add_to_history_callback(
SubGhz* subghz = context;
FuriString* item_name = furi_string_alloc();
FuriString* item_time = furi_string_alloc();
uint16_t idx = subghz_history_get_item(subghz->txrx->history);
uint16_t idx = subghz_history_get_item(subghz->history);
SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx);
if(subghz_history_add_to_history(subghz->txrx->history, decoder_base, subghz->txrx->preset)) {
if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) {
furi_string_reset(item_name);
furi_string_reset(item_time);
subghz->state_notifications = SubGhzNotificationStateRxDone;
subghz_history_get_text_item_menu(subghz->txrx->history, item_name, idx);
subghz_history_get_time_item_menu(subghz->txrx->history, item_time, idx);
subghz_history_get_text_item_menu(subghz->history, item_name, idx);
subghz_history_get_time_item_menu(subghz->history, item_time, idx);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(subghz->txrx->history, idx));
subghz_history_get_type_protocol(subghz->history, idx));
subghz_scene_receiver_update_statusbar(subghz);
}
@ -173,7 +174,7 @@ void subghz_scene_decode_raw_on_enter(void* context) {
if(subghz->decode_raw_state == SubGhzDecodeRawStateStart) {
//Decode RAW to history
subghz_history_reset(subghz->txrx->history);
subghz_history_reset(subghz->history);
if(subghz_scene_decode_raw_start(subghz)) {
subghz->decode_raw_state = SubGhzDecodeRawStateLoading;
subghz->state_notifications = SubGhzNotificationStateRx;
@ -181,16 +182,16 @@ void subghz_scene_decode_raw_on_enter(void* context) {
} else {
//Load history to receiver
subghz_view_receiver_exit(subghz->subghz_receiver);
for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) {
for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) {
furi_string_reset(item_name);
furi_string_reset(item_time);
subghz_history_get_text_item_menu(subghz->txrx->history, item_name, i);
subghz_history_get_time_item_menu(subghz->txrx->history, item_time, i);
subghz_history_get_text_item_menu(subghz->history, item_name, i);
subghz_history_get_time_item_menu(subghz->history, item_time, i);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(subghz->txrx->history, i));
subghz_history_get_type_protocol(subghz->history, i));
}
furi_string_free(item_name);
furi_string_free(item_time);

View file

@ -48,7 +48,7 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
} else if(event.event == SubGhzCustomEventSceneExit) {
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateExit) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz_preset_init(
subghz_set_preset(
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);

View file

@ -42,6 +42,7 @@ static void subghz_scene_read_raw_update_statusbar(void* context) {
#ifdef SUBGHZ_EXT_PRESET_NAME
subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, true);
//TODO if need subghz_get_preset
//furi_string_printf(modulation_str, "%s", furi_string_get_cstr(subghz->txrx->preset->name));
#else
subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false);
@ -139,14 +140,15 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
} else {
//Restore default setting
if(subghz->raw_send_only) {
subghz_preset_init(
subghz_set_preset(
subghz->txrx,
"AM650",
subghz_setting_get_default_frequency(subghz->txrx->setting),
subghz_setting_get_default_frequency(
subghz_txrx_get_setting(subghz->txrx)),
NULL,
0);
} else {
subghz_preset_init(
subghz_set_preset(
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
}
if(!scene_manager_search_and_switch_to_previous_scene(
@ -281,18 +283,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateIDLE) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx);
if(subghz_protocol_raw_save_to_file_init(
(SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx),
RAW_FILE_NAME,
subghz->txrx->preset)) {
&preset)) {
DOLPHIN_DEED(DolphinDeedSubGhzRawRec);
subghz_txrx_stop(subghz->txrx);
subghz_begin(
subghz->txrx,
subghz_setting_get_preset_data_by_name(
subghz->txrx->setting,
furi_string_get_cstr(subghz->txrx->preset->name)));
subghz_rx(subghz->txrx, subghz->txrx->preset->frequency);
subghz_rx_start(subghz->txrx);
subghz->state_notifications = SubGhzNotificationStateRx;
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);

View file

@ -40,12 +40,12 @@ const NotificationSequence subghz_sequence_rx_locked = {
static void subghz_scene_receiver_update_statusbar(void* context) {
SubGhz* subghz = context;
FuriString* history_stat_str = furi_string_alloc();
if(!subghz_history_get_text_space_left(subghz->txrx->history, history_stat_str)) {
if(!subghz_history_get_text_space_left(subghz->history, history_stat_str)) {
FuriString* frequency_str = furi_string_alloc();
FuriString* modulation_str = furi_string_alloc();
#ifdef SUBGHZ_EXT_PRESET_NAME
if(subghz_history_get_last_index(subghz->txrx->history) > 0) {
if(subghz_history_get_last_index(subghz->history) > 0) {
subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false);
} else {
FuriString* temp_str = furi_string_alloc();
@ -94,21 +94,22 @@ static void subghz_scene_add_to_history_callback(
FuriString* item_name = furi_string_alloc();
FuriString* item_time = furi_string_alloc();
uint16_t idx = subghz_history_get_item(subghz->txrx->history);
uint16_t idx = subghz_history_get_item(subghz->history);
if(subghz_history_add_to_history(subghz->txrx->history, decoder_base, subghz->txrx->preset)) {
SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx);
if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) {
furi_string_reset(item_name);
furi_string_reset(item_time);
subghz->state_notifications = SubGhzNotificationStateRxDone;
subghz_history_get_text_item_menu(subghz->txrx->history, item_name, idx);
subghz_history_get_time_item_menu(subghz->txrx->history, item_time, idx);
subghz_history_get_text_item_menu(subghz->history, item_name, idx);
subghz_history_get_time_item_menu(subghz->history, item_time, idx);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(subghz->txrx->history, idx));
subghz_history_get_type_protocol(subghz->history, idx));
subghz_scene_receiver_update_statusbar(subghz);
}
@ -125,8 +126,8 @@ void subghz_scene_receiver_on_enter(void* context) {
FuriString* item_time = furi_string_alloc();
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) {
subghz_preset_init(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz_history_reset(subghz->txrx->history);
subghz_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz_history_reset(subghz->history);
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart);
}
@ -135,16 +136,16 @@ void subghz_scene_receiver_on_enter(void* context) {
//Load history to receiver
subghz_view_receiver_exit(subghz->subghz_receiver);
for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) {
for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) {
furi_string_reset(item_name);
furi_string_reset(item_time);
subghz_history_get_text_item_menu(subghz->txrx->history, item_name, i);
subghz_history_get_time_item_menu(subghz->txrx->history, item_time, i);
subghz_history_get_text_item_menu(subghz->history, item_name, i);
subghz_history_get_time_item_menu(subghz->history, item_time, i);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(subghz->txrx->history, i));
subghz_history_get_type_protocol(subghz->history, i));
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
}
furi_string_free(item_name);
@ -183,11 +184,7 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz->state_notifications = SubGhzNotificationStateRx;
subghz_txrx_stop(subghz->txrx);
subghz_begin(
subghz->txrx,
subghz_setting_get_preset_data_by_name(
subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name)));
subghz_rx(subghz->txrx, subghz->txrx->preset->frequency);
subghz_rx_start(subghz->txrx);
subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen);
//to use a universal decoder, we are looking for a link to it
@ -215,7 +212,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz_preset_init(
subghz_set_preset(
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
@ -232,7 +229,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
case SubGhzCustomEventViewReceiverDeleteItem:
subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
subghz_history_delete_item(subghz->txrx->history, subghz->idx_menu_chosen);
subghz_history_delete_item(subghz->history, subghz->idx_menu_chosen);
subghz_view_receiver_delete_element_callback(subghz->subghz_receiver);
subghz_scene_receiver_update_statusbar(subghz);

View file

@ -93,12 +93,15 @@ uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void*
furi_assert(context);
SubGhz* subghz = context;
uint8_t index = 0;
for(uint8_t i = 0; i < subghz_setting_get_frequency_count(subghz->txrx->setting); i++) {
if(value == subghz_setting_get_frequency(subghz->txrx->setting, i)) {
for(uint8_t i = 0;
i < subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx));
i++) {
if(value == subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), i)) {
index = i;
break;
} else {
index = subghz_setting_get_frequency_default_index(subghz->txrx->setting);
index =
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx));
}
}
return index;
@ -108,12 +111,15 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void*
furi_assert(context);
SubGhz* subghz = context;
uint8_t index = 0;
for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz->txrx->setting); i++) {
if(!strcmp(subghz_setting_get_preset_name(subghz->txrx->setting, i), preset_name)) {
for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx));
i++) {
if(!strcmp(
subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), i),
preset_name)) {
index = i;
break;
} else {
// index = subghz_setting_get_frequency_default_index(subghz->txrx->setting);
// index = subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx));
}
}
return index;
@ -149,33 +155,48 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
text_buf,
sizeof(text_buf),
"%lu.%02lu",
subghz_setting_get_frequency(subghz->txrx->setting, index) / 1000000,
(subghz_setting_get_frequency(subghz->txrx->setting, index) % 1000000) / 10000);
subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) / 1000000,
(subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) %
1000000) /
10000);
variable_item_set_current_value_text(item, text_buf);
subghz->txrx->preset->frequency =
subghz_setting_get_frequency(subghz->txrx->setting, index);
subghz->last_settings->frequency = subghz->txrx->preset->frequency;
SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx);
subghz_set_preset(
subghz->txrx,
furi_string_get_cstr(preset.name),
subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index),
preset.data,
preset.data_size);
preset = subghz_get_preset(subghz->txrx);
subghz->last_settings->frequency = preset.frequency;
subghz_setting_set_default_frequency(
subghz->txrx->setting, subghz->txrx->preset->frequency);
subghz_txrx_get_setting(subghz->txrx), preset.frequency);
} else {
variable_item_set_current_value_index(
item, subghz_setting_get_frequency_default_index(subghz->txrx->setting));
item,
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)));
}
}
static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
const char* preset_name = subghz_setting_get_preset_name(subghz->txrx->setting, index);
const char* preset_name =
subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), index);
variable_item_set_current_value_text(item, preset_name);
//subghz->last_settings->preset = index;
SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx);
subghz_preset_init(
subghz_set_preset(
subghz->txrx,
preset_name,
subghz->txrx->preset->frequency,
subghz_setting_get_preset_data(subghz->txrx->setting, index),
subghz_setting_get_preset_data_size(subghz->txrx->setting, index));
preset.frequency,
subghz_setting_get_preset_data(subghz_txrx_get_setting(subghz->txrx), index),
subghz_setting_get_preset_data_size(subghz_txrx_get_setting(subghz->txrx), index));
}
static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) {
@ -189,18 +210,25 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item)
text_buf,
sizeof(text_buf),
"%lu.%02lu",
subghz_setting_get_default_frequency(subghz->txrx->setting) / 1000000,
(subghz_setting_get_default_frequency(subghz->txrx->setting) % 1000000) / 10000);
subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) / 1000000,
(subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) %
1000000) /
10000);
variable_item_set_current_value_text(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
text_buf);
subghz->txrx->preset->frequency =
subghz_setting_get_default_frequency(subghz->txrx->setting);
SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx);
subghz_set_preset(
subghz->txrx,
furi_string_get_cstr(preset.name),
subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)),
preset.data,
preset.data_size);
variable_item_set_current_value_index(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
subghz_setting_get_frequency_default_index(subghz->txrx->setting));
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)));
} else {
variable_item_set_current_value_text(
(VariableItem*)scene_manager_get_scene_state(
@ -209,7 +237,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item)
variable_item_set_current_value_index(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
subghz_setting_get_frequency_default_index(subghz->txrx->setting));
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)));
}
subghz_hopper_set_state(subghz->txrx, hopping_value[index]);
@ -277,15 +305,15 @@ void subghz_scene_receiver_config_on_enter(void* context) {
SubGhz* subghz = context;
VariableItem* item;
uint8_t value_index;
SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx);
item = variable_item_list_add(
subghz->variable_item_list,
"Frequency:",
subghz_setting_get_frequency_count(subghz->txrx->setting),
subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx)),
subghz_scene_receiver_config_set_frequency,
subghz);
value_index =
subghz_scene_receiver_config_next_frequency(subghz->txrx->preset->frequency, subghz);
value_index = subghz_scene_receiver_config_next_frequency(preset.frequency, subghz);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item);
variable_item_set_current_value_index(item, value_index);
@ -294,21 +322,23 @@ void subghz_scene_receiver_config_on_enter(void* context) {
text_buf,
sizeof(text_buf),
"%lu.%02lu",
subghz_setting_get_frequency(subghz->txrx->setting, value_index) / 1000000,
(subghz_setting_get_frequency(subghz->txrx->setting, value_index) % 1000000) / 10000);
subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) / 1000000,
(subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) %
1000000) /
10000);
variable_item_set_current_value_text(item, text_buf);
item = variable_item_list_add(
subghz->variable_item_list,
"Modulation:",
subghz_setting_get_preset_count(subghz->txrx->setting),
subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx)),
subghz_scene_receiver_config_set_preset,
subghz);
value_index = subghz_scene_receiver_config_next_preset(
furi_string_get_cstr(subghz->txrx->preset->name), subghz);
value_index =
subghz_scene_receiver_config_next_preset(furi_string_get_cstr(preset.name), subghz);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(
item, subghz_setting_get_preset_name(subghz->txrx->setting, value_index));
item, subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), value_index));
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {

View file

@ -26,15 +26,15 @@ static bool subghz_scene_receiver_info_update_parser(void* context) {
if(subghz_txrx_load_decoder_by_name_protocol(
subghz->txrx,
subghz_history_get_protocol_name(subghz->txrx->history, subghz->idx_menu_chosen))) {
subghz_history_get_protocol_name(subghz->history, subghz->idx_menu_chosen))) {
//todo we are trying to deserialize without checking for errors, since it is assumed that we just received this chignal
subghz_protocol_decoder_base_deserialize(
subghz_txrx_get_decoder(subghz->txrx),
subghz_history_get_raw_data(subghz->txrx->history, subghz->idx_menu_chosen));
subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen));
SubGhzRadioPreset* preset =
subghz_history_get_radio_preset(subghz->txrx->history, subghz->idx_menu_chosen);
subghz_preset_init(
subghz_history_get_radio_preset(subghz->history, subghz->idx_menu_chosen);
subghz_set_preset(
subghz->txrx,
furi_string_get_cstr(preset->name),
preset->frequency,
@ -123,21 +123,14 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
//CC1101 Stop RX -> Start TX
subghz_subghz_hopper_set_pause(subghz->txrx);
subghz_txrx_stop(subghz->txrx);
if(!subghz_scene_receiver_info_update_parser(subghz)) {
return false;
}
if(!subghz_tx_start(
subghz->txrx,
subghz_history_get_raw_data(subghz->txrx->history, subghz->idx_menu_chosen))) {
subghz_txrx_stop(subghz->txrx);
subghz_begin(
subghz->txrx,
subghz_setting_get_preset_data_by_name(
subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name)));
subghz_rx(subghz->txrx, subghz->txrx->preset->frequency);
subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen))) {
subghz_rx_start(subghz->txrx);
subghz_hopper_remove_pause(subghz->txrx);
subghz->state_notifications = SubGhzNotificationStateRx;
} else {
@ -153,11 +146,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
subghz_txrx_stop(subghz->txrx);
if(!subghz->in_decoder_scene) {
subghz_begin(
subghz->txrx,
subghz_setting_get_preset_data_by_name(
subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name)));
subghz_rx(subghz->txrx, subghz->txrx->preset->frequency);
subghz_rx_start(subghz->txrx);
subghz_hopper_remove_pause(subghz->txrx);
subghz->state_notifications = SubGhzNotificationStateRx;

View file

@ -156,7 +156,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
subghz_save_protocol_to_file(
subghz,
subghz_history_get_raw_data(
subghz->txrx->history, subghz->idx_menu_chosen),
subghz->history, subghz->idx_menu_chosen),
furi_string_get_cstr(subghz->file_path));
}
}

View file

@ -72,7 +72,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventViewTransmitterSendStart) {
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz_txrx_stop(subghz->txrx);
if(subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) {
subghz->state_notifications = SubGhzNotificationStateTx;
subghz_scene_transmitter_update_data_show(subghz);

View file

@ -272,9 +272,9 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
subghz->txrx->preset = malloc(sizeof(SubGhzRadioPreset));
subghz->txrx->preset->name = furi_string_alloc();
if(!alloc_for_tx_only) {
subghz_preset_init(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
} else {
subghz_preset_init(
subghz_set_preset(
subghz->txrx,
"AM650",
subghz_setting_get_default_frequency(subghz->txrx->setting),
@ -287,7 +287,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz->txrx->debug_pin_state = false;
if(!alloc_for_tx_only) {
subghz->txrx->history = subghz_history_alloc();
subghz->history = subghz_history_alloc();
}
subghz->txrx->worker = subghz_worker_alloc();
@ -333,6 +333,8 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) {
}
subghz_speaker_off(subghz->txrx);
subghz_txrx_stop(subghz->txrx);
subghz_sleep(subghz->txrx);
#if FURI_DEBUG
// Packet Test
@ -421,7 +423,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) {
flipper_format_free(subghz->txrx->fff_data);
if(!alloc_for_tx_only) {
subghz_history_free(subghz->txrx->history);
subghz_history_free(subghz->history);
}
furi_string_free(subghz->txrx->preset->name);
free(subghz->txrx->preset);

View file

@ -91,7 +91,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
}
furi_string_set_str(
temp_str, subghz_set_preset(subghz->txrx, furi_string_get_cstr(temp_str)));
temp_str, subghz_get_name_preset(subghz->txrx, furi_string_get_cstr(temp_str)));
if(temp_str == NULL) {
break;
}
@ -112,7 +112,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
}
size_t preset_index = subghz_setting_get_inx_preset_by_name(
subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(temp_str));
subghz_preset_init(
subghz_set_preset(
subghz->txrx,
furi_string_get_cstr(temp_str),
temp_data32,

View file

@ -111,6 +111,7 @@ struct SubGhz {
SubGhzThresholdRssi* threshold_rssi;
SubGhzRxKeyState rx_key_state;
SubGhzHistory* history;
uint16_t idx_menu_chosen;
SubGhzLoadTypeFile load_type_file;

View file

@ -2,7 +2,7 @@
#define TAG "SubGhz"
void subghz_preset_init(
void subghz_set_preset(
SubGhzTxRx* txrx,
const char* preset_name,
uint32_t frequency,
@ -37,7 +37,7 @@ void subghz_get_frequency_modulation(
}
}
const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset) {
const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset) {
UNUSED(txrx);
const char* preset_name = NULL;
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
@ -56,7 +56,12 @@ const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset) {
return preset_name;
}
void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) {
SubGhzRadioPreset subghz_get_preset(SubGhzTxRx* txrx) {
furi_assert(txrx);
return *txrx->preset;
}
static void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) {
furi_assert(txrx);
furi_hal_subghz_reset();
furi_hal_subghz_idle();
@ -65,7 +70,7 @@ void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) {
txrx->txrx_state = SubGhzTxRxStateIDLE;
}
uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency) {
static uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency) {
furi_assert(txrx);
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
furi_crash("SubGhz: Incorrect RX frequency.");
@ -106,11 +111,11 @@ static void subghz_rx_end(SubGhzTxRx* txrx) {
txrx->txrx_state = SubGhzTxRxStateIDLE;
}
// static void subghz_sleep(SubGhzTxRx* txrx) {
// furi_assert(txrx);
// furi_hal_subghz_sleep();
// txrx->txrx_state = SubGhzTxRxStateSleep;
// }
void subghz_sleep(SubGhzTxRx* txrx) {
furi_assert(txrx);
furi_hal_subghz_sleep();
txrx->txrx_state = SubGhzTxRxStateSleep;
}
static bool subghz_tx(SubGhzTxRx* txrx, uint32_t frequency) {
furi_assert(txrx);
@ -133,6 +138,9 @@ static bool subghz_tx(SubGhzTxRx* txrx, uint32_t frequency) {
bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) {
furi_assert(txrx);
furi_assert(flipper_format);
subghz_txrx_stop(txrx);
bool ret = false;
FuriString* temp_str = furi_string_alloc();
@ -200,6 +208,16 @@ bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) {
return ret;
}
void subghz_rx_start(SubGhzTxRx* txrx) {
furi_assert(txrx);
subghz_txrx_stop(txrx);
subghz_begin(
txrx,
subghz_setting_get_preset_data_by_name(
subghz_txrx_get_setting(txrx), furi_string_get_cstr(txrx->preset->name)));
subghz_rx(txrx, txrx->preset->frequency);
}
void subghz_txrx_need_save_callback_set(
SubGhzTxRx* txrx,
SubGhzTxRxNeedSaveCallback callback,
@ -449,7 +467,7 @@ bool subghz_gen_data_protocol(
bool res = false;
subghz_preset_init(txrx, preset_name, frequency, NULL, 0);
subghz_set_preset(txrx, preset_name, frequency, NULL, 0);
txrx->decoder_result =
subghz_receiver_search_decoder_base_by_name(txrx->receiver, protocol_name);
@ -520,7 +538,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq( //TODO rename
txrx->transmitter =
subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME);
subghz_preset_init(txrx, preset_name, frequency, NULL, 0);
subghz_set_preset(txrx, preset_name, frequency, NULL, 0);
if(txrx->transmitter && subghz_protocol_keeloq_create_data(
subghz_transmitter_get_protocol_instance(txrx->transmitter),
@ -552,7 +570,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename
txrx->transmitter =
subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME);
subghz_preset_init(txrx, preset_name, frequency, NULL, 0);
subghz_set_preset(txrx, preset_name, frequency, NULL, 0);
if(txrx->transmitter && subghz_protocol_keeloq_bft_create_data(
subghz_transmitter_get_protocol_instance(txrx->transmitter),
@ -596,7 +614,7 @@ bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename
txrx->transmitter =
subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME);
subghz_preset_init(txrx, preset_name, frequency, NULL, 0);
subghz_set_preset(txrx, preset_name, frequency, NULL, 0);
if(txrx->transmitter && subghz_protocol_nice_flor_s_create_data(
subghz_transmitter_get_protocol_instance(txrx->transmitter),
@ -629,7 +647,7 @@ bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename
txrx->transmitter =
subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME);
subghz_preset_init(txrx, preset_name, frequency, NULL, 0);
subghz_set_preset(txrx, preset_name, frequency, NULL, 0);
if(txrx->transmitter && subghz_protocol_faac_slh_create_data(
subghz_transmitter_get_protocol_instance(txrx->transmitter),
@ -670,7 +688,7 @@ bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename
txrx->transmitter =
subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME);
subghz_preset_init(txrx, preset_name, frequency, NULL, 0);
subghz_set_preset(txrx, preset_name, frequency, NULL, 0);
if(txrx->transmitter && subghz_protocol_alutech_at_4n_create_data(
subghz_transmitter_get_protocol_instance(txrx->transmitter),
@ -700,7 +718,7 @@ bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename
txrx->transmitter =
subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME);
subghz_preset_init(txrx, preset_name, frequency, NULL, 0);
subghz_set_preset(txrx, preset_name, frequency, NULL, 0);
if(txrx->transmitter && subghz_protocol_somfy_telis_create_data(
subghz_transmitter_get_protocol_instance(txrx->transmitter),
@ -729,7 +747,7 @@ bool subghz_gen_secplus_v2_protocol(
bool ret = false;
txrx->transmitter =
subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
subghz_preset_init(txrx, name_preset, frequency, NULL, 0);
subghz_set_preset(txrx, name_preset, frequency, NULL, 0);
if(txrx->transmitter) {
subghz_protocol_secplus_v2_create_data(
subghz_transmitter_get_protocol_instance(txrx->transmitter),

View file

@ -21,7 +21,6 @@ struct SubGhzTxRx {
FlipperFormat* fff_data;
SubGhzRadioPreset* preset;
SubGhzHistory* history;
SubGhzSetting* setting;
uint8_t hopper_timeout;
@ -40,26 +39,27 @@ struct SubGhzTxRx {
typedef struct SubGhzTxRx SubGhzTxRx;
void subghz_preset_init(
void subghz_set_preset(
SubGhzTxRx* txrx,
const char* preset_name,
uint32_t frequency,
uint8_t* preset_data,
size_t preset_data_size);
const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset);
const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset);
SubGhzRadioPreset subghz_get_preset(SubGhzTxRx* txrx);
void subghz_get_frequency_modulation(
SubGhzTxRx* txrx,
FuriString* frequency,
FuriString* modulation,
bool long_name);
void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data);
uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency);
bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format);
//void subghz_rx_end(SubGhzTxRx* txrx); //depricated
//void subghz_sleep(SubGhzTxRx* txrx);
void subghz_rx_start(SubGhzTxRx* txrx);
void subghz_txrx_stop(SubGhzTxRx* txrx);
void subghz_sleep(SubGhzTxRx* txrx);
SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* txrx);
void subghz_hopper_update(SubGhzTxRx* txrx);