Skip to content

Commit 7ea28d3

Browse files
thebenternCopilot
andauthored
Add back FEM LNA mode configuration for LoRa (#9809)
* Add back FEM LNA mode configuration for LoRa * Update src/mesh/NodeDB.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/AdminModule.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * copilot garbage --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 65bf163 commit 7ea28d3

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/mesh/NodeDB.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ void NodeDB::installDefaultConfig(bool preserveKey = false)
568568
true; // FIXME: maybe false in the future, and setting region to enable it. (unset region forces it off)
569569
config.lora.override_duty_cycle = false;
570570
config.lora.config_ok_to_mqtt = false;
571+
#if HAS_LORA_FEM
572+
config.lora.fem_lna_mode = meshtastic_Config_LoRaConfig_FEM_LNA_Mode_DISABLED;
573+
#else
574+
config.lora.fem_lna_mode = meshtastic_Config_LoRaConfig_FEM_LNA_Mode_NOT_PRESENT;
575+
#endif
571576

572577
#if HAS_TFT // For the devices that support MUI, default to that
573578
config.display.displaymode = meshtastic_Config_DisplayConfig_DisplayMode_COLOR;

src/mesh/SX126xInterface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ template <typename T> bool SX126xInterface<T>::init()
5858

5959
#if HAS_LORA_FEM
6060
loraFEMInterface.init();
61+
// Apply saved FEM LNA mode from config
62+
if (loraFEMInterface.isLnaCanControl()) {
63+
loraFEMInterface.setLNAEnable(config.lora.fem_lna_mode == meshtastic_Config_LoRaConfig_FEM_LNA_Mode_ENABLED);
64+
}
6165
#endif
6266

6367
#ifdef RF95_FAN_EN

src/modules/AdminModule.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,17 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
795795
}
796796
#endif
797797
config.lora = validatedLora;
798+
799+
#if HAS_LORA_FEM
800+
// Apply FEM LNA mode from config (only meaningful on hardware that supports it)
801+
if (loraFEMInterface.isLnaCanControl()) {
802+
loraFEMInterface.setLNAEnable(config.lora.fem_lna_mode == meshtastic_Config_LoRaConfig_FEM_LNA_Mode_ENABLED);
803+
} else if (config.lora.fem_lna_mode != meshtastic_Config_LoRaConfig_FEM_LNA_Mode_NOT_PRESENT) {
804+
// Hardware FEM does not support LNA control; normalize stored config to match actual capability
805+
LOG_WARN("FEM LNA mode configured but current FEM does not support LNA control; normalizing to NOT_PRESENT");
806+
config.lora.fem_lna_mode = meshtastic_Config_LoRaConfig_FEM_LNA_Mode_NOT_PRESENT;
807+
}
808+
#endif
798809
// If we're setting region for the first time, init the region and regenerate the keys
799810
if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) {
800811
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN || MESHTASTIC_EXCLUDE_PKI)

0 commit comments

Comments
 (0)