Use proper switch lookup

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:11 +01:00
parent 1d2892ee2f
commit 56ceaebeb8
@@ -69,25 +69,20 @@ std::string YamlStickLookup::idx2name(unsigned int idx)
int YamlSwitchLookup::name2idx(const std::string& name) int YamlSwitchLookup::name2idx(const std::string& name)
{ {
// TODO: replace this with a real lookup of available switches auto fw = getCurrentFirmware();
if (name.size() == 2 int idx = fw->getSwitchesIndex(name.c_str());
&& name[0] == 'S' if (idx < 0) return -1;
&& (name[1] >= 'A' && name[1] <= 'J')) {
return name[1] - 'A'; return idx;
}
return -1;
} }
std::string YamlSwitchLookup::idx2name(unsigned int idx) std::string YamlSwitchLookup::idx2name(unsigned int idx)
{ {
// TODO: replace this with a real lookup of available switches auto fw = getCurrentFirmware();
if (idx < 10) { unsigned int switches = Boards::getCapability(fw->getBoard(), Board::Switches);
return std::string("S") + (char)('A' + idx); if (idx >= switches) return std::string();
}
return std::string(); return fw->getSwitchesTag(idx);
} }
int YamlPotLookup::name2idx(const std::string& name) int YamlPotLookup::name2idx(const std::string& name)