Skip to content

Commit

Permalink
rework subghz settings, enable tx-rx state on unused gpio pin by default
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Apr 5, 2024
1 parent f8d4d93 commit a830d6b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 199 deletions.
37 changes: 0 additions & 37 deletions applications/main/subghz/scenes/subghz_scene_radio_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ const char* const timestamp_names_text[TIMESTAMP_NAMES_COUNT] = {
"ON",
};

#define EXT_MOD_POWER_AMP_COUNT 2
const char* const ext_mod_power_amp_text[EXT_MOD_POWER_AMP_COUNT] = {
"OFF",
"ON",
};

#define DEBUG_P_COUNT 2
const char* const debug_pin_text[DEBUG_P_COUNT] = {
"OFF",
Expand Down Expand Up @@ -94,27 +88,6 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) {
furi_hal_subghz_set_rolling_counter_mult(debug_counter_val[index]);
}

static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);

variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]);

subghz->last_settings->external_module_power_amp = index == 1;

// Set globally in furi hal
furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp);

subghz_last_settings_save(subghz->last_settings);

// reinit external device
const SubGhzRadioDeviceType current = subghz_txrx_radio_device_get(subghz->txrx);
if(current != SubGhzRadioDeviceTypeInternal) {
subghz_txrx_radio_device_set(subghz->txrx, SubGhzRadioDeviceTypeInternal);
subghz_txrx_radio_device_set(subghz->txrx, current);
}
}

static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
Expand Down Expand Up @@ -147,16 +120,6 @@ void subghz_scene_radio_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, radio_device_text[value_index]);

item = variable_item_list_add(
variable_item_list,
"Ext Power Amp",
EXT_MOD_POWER_AMP_COUNT,
subghz_scene_reciever_config_set_ext_mod_power_amp_text,
subghz);
value_index = subghz->last_settings->external_module_power_amp ? 1 : 0;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, ext_mod_power_amp_text[value_index]);

item = variable_item_list_add(
variable_item_list,
"Protocol Names",
Expand Down
3 changes: 0 additions & 3 deletions applications/main/subghz/subghz_dangerous_freq.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ void subghz_dangerous_freq() {
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
subghz_last_settings_load(last_settings, 0);

// Set globally in furi hal
furi_hal_subghz_set_ext_power_amp(last_settings->external_module_power_amp);

subghz_last_settings_free(last_settings);

furi_record_close(RECORD_STORAGE);
Expand Down
146 changes: 53 additions & 93 deletions applications/main/subghz/subghz_last_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
#define TAG "SubGhzLastSettings"

#define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File"
#define SUBGHZ_LAST_SETTING_FILE_VERSION 1
#define SUBGHZ_LAST_SETTING_FILE_VERSION 2
#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/last_subghz.settings")

#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency"
#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" // AKA Modulation
#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_FEEDBACK_LEVEL "FeedbackLevel"
#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger"
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External"
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower"
#define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames"
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp"
#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE "Hopping"
#define SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER "IgnoreFilter"
#define SUBGHZ_LAST_SETTING_FIELD_FILTER "Filter"
Expand All @@ -40,9 +37,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
uint32_t temp_frequency = 0;
uint32_t temp_frequency_analyzer_feedback_level = 0;
float temp_frequency_analyzer_trigger = 0;
bool temp_external_module_enabled = false;
bool temp_external_module_power_5v_disable = false;
bool temp_external_module_power_amp = false;
bool temp_timestamp_file_names = false;
bool temp_enable_hopping = false;
bool temp_delete_old_sig = false;
Expand All @@ -58,62 +52,63 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
bool frequency_analyzer_feedback_level_was_read = false;
bool frequency_analyzer_trigger_was_read = false;

FuriString* temp_str = furi_string_alloc();
uint32_t config_version = 0;

if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH &&
flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) {
preset_was_read = flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (uint32_t*)&temp_preset, 1);
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1);
frequency_analyzer_feedback_level_was_read = flipper_format_read_uint32(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_FEEDBACK_LEVEL,
(uint32_t*)&temp_frequency_analyzer_feedback_level,
1);
frequency_analyzer_trigger_was_read = flipper_format_read_float(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER,
(float*)&temp_frequency_analyzer_trigger,
1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED,
(bool*)&temp_external_module_enabled,
1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER,
(bool*)&temp_external_module_power_5v_disable,
1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES,
(bool*)&temp_timestamp_file_names,
1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP,
(bool*)&temp_external_module_power_amp,
1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE,
(bool*)&temp_enable_hopping,
1);
rssi_was_read = flipper_format_read_float(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, (float*)&temp_rssi, 1);
ignore_filter_was_read = flipper_format_read_uint32(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER,
(uint32_t*)&temp_ignore_filter,
1);
filter_was_read = flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FILTER, (uint32_t*)&temp_filter, 1);
flipper_format_read_bool(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD, (bool*)&temp_delete_old_sig, 1);
do {
if(!flipper_format_read_header(fff_data_file, temp_str, &config_version)) break;
if((strcmp(furi_string_get_cstr(temp_str), SUBGHZ_LAST_SETTING_FILE_TYPE) != 0) ||
(config_version != SUBGHZ_LAST_SETTING_FILE_VERSION)) {
break;
}

preset_was_read = flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (uint32_t*)&temp_preset, 1);
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1);
frequency_analyzer_feedback_level_was_read = flipper_format_read_uint32(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_FEEDBACK_LEVEL,
(uint32_t*)&temp_frequency_analyzer_feedback_level,
1);
frequency_analyzer_trigger_was_read = flipper_format_read_float(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER,
(float*)&temp_frequency_analyzer_trigger,
1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES,
(bool*)&temp_timestamp_file_names,
1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE,
(bool*)&temp_enable_hopping,
1);
rssi_was_read = flipper_format_read_float(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, (float*)&temp_rssi, 1);
ignore_filter_was_read = flipper_format_read_uint32(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER,
(uint32_t*)&temp_ignore_filter,
1);
filter_was_read = flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FILTER, (uint32_t*)&temp_filter, 1);
flipper_format_read_bool(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD,
(bool*)&temp_delete_old_sig,
1);
} while(0);
} else {
FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH);
}

