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