Add support for analogs with name different from tag
This commit is contained in:
@@ -510,108 +510,81 @@ QString Boards::getAxisName(int index)
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
}
|
||||
|
||||
#define ADDINDEXNAMEPAIR(name) tbl.push_back( { cnt++, name } );
|
||||
|
||||
Int2StringMappingTable Boards::getAnalogNamesLookupTable(Board::Type board)
|
||||
StringTagMappingTable Boards::getAnalogNamesLookupTable(Board::Type board)
|
||||
{
|
||||
Int2StringMappingTable tbl;
|
||||
int cnt = 0;
|
||||
StringTagMappingTable tbl;
|
||||
|
||||
if (getBoardCapability(board, Board::Sticks)) {
|
||||
ADDINDEXNAMEPAIR("Rud")
|
||||
ADDINDEXNAMEPAIR("Ele")
|
||||
ADDINDEXNAMEPAIR("Thr")
|
||||
ADDINDEXNAMEPAIR("Ail")
|
||||
tbl.insert(tbl.end(), {"Rud", "Ele", "Thr", "Ail"});
|
||||
}
|
||||
|
||||
if (IS_SKY9X(board)) {
|
||||
ADDINDEXNAMEPAIR("P1")
|
||||
ADDINDEXNAMEPAIR("P2")
|
||||
ADDINDEXNAMEPAIR("P3")
|
||||
}
|
||||
else if (IS_TARANIS_X9E(board)) {
|
||||
ADDINDEXNAMEPAIR("F1")
|
||||
ADDINDEXNAMEPAIR("F2")
|
||||
ADDINDEXNAMEPAIR("F3")
|
||||
ADDINDEXNAMEPAIR("F4")
|
||||
ADDINDEXNAMEPAIR("S1")
|
||||
ADDINDEXNAMEPAIR("S2")
|
||||
ADDINDEXNAMEPAIR("LS")
|
||||
ADDINDEXNAMEPAIR("RS")
|
||||
}
|
||||
else if (IS_TARANIS_XLITE(board)) {
|
||||
ADDINDEXNAMEPAIR("S1")
|
||||
ADDINDEXNAMEPAIR("S2")
|
||||
ADDINDEXNAMEPAIR("GyrX")
|
||||
ADDINDEXNAMEPAIR("GyrY")
|
||||
}
|
||||
else if (IS_TARANIS(board)) {
|
||||
ADDINDEXNAMEPAIR("S1")
|
||||
ADDINDEXNAMEPAIR("S2")
|
||||
ADDINDEXNAMEPAIR("S3")
|
||||
ADDINDEXNAMEPAIR("LS")
|
||||
ADDINDEXNAMEPAIR("RS")
|
||||
}
|
||||
else if (IS_HORUS_X12S(board)) {
|
||||
ADDINDEXNAMEPAIR("S1")
|
||||
ADDINDEXNAMEPAIR("6P")
|
||||
ADDINDEXNAMEPAIR("S2")
|
||||
ADDINDEXNAMEPAIR("L1")
|
||||
ADDINDEXNAMEPAIR("L2")
|
||||
ADDINDEXNAMEPAIR("LS")
|
||||
ADDINDEXNAMEPAIR("RS")
|
||||
ADDINDEXNAMEPAIR("JSx")
|
||||
ADDINDEXNAMEPAIR("JSy")
|
||||
}
|
||||
else if (IS_FLYSKY_NV14(board)) {
|
||||
ADDINDEXNAMEPAIR("VRA")
|
||||
ADDINDEXNAMEPAIR("VRB")
|
||||
}
|
||||
else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) {
|
||||
ADDINDEXNAMEPAIR("S1")
|
||||
ADDINDEXNAMEPAIR("6P")
|
||||
ADDINDEXNAMEPAIR("S2")
|
||||
ADDINDEXNAMEPAIR("EX1")
|
||||
ADDINDEXNAMEPAIR("EX2" )
|
||||
//ADDINDEXNAMEPAIR("EX3") // not yet implemented
|
||||
//ADDINDEXNAMEPAIR("EX4") // not yet implemented
|
||||
ADDINDEXNAMEPAIR("LS")
|
||||
ADDINDEXNAMEPAIR("RS")
|
||||
tbl.insert(tbl.end(), {"P1", "P2", "P3"});
|
||||
} else if (IS_TARANIS_X9E(board)) {
|
||||
tbl.insert(tbl.end(), {
|
||||
{"F1", "POT1"},
|
||||
{"F2", "POT2"},
|
||||
{"F3", "POT3"},
|
||||
{"F4", "POT4"},
|
||||
{"S1", "SLIDER1"},
|
||||
{"S2", "SLIDER2"},
|
||||
{"LS", "SLIDER3"},
|
||||
{"RS", "SLIDER4"},
|
||||
});
|
||||
} else if (IS_TARANIS_XLITE(board)) {
|
||||
tbl.insert(tbl.end(), {
|
||||
{"S1", "POT1"},
|
||||
{"S2", "POT2"},
|
||||
{"GyrX", "GYRO1"},
|
||||
{"GyrY", "GYRO2"},
|
||||
});
|
||||
} else if (IS_TARANIS(board)) {
|
||||
tbl.insert(tbl.end(), {
|
||||
{"S1", "POT1"},
|
||||
{"S2", "POT2"},
|
||||
{"S3", "POT3"},
|
||||
{"LS", "SLIDER1"},
|
||||
{"RS", "SLIDER2"},
|
||||
});
|
||||
} else if (IS_HORUS_X12S(board)) {
|
||||
tbl.insert(tbl.end(), {
|
||||
{"S1", "S1"},
|
||||
{"6P", "6POS"},
|
||||
{"S2", "S2"},
|
||||
{"L1", "S3"},
|
||||
{"L2", "S4"},
|
||||
{"LS", "LS"},
|
||||
{"RS", "RS"},
|
||||
{"JSx", "MOUSE1"},
|
||||
{"JSy", "MOUSE2"},
|
||||
});
|
||||
} else if (IS_FLYSKY_NV14(board)) {
|
||||
tbl.insert(tbl.end(), {
|
||||
{"VRA", "POT1"},
|
||||
{"VRB", "POT2"},
|
||||
});
|
||||
} else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) {
|
||||
tbl.insert(tbl.end(), {
|
||||
{"S1", "S1"},
|
||||
{"6P", "6POS"},
|
||||
{"S2", "S2"},
|
||||
{"EX1", "EXT1"},
|
||||
{"EX2", "EXT2"},
|
||||
// {"EX3", "EXT3"},
|
||||
// {"EX4", "EXT4"},
|
||||
{"LS", "LS"},
|
||||
{"RS", "RS"},
|
||||
});
|
||||
}
|
||||
|
||||
return tbl;
|
||||
}
|
||||
|
||||
int Boards::getAnalogInputIndex(Board::Type board, char * name)
|
||||
{
|
||||
Int2StringMappingTable tbl = getAnalogNamesLookupTable(board);
|
||||
|
||||
const auto& it =
|
||||
find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) {
|
||||
if (row.second == name) return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
if (it != tbl.end()) {
|
||||
return it->first;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString Boards::getAnalogInputName(Board::Type board, int index)
|
||||
{
|
||||
Int2StringMappingTable tbl = getAnalogNamesLookupTable(board);
|
||||
|
||||
const auto& it =
|
||||
find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) {
|
||||
if (row.first == index) return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
if (it != tbl.end()) {
|
||||
return QString::fromUtf8(it->second.data(), it->second.size());
|
||||
}
|
||||
const StringTagMappingTable& lut = getAnalogNamesLookupTable(board);
|
||||
if (index < lut.size())
|
||||
return QString::fromStdString(lut[index].name);
|
||||
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
}
|
||||
|
||||
@@ -203,8 +203,7 @@ class Boards
|
||||
static Board::SwitchInfo getSwitchInfo(Board::Type board, int index);
|
||||
static int getCapability(Board::Type board, Board::Capability capability);
|
||||
static QString getAxisName(int index);
|
||||
static Int2StringMappingTable getAnalogNamesLookupTable(Board::Type board);
|
||||
static int getAnalogInputIndex(Board::Type board, char * name);
|
||||
static StringTagMappingTable getAnalogNamesLookupTable(Board::Type board);
|
||||
static QString getAnalogInputName(Board::Type board, int index);
|
||||
static bool isBoardCompatible(Board::Type board1, Board::Type board2);
|
||||
static QString getBoardName(Board::Type board);
|
||||
|
||||
@@ -24,8 +24,30 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef std::pair<int, std::string> Int2StringMapping;
|
||||
typedef std::vector<Int2StringMapping> Int2StringMappingTable;
|
||||
struct StringTagMapping {
|
||||
std::string name;
|
||||
std::string tag;
|
||||
|
||||
StringTagMapping() = default;
|
||||
StringTagMapping(const char* name) :
|
||||
name(name), tag(name)
|
||||
{
|
||||
}
|
||||
StringTagMapping(const std::string& name) :
|
||||
name(name), tag(name)
|
||||
{
|
||||
}
|
||||
StringTagMapping(const char* name, const char* tag) :
|
||||
name(name), tag(tag)
|
||||
{
|
||||
}
|
||||
StringTagMapping(const std::string& name, const std::string& tag) :
|
||||
name(name), tag(tag)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<StringTagMapping> StringTagMappingTable;
|
||||
|
||||
class FieldRange
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "yaml_calibdata.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
YamlCalibData::YamlCalibData() { memset(calib, 0, sizeof(calib)); }
|
||||
|
||||
@@ -66,10 +67,11 @@ bool convert<CalibData>::decode(const Node& node, CalibData& rhs)
|
||||
Node convert<YamlCalibData>::encode(const YamlCalibData& rhs)
|
||||
{
|
||||
Node node;
|
||||
const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable();
|
||||
// TODO: we need something better here!
|
||||
int idx = 0;
|
||||
// TODO: for efficiency construct once at an outer level possibly add to Firmware?
|
||||
const auto* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable();
|
||||
for (const auto& kv : *calibIdxLut) {
|
||||
node[kv.second] = rhs.calib[kv.first];
|
||||
node[kv.tag] = rhs.calib[idx++];
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -77,14 +79,14 @@ Node convert<YamlCalibData>::encode(const YamlCalibData& rhs)
|
||||
bool convert<YamlCalibData>::decode(const Node& node, YamlCalibData& rhs)
|
||||
{
|
||||
if (!node.IsMap()) return false;
|
||||
const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable();
|
||||
//for_each(calibIdxLut->begin(), calibIdxLut->end(), [=](const Int2StringMapping& row) {
|
||||
// qDebug() << "index:" << row.first << "value:" << row.second.c_str();
|
||||
// });
|
||||
int idx = 0;
|
||||
|
||||
for (const auto& kv : node) {
|
||||
kv.first >> *calibIdxLut >> idx;
|
||||
kv.second >> rhs.calib[idx];
|
||||
std::string tag;
|
||||
kv.first >> tag;
|
||||
int idx = getCurrentFirmware()->getAnalogInputIndex(tag.c_str());
|
||||
if (idx >= 0) {
|
||||
kv.second >> rhs.calib[idx];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "yaml_ops.h"
|
||||
#include "generalsettings.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
struct CalibData {
|
||||
int16_t mid;
|
||||
|
||||
@@ -178,3 +178,20 @@ void Firmware::addOptionsGroup(const OptionsGroup & options)
|
||||
{
|
||||
this->opts.append(options);
|
||||
}
|
||||
|
||||
int Firmware::getAnalogInputIndex(const char * tag)
|
||||
{
|
||||
const StringTagMappingTable& lut = analogInputNamesLookupTable;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -291,11 +291,6 @@ class Firmware
|
||||
eepromInterface(nullptr),
|
||||
analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board))
|
||||
{
|
||||
/* qDebug() << "board:" << Boards::getBoardName(board);
|
||||
* for_each(analogInputNamesLookupTable.begin(), analogInputNamesLookupTable.end(), [=](const Int2StringMapping& row) {
|
||||
* qDebug() << "index:" << row.first << "value:" << row.second.c_str();
|
||||
* });
|
||||
*/
|
||||
}
|
||||
|
||||
virtual ~Firmware() { }
|
||||
@@ -403,11 +398,13 @@ class Firmware
|
||||
currentVariant = value;
|
||||
}
|
||||
|
||||
const Int2StringMappingTable * getAnalogIndexNamesLookupTable()
|
||||
const StringTagMappingTable* getAnalogIndexNamesLookupTable()
|
||||
{
|
||||
return &analogInputNamesLookupTable;
|
||||
}
|
||||
|
||||
int getAnalogInputIndex(const char * tag);
|
||||
|
||||
protected:
|
||||
QString id;
|
||||
QString name;
|
||||
@@ -415,7 +412,7 @@ class Firmware
|
||||
unsigned int variantBase;
|
||||
Firmware * base;
|
||||
EEPROMInterface * eepromInterface;
|
||||
const Int2StringMappingTable analogInputNamesLookupTable;
|
||||
const StringTagMappingTable analogInputNamesLookupTable;
|
||||
QList<const char *> languages;
|
||||
//QList<const char *> ttslanguages;
|
||||
OptionsList opts;
|
||||
|
||||
Reference in New Issue
Block a user