furi_string_free(temp_str);

if(temp_frequency == 0 || !furi_hal_subghz_is_tx_allowed(temp_frequency)) {
FURI_LOG_W(TAG, "Last used frequency not found or can't be used!");

Expand All @@ -122,9 +117,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->frequency_analyzer_feedback_level =
SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL;
instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER;
instance->external_module_enabled = false;
instance->timestamp_file_names = false;
instance->external_module_power_amp = false;
instance->enable_hopping = false;
instance->delete_old_signals = false;
instance->ignore_filter = 0x00;
Expand Down Expand Up @@ -155,17 +148,10 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
} else {
instance->preset_index = temp_preset;
}
instance->external_module_enabled = temp_external_module_enabled;

instance->external_module_power_5v_disable = temp_external_module_power_5v_disable;

instance->timestamp_file_names = temp_timestamp_file_names;

instance->delete_old_signals = temp_delete_old_sig;

// External power amp CC1101
instance->external_module_power_amp = temp_external_module_power_amp;

instance->rssi = rssi_was_read ? temp_rssi : SUBGHZ_RAW_THRESHOLD_MIN;
instance->enable_hopping = temp_enable_hopping;
instance->ignore_filter = ignore_filter_was_read ? temp_ignore_filter : 0x00;
Expand All @@ -180,8 +166,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->filter = SubGhzProtocolFlag_Decodable;
}
#endif
// Set globally in furi hal
furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp);
}

