Skip to content

Commit

Permalink
fix(cpn): function switches
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower committed Apr 21, 2024
1 parent 60119ae commit cc7e630
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
24 changes: 24 additions & 0 deletions companion/src/firmwares/boardjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ void BoardJson::afterLoadFixups(Board::Type board, InputsTable * inputs, Switche
switches->insert(switches->end(), defn);
}
}

// Function switches names are not in the json file and are relative to last real switch name
std::string lastswitch;

for (const auto &swtch : *switches) {
if (isSwitchStd(swtch) && lastswitch < swtch.name)
lastswitch = swtch.name;
}

if (lastswitch.size() == 2) {
const std::string prfx = lastswitch.substr(0, 1);
char lastsw[1];
lastswitch.copy(lastsw, 1, 1);

for (auto &swtch : *switches) {
if (isSwitchFunc(swtch)) {
swtch.name = prfx;
char fsnum[1];
swtch.tag.copy(fsnum, 1, swtch.tag.size() - 1);
char swnum = lastsw[0] + fsnum[0] - '0';
swtch.name += std::string(1, swnum);
}
}
}
}

// called from Boards::getCapability if no capability match
Expand Down
13 changes: 10 additions & 3 deletions companion/src/firmwares/edgetx/yaml_rawswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
rhs.index = tsw_idx + 1;
}

} else if ((val_len >= 4 && (
(val[0] == 'F' && val[1] == 'L') ||
(val[0] == 'S' && val[1] == 'W')) &&
} else if ((val_len >= 4 &&
val[0] == 'F' && val[1] == 'L' &&
val[2] >= '1' && val[2] <= '9' &&
val[val_len - 1] >= '0' && val[val_len - 1] <= '2') ||
(val_len >= 3 && val[0] == 'S' &&
Expand All @@ -169,6 +168,14 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
int sw_idx = Boards::getSwitchYamlIndex(sw_str_tmp.substr(0, val_len - 1).c_str(), BoardJson::YLT_REF);
if (sw_idx >= 0) {
rhs.type = SWITCH_TYPE_SWITCH;

if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
if (IS_JUMPER_TPRO(board) && sw_idx >= 4) {
// added support for real switches SE & SF so need to shift function switches
sw_idx += 2;
}
}

rhs.index = sw_idx * 3 + (val[val_len - 1] - '0' + 1);
}

Expand Down
2 changes: 1 addition & 1 deletion companion/src/modeledit/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model

for (int i = 0; i < switchcnt; i++) {
QLabel * lblSwitchId = new QLabel(this);
lblSwitchId->setText(tr("SW%1").arg(i + 1));
lblSwitchId->setText(Boards::getSwitchName(Boards::getSwitchIndex(QString("SW%1").arg(i + 1), Board::LVT_TAG)));

AutoLineEdit * aleName = new AutoLineEdit(this);
aleName->setProperty("index", i);
Expand Down

0 comments on commit cc7e630

Please sign in to comment.