Move trim sources to boards

This commit is contained in:
elecpower
2021-12-31 10:53:10 +01:00
committed by Raphael Coeffic
parent ac9ce745bd
commit 19a9259d96
5 changed files with 62 additions and 14 deletions
+21
View File
@@ -784,3 +784,24 @@ StringTagMappingTable Boards::getTrimSwitchesLookupTable(Board::Type board)
return tbl;
}
// static
StringTagMappingTable Boards::getTrimSourcesLookupTable(Board::Type board)
{
StringTagMappingTable tbl;
tbl.insert(tbl.end(), {
{std::to_string(TRIM_AXIS_LH), "TrimRud"},
{std::to_string(TRIM_AXIS_LV), "TrimEle"},
{std::to_string(TRIM_AXIS_RV), "TrimThr"},
{std::to_string(TRIM_AXIS_RH), "TrimAil"},
});
if (getCapability(board, Board::NumTrims) > 4)
tbl.insert(tbl.end(), {
{std::to_string(TRIM_AXIS_T5), "TrimT5"},
{std::to_string(TRIM_AXIS_T6), "TrimT6"},
});
return tbl;
}
+1
View File
@@ -215,6 +215,7 @@ class Boards
static AbstractStaticItemModel * sliderTypeItemModel();
static AbstractStaticItemModel * switchTypeItemModel();
static StringTagMappingTable getTrimSwitchesLookupTable(Board::Type board);
static StringTagMappingTable getTrimSourcesLookupTable(Board::Type board);
protected:
@@ -21,16 +21,6 @@
#include "yaml_rawsource.h"
#include "eeprominterface.h"
// SOURCE_TYPE_TRIM
const YamlLookupTable trimSourceLut = {
{ 0, "TrimRud" },
{ 1, "TrimEle" },
{ 2, "TrimThr" },
{ 3, "TrimAil" },
{ 4, "TrimT5" },
{ 5, "TrimT6" },
};
std::string YamlRawSourceEncode(const RawSource& rhs)
{
std::string src_str;
@@ -49,7 +39,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
src_str = getCurrentFirmware()->getAnalogInputTag(rhs.index);
break;
case SOURCE_TYPE_TRIM:
src_str = YAML::LookupValue(trimSourceLut, rhs.index);
src_str = getCurrentFirmware()->getTrimSourcesTag(rhs.index);
break;
case SOURCE_TYPE_MAX:
src_str += "MAX";
@@ -220,10 +210,10 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
rhs.index = ana_idx;
}
YAML::Node conv = node >> trimSourceLut;
if (conv.IsScalar()) {
int trm_idx = getCurrentFirmware()->getTrimSourcesIndex(src_str.c_str());
if (trm_idx >= 0) {
rhs.type = SOURCE_TYPE_TRIM;
rhs.index = conv.as<int>();
rhs.index = trm_idx;
}
int cyc_idx = getCurrentFirmware()->getRawSourceCyclicIndex(src_str.c_str());
@@ -257,6 +257,33 @@ std::string Firmware::getTrimSwitchesTag(unsigned int index)
return std::string();
}
int Firmware::getTrimSourcesIndex(const char * tag)
{
const StringTagMappingTable& lut = trimSourcesLookupTable;
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::getTrimSourcesTag(unsigned int index)
{
const StringTagMappingTable& lut = trimSourcesLookupTable;
if (index < lut.size())
return lut[index].tag;
return std::string();
}
int Firmware::getRawSwitchTypesIndex(const char * tag)
{
const StringTagMappingTable& lut = rawSwitchTypesLookupTable;
@@ -294,6 +294,7 @@ class Firmware
analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)),
switchesLookupTable(Boards::getSwitchesLookupTable(board)),
trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)),
trimSourcesLookupTable(Boards::getTrimSourcesLookupTable(board)),
rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()),
rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()),
rawSourceCyclicLookupTable(RawSource::getCyclicLookupTable())
@@ -420,6 +421,11 @@ class Firmware
return &trimSwitchesLookupTable;
}
const StringTagMappingTable* getTrimSourcesLookupTable()
{
return &trimSourcesLookupTable;
}
const StringTagMappingTable* getRawSwitchTypesLookupTable()
{
return &rawSwitchTypesLookupTable;
@@ -441,6 +447,8 @@ class Firmware
std::string getSwitchesTag(unsigned int index);
int getTrimSwitchesIndex(const char * tag);
std::string getTrimSwitchesTag(unsigned int index);
int getTrimSourcesIndex(const char * tag);
std::string getTrimSourcesTag(unsigned int index);
int getRawSwitchTypesIndex(const char * tag);
std::string getRawSwitchTypesTag(unsigned int index);
int getRawSourceSpecialTypesIndex(const char * tag);
@@ -458,6 +466,7 @@ class Firmware
const StringTagMappingTable analogInputNamesLookupTable;
const StringTagMappingTable switchesLookupTable;
const StringTagMappingTable trimSwitchesLookupTable;
const StringTagMappingTable trimSourcesLookupTable;
const StringTagMappingTable rawSwitchTypesLookupTable;
const StringTagMappingTable rawSourceSpecialTypesLookupTable;
const StringTagMappingTable rawSourceCyclicLookupTable;