Move cyc source to firmware

This commit is contained in:
elecpower
2021-12-31 10:53:10 +01:00
committed by Raphael Coeffic
parent 4c92f9dbc9
commit ac9ce745bd
5 changed files with 55 additions and 15 deletions
@@ -31,16 +31,6 @@ const YamlLookupTable trimSourceLut = {
{ 5, "TrimT6" },
};
// SOURCE_TYPE_CYC
const YamlLookupTable cycSourceLut = {
{ 0, "CYC1" },
{ 1, "CYC2" },
{ 2, "CYC3" },
};
// SOURCE_TYPE_MAX
// { MIXSRC_MAX, "MAX" },
std::string YamlRawSourceEncode(const RawSource& rhs)
{
std::string src_str;
@@ -74,7 +64,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
src_str += ")";
break;
case SOURCE_TYPE_CYC:
src_str = YAML::LookupValue(cycSourceLut, rhs.index);
src_str = getCurrentFirmware()->getRawSourceCyclicTag(rhs.index);
break;
case SOURCE_TYPE_PPM:
src_str += "tr(";
@@ -236,10 +226,10 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
rhs.index = conv.as<int>();
}
conv = node >> cycSourceLut;
if (conv.IsScalar()) {
int cyc_idx = getCurrentFirmware()->getRawSourceCyclicIndex(src_str.c_str());
if (cyc_idx >= 0) {
rhs.type = SOURCE_TYPE_CYC;
rhs.index = conv.as<int>();
rhs.index = cyc_idx;
}
int sp_idx = getCurrentFirmware()->getRawSourceSpecialTypesIndex(src_str.c_str());
@@ -308,3 +308,29 @@ std::string Firmware::getRawSourceSpecialTypesTag(unsigned int index)
return std::string();
}
int Firmware::getRawSourceCyclicIndex(const char * tag)
{
const StringTagMappingTable& lut = rawSourceCyclicLookupTable;
auto it =
find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) {
if (elmt.tag == tag) return true;
return false;
});
if (it != lut.end()) {
return it - lut.begin();
}
return -1;
}
std::string Firmware::getRawSourceCyclicTag(unsigned int index)
{
const StringTagMappingTable& lut = rawSourceCyclicLookupTable;
if (index < lut.size())
return lut[index].tag;
return std::string();
}
+10 -1
View File
@@ -295,7 +295,8 @@ class Firmware
switchesLookupTable(Boards::getSwitchesLookupTable(board)),
trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)),
rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()),
rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable())
rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()),
rawSourceCyclicLookupTable(RawSource::getCyclicLookupTable())
{
}
@@ -429,6 +430,11 @@ class Firmware
return &rawSourceSpecialTypesLookupTable;
}
const StringTagMappingTable* getRawSourceCyclicLookupTable()
{
return &rawSourceCyclicLookupTable;
}
int getAnalogInputIndex(const char * tag);
std::string getAnalogInputTag(unsigned int index);
int getSwitchesIndex(const char * tag);
@@ -439,6 +445,8 @@ class Firmware
std::string getRawSwitchTypesTag(unsigned int index);
int getRawSourceSpecialTypesIndex(const char * tag);
std::string getRawSourceSpecialTypesTag(unsigned int index);
int getRawSourceCyclicIndex(const char * tag);
std::string getRawSourceCyclicTag(unsigned int index);
protected:
QString id;
@@ -452,6 +460,7 @@ class Firmware
const StringTagMappingTable trimSwitchesLookupTable;
const StringTagMappingTable rawSwitchTypesLookupTable;
const StringTagMappingTable rawSourceSpecialTypesLookupTable;
const StringTagMappingTable rawSourceCyclicLookupTable;
QList<const char *> languages;
//QList<const char *> ttslanguages;
OptionsList opts;
+14
View File
@@ -439,3 +439,17 @@ tbl.insert(tbl.end(), {
return tbl;
}
// static
StringTagMappingTable RawSource::getCyclicLookupTable()
{
StringTagMappingTable tbl;
tbl.insert(tbl.end(), {
{"0", "CYC1"},
{"1", "CYC2"},
{"2", "CYC3"},
});
return tbl;
}
+1
View File
@@ -276,6 +276,7 @@ class RawSource {
QStringList getStickList(Boards board) const;
QStringList getSwitchList(Boards board) const;
static StringTagMappingTable getSpecialTypesLookupTable();
static StringTagMappingTable getCyclicLookupTable();
bool operator == ( const RawSource & other) const {
return (this->type == other.type) && (this->index == other.index);