From 58beca313d229fe2c3345005f6f20250deeac09b Mon Sep 17 00:00:00 2001 From: Z3BRO <101530102+Z3BRO@users.noreply.github.com> Date: Thu, 27 Jul 2023 17:25:32 +0200 Subject: [PATCH] SubGHz External High Power --- .../scenes/subghz_scene_radio_settings.c | 32 ++++++++++++++++ .../main/subghz/subghz_last_settings.c | 19 +++++++++- .../main/subghz/subghz_last_settings.h | 1 + lib/subghz/devices/devices.c | 38 +++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 6fb6e5089..598d6fdce 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -20,6 +20,12 @@ 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", @@ -105,6 +111,22 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) { // subghz_last_settings_save(subghz->last_settings); // } +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]); + + if(index == 1) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } else { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + + subghz->last_settings->external_module_power_amp = index == 1; + subghz_last_settings_save(subghz->last_settings); +} + 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); @@ -137,6 +159,16 @@ 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 High Power", + 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, "Time in names", diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index b61ed3769..5f67fc780 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -19,6 +19,7 @@ #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_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" SubGhzLastSettings* subghz_last_settings_alloc(void) { @@ -46,6 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count 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; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; @@ -77,6 +79,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count 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_EXTERNAL_MODULE_POWER_AMP, + (bool*)&temp_external_module_power_amp, 1); flipper_format_read_bool( fff_data_file, @@ -96,6 +103,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL; instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; instance->external_module_enabled = false; + instance->external_module_power_amp = false; instance->timestamp_file_names = false; } else { @@ -118,7 +126,9 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_power_5v_disable = temp_external_module_power_5v_disable; instance->timestamp_file_names = temp_timestamp_file_names; - + + instance->external_module_power_amp = temp_external_module_power_amp; + /*/} else { instance->preset = temp_preset; }*/ @@ -188,6 +198,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { &instance->external_module_power_5v_disable, 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, diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index d1a5b495f..c351cb6a5 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -13,6 +13,7 @@ typedef struct { // 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; } SubGhzLastSettings; diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index a90bf73a3..525c38323 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -2,14 +2,34 @@ #include "registry.h" +#include + void subghz_devices_init() { furi_check(!subghz_device_registry_is_valid()); subghz_device_registry_init(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } + + subghz_last_settings_free(last_settings); } void subghz_devices_deinit(void) { furi_check(subghz_device_registry_is_valid()); subghz_device_registry_deinit(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + + subghz_last_settings_free(last_settings); } const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) { @@ -69,6 +89,7 @@ void subghz_devices_idle(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->idle) { device->interconnect->idle(); + furi_hal_gpio_write(&gpio_ext_pc3, 0); } } @@ -121,6 +142,15 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_tx) { ret = device->interconnect->set_tx(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_write(&gpio_ext_pc3, 1); + } + + subghz_last_settings_free(last_settings); } return ret; } @@ -161,6 +191,14 @@ void subghz_devices_set_rx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_rx) { device->interconnect->set_rx(); + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } + + subghz_last_settings_free(last_settings); } }