Move special source lookup to firmware
This commit is contained in:
committed by
Raphael Coeffic
parent
6f54fad526
commit
4c92f9dbc9
@@ -41,19 +41,6 @@ const YamlLookupTable cycSourceLut = {
|
||||
// SOURCE_TYPE_MAX
|
||||
// { MIXSRC_MAX, "MAX" },
|
||||
|
||||
const YamlLookupTable specialSourceLut = {
|
||||
{ 0, "TX_VOLTAGE" },
|
||||
{ 1, "TX_TIME" },
|
||||
{ 2, "TX_GPS" },
|
||||
{ 3, "RESERVED1" },
|
||||
{ 4, "RESERVED2" },
|
||||
{ 5, "RESERVED3" },
|
||||
{ 6, "RESERVED4" },
|
||||
{ 7, "TIMER1" },
|
||||
{ 8, "TIMER2" },
|
||||
{ 9, "TIMER3" },
|
||||
};
|
||||
|
||||
std::string YamlRawSourceEncode(const RawSource& rhs)
|
||||
{
|
||||
std::string src_str;
|
||||
@@ -105,7 +92,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
|
||||
src_str += ")";
|
||||
break;
|
||||
case SOURCE_TYPE_SPECIAL:
|
||||
src_str = YAML::LookupValue(specialSourceLut, rhs.index);
|
||||
src_str = getCurrentFirmware()->getRawSourceSpecialTypesTag(rhs.index);
|
||||
break;
|
||||
case SOURCE_TYPE_TELEMETRY:
|
||||
src_str = "tele(";
|
||||
@@ -255,10 +242,10 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
|
||||
rhs.index = conv.as<int>();
|
||||
}
|
||||
|
||||
conv = node >> specialSourceLut;
|
||||
if (conv.IsScalar()) {
|
||||
int sp_idx = getCurrentFirmware()->getRawSourceSpecialTypesIndex(src_str.c_str());
|
||||
if (sp_idx >= 0) {
|
||||
rhs.type = SOURCE_TYPE_SPECIAL;
|
||||
rhs.index = conv.as<int>();
|
||||
rhs.index = sp_idx;
|
||||
}
|
||||
|
||||
if (node.IsScalar() && node.as<std::string>() == "MAX") {
|
||||
|
||||
@@ -282,3 +282,29 @@ std::string Firmware::getRawSwitchTypesTag(unsigned int index)
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
int Firmware::getRawSourceSpecialTypesIndex(const char * tag)
|
||||
{
|
||||
const StringTagMappingTable& lut = rawSourceSpecialTypesLookupTable;
|
||||
|
||||
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::getRawSourceSpecialTypesTag(unsigned int index)
|
||||
{
|
||||
const StringTagMappingTable& lut = rawSourceSpecialTypesLookupTable;
|
||||
if (index < lut.size())
|
||||
return lut[index].tag;
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
@@ -294,7 +294,8 @@ class Firmware
|
||||
analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)),
|
||||
switchesLookupTable(Boards::getSwitchesLookupTable(board)),
|
||||
trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)),
|
||||
rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable())
|
||||
rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()),
|
||||
rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -423,6 +424,11 @@ class Firmware
|
||||
return &rawSwitchTypesLookupTable;
|
||||
}
|
||||
|
||||
const StringTagMappingTable* getRawSourceSpecialTypesLookupTable()
|
||||
{
|
||||
return &rawSourceSpecialTypesLookupTable;
|
||||
}
|
||||
|
||||
int getAnalogInputIndex(const char * tag);
|
||||
std::string getAnalogInputTag(unsigned int index);
|
||||
int getSwitchesIndex(const char * tag);
|
||||
@@ -431,6 +437,8 @@ class Firmware
|
||||
std::string getTrimSwitchesTag(unsigned int index);
|
||||
int getRawSwitchTypesIndex(const char * tag);
|
||||
std::string getRawSwitchTypesTag(unsigned int index);
|
||||
int getRawSourceSpecialTypesIndex(const char * tag);
|
||||
std::string getRawSourceSpecialTypesTag(unsigned int index);
|
||||
|
||||
protected:
|
||||
QString id;
|
||||
@@ -443,6 +451,7 @@ class Firmware
|
||||
const StringTagMappingTable switchesLookupTable;
|
||||
const StringTagMappingTable trimSwitchesLookupTable;
|
||||
const StringTagMappingTable rawSwitchTypesLookupTable;
|
||||
const StringTagMappingTable rawSourceSpecialTypesLookupTable;
|
||||
QList<const char *> languages;
|
||||
//QList<const char *> ttslanguages;
|
||||
OptionsList opts;
|
||||
|
||||
@@ -418,3 +418,24 @@ QStringList RawSource::getSwitchList(Boards board) const
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// static
|
||||
StringTagMappingTable RawSource::getSpecialTypesLookupTable()
|
||||
{
|
||||
StringTagMappingTable tbl;
|
||||
|
||||
tbl.insert(tbl.end(), {
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TX_BATT), "TX_VOLTAGE"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TX_TIME), "TX_TIME"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TX_GPS), "TX_GPS"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED1), "RESERVED1"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED2), "RESERVED2"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED3), "RESERVED3"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED4), "RESERVED4"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER1), "TIMER1"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER2), "TIMER2"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER3), "TIMER3"},
|
||||
});
|
||||
|
||||
return tbl;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "boards.h"
|
||||
#include "constants.h"
|
||||
#include "datahelpers.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
@@ -274,6 +275,7 @@ class RawSource {
|
||||
void clear() { type = SOURCE_TYPE_NONE; index = 0; }
|
||||
QStringList getStickList(Boards board) const;
|
||||
QStringList getSwitchList(Boards board) const;
|
||||
static StringTagMappingTable getSpecialTypesLookupTable();
|
||||
|
||||
bool operator == ( const RawSource & other) const {
|
||||
return (this->type == other.type) && (this->index == other.index);
|
||||
|
||||
Reference in New Issue
Block a user