flipper_format_file_close(fff_data_file);
Expand Down Expand Up @@ -233,34 +217,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
1)) {
break;
}
if(!flipper_format_insert_or_update_bool(
file,
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED,
&instance->external_module_enabled,
1)) {
break;
}
if(!flipper_format_insert_or_update_bool(
file,
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER,
&instance->external_module_power_5v_disable,
1)) {
break;
}
if(!flipper_format_insert_or_update_bool(
file,
SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES,
&instance->timestamp_file_names,
1)) {
break;
}
if(!flipper_format_insert_or_update_bool(
file,
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP,
&instance->external_module_power_amp,
1)) {
break;
}
if(!flipper_format_insert_or_update_bool(
file, SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE, &instance->enable_hopping, 1)) {
break;
Expand Down Expand Up @@ -312,17 +275,14 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) {

FURI_LOG_I(
TAG,
"Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s,\n"
"Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, TimestampNames: %s,\n"
"Hopping: %s,\nPreset: %ld, RSSI: %.2f, "
"Starline: %s, Cars: %s, Magellan: %s, NiceFloR-S: %s, BinRAW: %s",
instance->frequency / 1000000 % 1000,
instance->frequency / 10000 % 100,
instance->frequency_analyzer_feedback_level,
(double)instance->frequency_analyzer_trigger,
bool_to_char(instance->external_module_enabled),
bool_to_char(instance->external_module_power_5v_disable),
bool_to_char(instance->timestamp_file_names),
bool_to_char(instance->external_module_power_amp),
bool_to_char(instance->enable_hopping),
instance->preset_index,
(double)instance->rssi,
Expand Down
5 changes: 0 additions & 5 deletions applications/main/subghz/subghz_last_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ typedef struct {
uint32_t preset_index; // AKA Modulation
uint32_t frequency_analyzer_feedback_level;
float frequency_analyzer_trigger;
// TODO not using but saved so as not to change the version
bool external_module_enabled;
bool external_module_power_5v_disable;
bool external_module_power_amp;
// saved so as not to change the version
bool timestamp_file_names;
bool enable_hopping;
uint32_t ignore_filter;
Expand Down
2 changes: 1 addition & 1 deletion lib/subghz/devices/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool subghz_devices_begin(const SubGhzDevice* device) {
SubGhzDeviceConf conf = {
.ver = 1,
.extended_range = false, // TODO
.power_amp = furi_hal_subghz_get_ext_power_amp(),
.power_amp = true,
};

ret = device->interconnect->begin(&conf);
Expand Down
2 changes: 0 additions & 2 deletions targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,6 @@ Function,-,furi_hal_subghz_dump_state,void,
Function,+,furi_hal_subghz_flush_rx,void,
Function,+,furi_hal_subghz_flush_tx,void,
Function,+,furi_hal_subghz_get_data_gpio,const GpioPin*,
Function,+,furi_hal_subghz_get_ext_power_amp,_Bool,
Function,+,furi_hal_subghz_get_lqi,uint8_t,
Function,+,furi_hal_subghz_get_rolling_counter_mult,int8_t,
Function,+,furi_hal_subghz_get_rssi,float,
Expand All @@ -1608,7 +1607,6 @@ Function,+,furi_hal_subghz_reset,void,
Function,+,furi_hal_subghz_rx,void,
Function,+,furi_hal_subghz_rx_pipe_not_empty,_Bool,
Function,+,furi_hal_subghz_set_async_mirror_pin,void,const GpioPin*
Function,+,furi_hal_subghz_set_ext_power_amp,void,_Bool
Function,+,furi_hal_subghz_set_frequency,uint32_t,uint32_t
Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t
Function,+,furi_hal_subghz_set_path,void,FuriHalSubGhzPath
Expand Down
10 changes: 0 additions & 10 deletions targets/f7/furi_hal/furi_hal_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ typedef struct {
const GpioPin* async_mirror_pin;

int8_t rolling_counter_mult;
bool ext_power_amp : 1;
bool dangerous_frequency_i : 1;
} FuriHalSubGhz;

Expand All @@ -61,7 +60,6 @@ volatile FuriHalSubGhz furi_hal_subghz = {
.regulation = SubGhzRegulationTxRx,
.async_mirror_pin = NULL,
.rolling_counter_mult = 1,
.ext_power_amp = false,
.dangerous_frequency_i = false,
};

Expand All @@ -77,14 +75,6 @@ void furi_hal_subghz_set_dangerous_frequency(bool state_i) {
furi_hal_subghz.dangerous_frequency_i = state_i;
}

void furi_hal_subghz_set_ext_power_amp(bool enabled) {
furi_hal_subghz.ext_power_amp = enabled;
}

bool furi_hal_subghz_get_ext_power_amp(void) {
return furi_hal_subghz.ext_power_amp;
}

void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) {
furi_hal_subghz.async_mirror_pin = pin;
}
Expand Down
Loading

0 comments on commit a830d6b

Please sign in to comment.