diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 097267b9c19..e31afc999e6 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -557,24 +557,47 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) node["customFn"] >> rhs.customFn; - YamlStickConfig stickConfig; - node["sticksConfig"] >> stickConfig; - stickConfig.copy(rhs.inputConfig); + // the GeneralSettings struct is initialised to hardware definition defaults which is fine for new settings + // however when parsing saved settings set all inputs to None and override with parsed values + // thus any inputs not parsed will be None rather than the default + for (int i = 0; i < CPN_MAX_INPUTS; i++) { + rhs.inputConfig[i].flexType = (Board::FlexType)Board::FLEX_NONE; + } - YamlPotConfig potsConfig; - node["potsConfig"] >> potsConfig; - potsConfig.copy(rhs.inputConfig); + if (node["sticksConfig"]) { + YamlStickConfig stickConfig; + node["sticksConfig"] >> stickConfig; + // merge + stickConfig.copy(rhs.inputConfig); + } + + if (node["potsConfig"]) { + YamlPotConfig potsConfig; + node["potsConfig"] >> potsConfig; + // merge + potsConfig.copy(rhs.inputConfig); + } // for parsing pre v2.10 config - this is not encoded if (node["slidersConfig"]) { YamlSliderConfig slidersConfig; node["slidersConfig"] >> slidersConfig; + // merge slidersConfig.copy(rhs.inputConfig); } - YamlSwitchConfig switchConfig; - node["switchConfig"] >> switchConfig; - switchConfig.copy(rhs.switchConfig); + // the GeneralSettings struct is initialised to hardware definition defaults which is fine for new settings + // however when parsing saved settings set all switches to None and override with parsed values + // thus any switches not parsed will be None rather than the default + for (int i = 0; i < CPN_MAX_SWITCHES; i++) { + rhs.switchConfig[i].type = Board::SWITCH_NOT_AVAILABLE; + } + + if (node["switchConfig"]) { + YamlSwitchConfig switchConfig; + node["switchConfig"] >> switchConfig; + switchConfig.copy(rhs.switchConfig); + } // MUST be parsed after switchConfig if (node["flexSwitches"]) { @@ -596,11 +619,6 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) // OneBit sampling (X9D only?) node["uartSampleMode"] >> rhs.uartSampleMode; - // override critical settings after import - // TODO: for consistency move up call stack to use existing eeprom and profile conversions - if (needsConversion) - rhs.init(); - node["selectedTheme"] >> rhs.selectedTheme; // Radio level tabs control (global settings) @@ -622,6 +640,11 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) node["labelMultiMode"] >> rhs.labelMultiMode; node["favMultiMode"] >> rhs.favMultiMode; + // override critical settings after import + // TODO: for consistency move up call stack to use existing eeprom and profile conversions + if (needsConversion) + rhs.init(); + // perform integrity checks and fix-ups YamlValidateNames(rhs, fw->getBoard()); rhs.validateFlexSwitches(); diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 71184a39864..fabf76d5d1e 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -365,15 +365,6 @@ bool convert::decode(const Node& node, YamlSwitchConfig& rhs) const int maxcnt = Boards::getCapability(board, Board::Switches); - // load defaults in case values not in yaml file - for (int i = 0; i < maxcnt; i++) { - Board::SwitchInfo info = Boards::getSwitchInfo(i, board); - rhs.config[i].tag = info.tag; - memset(rhs.config[i].name, 0, sizeof(rhs.config[i].name)); - rhs.config[i].type = info.dflt; - rhs.config[i].inverted = info.inverted; - } - for (const auto& kv : node) { std::string tag; kv.first >> tag; diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index 84f8ce9d2f5..173b72ef06d 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -156,6 +156,7 @@ bool GeneralSettings::unassignedInputFlexSwitches() const void GeneralSettings::clear() { memset(reinterpret_cast(this), 0, sizeof(GeneralSettings)); + setDefaultControlTypes(getCurrentBoard()); init(); } @@ -191,8 +192,6 @@ void GeneralSettings::init() vBatMax = -40; //8V } - setDefaultControlTypes(board); - backlightMode = 3; // keys and sticks backlightDelay = 2; // 2 * 5 = 10 secs inactivityTimer = 10; @@ -223,12 +222,6 @@ void GeneralSettings::init() else if (IS_TARANIS_X9E(board) || IS_TARANIS_SMALL(board)) strcpy(bluetoothName, "taranis"); - for (uint8_t i = 0; i < 4; i++) { - trainer.mix[i].mode = TrainerMix::TRN_MIX_MODE_SUBST; - trainer.mix[i].src = i; - trainer.mix[i].weight = 100; - } - ttsLanguage[0] = 'e'; ttsLanguage[1] = 'n'; @@ -369,6 +362,12 @@ void GeneralSettings::setDefaultControlTypes(Board::Type board) switchConfig[i].inverted = info.inverted; switchConfig[i].inputIdx = SWITCH_INPUTINDEX_NONE; } + + for (uint8_t i = 0; i < 4; i++) { + trainer.mix[i].mode = TrainerMix::TRN_MIX_MODE_SUBST; + trainer.mix[i].src = i; + trainer.mix[i].weight = 100; + } } int GeneralSettings::getDefaultStick(unsigned int channel) const