Skip to content

Commit

Permalink
fix(cpn): set input and switch types to none if not configured (#5026)
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower authored May 24, 2024
1 parent d21ac7b commit fae3f83
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
51 changes: 37 additions & 14 deletions companion/src/firmwares/edgetx/yaml_generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,24 +557,47 @@ bool convert<GeneralSettings>::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"]) {
Expand All @@ -596,11 +619,6 @@ bool convert<GeneralSettings>::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)
Expand All @@ -622,6 +640,11 @@ bool convert<GeneralSettings>::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();
Expand Down
9 changes: 0 additions & 9 deletions companion/src/firmwares/edgetx/yaml_switchconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,6 @@ bool convert<YamlSwitchConfig>::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;
Expand Down
15 changes: 7 additions & 8 deletions companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ bool GeneralSettings::unassignedInputFlexSwitches() const
void GeneralSettings::clear()
{
memset(reinterpret_cast<void *>(this), 0, sizeof(GeneralSettings));
setDefaultControlTypes(getCurrentBoard());
init();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fae3f83

Please sign in to comment.