Move analogInputNamesLookupTable to Firmware
This commit is contained in:
committed by
Raphael Coeffic
parent
d636487663
commit
df4a4a6960
@@ -510,73 +510,73 @@ QString Boards::getAxisName(int index)
|
|||||||
return CPN_STR_UNKNOWN_ITEM;
|
return CPN_STR_UNKNOWN_ITEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ANALOGINDEXNAMEENTRY(name) tbl.push_back( { cnt++, name } );
|
#define ADDINDEXNAMEPAIR(name) tbl.push_back( { cnt++, name } );
|
||||||
|
|
||||||
AnalogIndexNamesLookupTable Boards::getAnalogNamesLookupTable(Board::Type board)
|
Int2StringMappingTable Boards::getAnalogNamesLookupTable(Board::Type board)
|
||||||
{
|
{
|
||||||
AnalogIndexNamesLookupTable tbl;
|
Int2StringMappingTable tbl;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
if (getBoardCapability(board, Board::Sticks)) {
|
if (getBoardCapability(board, Board::Sticks)) {
|
||||||
ANALOGINDEXNAMEENTRY("Rud")
|
ADDINDEXNAMEPAIR("Rud")
|
||||||
ANALOGINDEXNAMEENTRY("Ele")
|
ADDINDEXNAMEPAIR("Ele")
|
||||||
ANALOGINDEXNAMEENTRY("Thr")
|
ADDINDEXNAMEPAIR("Thr")
|
||||||
ANALOGINDEXNAMEENTRY("Ail")
|
ADDINDEXNAMEPAIR("Ail")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_SKY9X(board)) {
|
if (IS_SKY9X(board)) {
|
||||||
ANALOGINDEXNAMEENTRY("P1")
|
ADDINDEXNAMEPAIR("P1")
|
||||||
ANALOGINDEXNAMEENTRY("P2")
|
ADDINDEXNAMEPAIR("P2")
|
||||||
ANALOGINDEXNAMEENTRY("P3")
|
ADDINDEXNAMEPAIR("P3")
|
||||||
}
|
}
|
||||||
else if (IS_TARANIS_X9E(board)) {
|
else if (IS_TARANIS_X9E(board)) {
|
||||||
ANALOGINDEXNAMEENTRY("F1")
|
ADDINDEXNAMEPAIR("F1")
|
||||||
ANALOGINDEXNAMEENTRY("F2")
|
ADDINDEXNAMEPAIR("F2")
|
||||||
ANALOGINDEXNAMEENTRY("F3")
|
ADDINDEXNAMEPAIR("F3")
|
||||||
ANALOGINDEXNAMEENTRY("F4")
|
ADDINDEXNAMEPAIR("F4")
|
||||||
ANALOGINDEXNAMEENTRY("S1")
|
ADDINDEXNAMEPAIR("S1")
|
||||||
ANALOGINDEXNAMEENTRY("S2")
|
ADDINDEXNAMEPAIR("S2")
|
||||||
ANALOGINDEXNAMEENTRY("LS")
|
ADDINDEXNAMEPAIR("LS")
|
||||||
ANALOGINDEXNAMEENTRY("RS")
|
ADDINDEXNAMEPAIR("RS")
|
||||||
}
|
}
|
||||||
else if (IS_TARANIS_XLITE(board)) {
|
else if (IS_TARANIS_XLITE(board)) {
|
||||||
ANALOGINDEXNAMEENTRY("S1")
|
ADDINDEXNAMEPAIR("S1")
|
||||||
ANALOGINDEXNAMEENTRY("S2")
|
ADDINDEXNAMEPAIR("S2")
|
||||||
ANALOGINDEXNAMEENTRY("GyrX")
|
ADDINDEXNAMEPAIR("GyrX")
|
||||||
ANALOGINDEXNAMEENTRY("GyrY")
|
ADDINDEXNAMEPAIR("GyrY")
|
||||||
}
|
}
|
||||||
else if (IS_TARANIS(board)) {
|
else if (IS_TARANIS(board)) {
|
||||||
ANALOGINDEXNAMEENTRY("S1")
|
ADDINDEXNAMEPAIR("S1")
|
||||||
ANALOGINDEXNAMEENTRY("S2")
|
ADDINDEXNAMEPAIR("S2")
|
||||||
ANALOGINDEXNAMEENTRY("S3")
|
ADDINDEXNAMEPAIR("S3")
|
||||||
ANALOGINDEXNAMEENTRY("LS")
|
ADDINDEXNAMEPAIR("LS")
|
||||||
ANALOGINDEXNAMEENTRY("RS")
|
ADDINDEXNAMEPAIR("RS")
|
||||||
}
|
}
|
||||||
else if (IS_HORUS_X12S(board)) {
|
else if (IS_HORUS_X12S(board)) {
|
||||||
ANALOGINDEXNAMEENTRY("S1")
|
ADDINDEXNAMEPAIR("S1")
|
||||||
ANALOGINDEXNAMEENTRY("6P")
|
ADDINDEXNAMEPAIR("6P")
|
||||||
ANALOGINDEXNAMEENTRY("S2")
|
ADDINDEXNAMEPAIR("S2")
|
||||||
ANALOGINDEXNAMEENTRY("L1")
|
ADDINDEXNAMEPAIR("L1")
|
||||||
ANALOGINDEXNAMEENTRY("L2")
|
ADDINDEXNAMEPAIR("L2")
|
||||||
ANALOGINDEXNAMEENTRY("LS")
|
ADDINDEXNAMEPAIR("LS")
|
||||||
ANALOGINDEXNAMEENTRY("RS")
|
ADDINDEXNAMEPAIR("RS")
|
||||||
ANALOGINDEXNAMEENTRY("JSx")
|
ADDINDEXNAMEPAIR("JSx")
|
||||||
ANALOGINDEXNAMEENTRY("JSy")
|
ADDINDEXNAMEPAIR("JSy")
|
||||||
}
|
}
|
||||||
else if (IS_FLYSKY_NV14(board)) {
|
else if (IS_FLYSKY_NV14(board)) {
|
||||||
ANALOGINDEXNAMEENTRY("VRA")
|
ADDINDEXNAMEPAIR("VRA")
|
||||||
ANALOGINDEXNAMEENTRY("VRB")
|
ADDINDEXNAMEPAIR("VRB")
|
||||||
}
|
}
|
||||||
else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) {
|
else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) {
|
||||||
ANALOGINDEXNAMEENTRY("S1")
|
ADDINDEXNAMEPAIR("S1")
|
||||||
ANALOGINDEXNAMEENTRY("6P")
|
ADDINDEXNAMEPAIR("6P")
|
||||||
ANALOGINDEXNAMEENTRY("S2")
|
ADDINDEXNAMEPAIR("S2")
|
||||||
ANALOGINDEXNAMEENTRY("EX1")
|
ADDINDEXNAMEPAIR("EX1")
|
||||||
ANALOGINDEXNAMEENTRY("EX2" )
|
ADDINDEXNAMEPAIR("EX2" )
|
||||||
//ANALOGINDEXNAMEENTRY("EX3") // not yet implemented
|
//ADDINDEXNAMEPAIR("EX3") // not yet implemented
|
||||||
//ANALOGINDEXNAMEENTRY("EX4") // not yet implemented
|
//ADDINDEXNAMEPAIR("EX4") // not yet implemented
|
||||||
ANALOGINDEXNAMEENTRY("LS")
|
ADDINDEXNAMEPAIR("LS")
|
||||||
ANALOGINDEXNAMEENTRY("RS")
|
ADDINDEXNAMEPAIR("RS")
|
||||||
}
|
}
|
||||||
|
|
||||||
return tbl;
|
return tbl;
|
||||||
@@ -584,15 +584,15 @@ AnalogIndexNamesLookupTable Boards::getAnalogNamesLookupTable(Board::Type board)
|
|||||||
|
|
||||||
int Boards::getAnalogInputIndex(Board::Type board, char * name)
|
int Boards::getAnalogInputIndex(Board::Type board, char * name)
|
||||||
{
|
{
|
||||||
AnalogIndexNamesLookupTable lut = getAnalogNamesLookupTable(board);
|
Int2StringMappingTable tbl = getAnalogNamesLookupTable(board);
|
||||||
|
|
||||||
const auto& it =
|
const auto& it =
|
||||||
find_if(lut.begin(), lut.end(), [=](const AnalogIndexNamesLookupElmt& elmt) {
|
find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) {
|
||||||
if (elmt.second == name) return true;
|
if (row.second == name) return true;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (it != lut.end()) {
|
if (it != tbl.end()) {
|
||||||
return it->first;
|
return it->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,15 +601,15 @@ int Boards::getAnalogInputIndex(Board::Type board, char * name)
|
|||||||
|
|
||||||
QString Boards::getAnalogInputName(Board::Type board, int index)
|
QString Boards::getAnalogInputName(Board::Type board, int index)
|
||||||
{
|
{
|
||||||
AnalogIndexNamesLookupTable lut = getAnalogNamesLookupTable(board);
|
Int2StringMappingTable tbl = getAnalogNamesLookupTable(board);
|
||||||
|
|
||||||
const auto& it =
|
const auto& it =
|
||||||
find_if(lut.begin(), lut.end(), [=](const AnalogIndexNamesLookupElmt& elmt) {
|
find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) {
|
||||||
if (elmt.first == index) return true;
|
if (row.first == index) return true;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (it != lut.end()) {
|
if (it != tbl.end()) {
|
||||||
return QString::fromUtf8(it->second.data(), it->second.size());
|
return QString::fromUtf8(it->second.data(), it->second.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,14 +19,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "datahelpers.h"
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class AbstractStaticItemModel;
|
class AbstractStaticItemModel;
|
||||||
|
|
||||||
// identiying names of static abstract item models
|
// identiying names of static abstract item models
|
||||||
@@ -177,9 +175,6 @@ namespace Board {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::pair<int, std::string> AnalogIndexNamesLookupElmt;
|
|
||||||
typedef std::vector<AnalogIndexNamesLookupElmt> AnalogIndexNamesLookupTable;
|
|
||||||
|
|
||||||
class Boards
|
class Boards
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(Boards)
|
Q_DECLARE_TR_FUNCTIONS(Boards)
|
||||||
@@ -208,7 +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 AnalogIndexNamesLookupTable getAnalogNamesLookupTable(Board::Type board);
|
static Int2StringMappingTable getAnalogNamesLookupTable(Board::Type board);
|
||||||
static int getAnalogInputIndex(Board::Type board, char * name);
|
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);
|
||||||
|
|||||||
@@ -21,6 +21,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
typedef std::pair<int, std::string> Int2StringMapping;
|
||||||
|
typedef std::vector<Int2StringMapping> Int2StringMappingTable;
|
||||||
|
|
||||||
class FieldRange
|
class FieldRange
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,10 +66,9 @@ 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;
|
||||||
// TODO: for efficiency construct once at an outer level possibly add to Firmware?
|
const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable();
|
||||||
const YamlLookupTable calibIdxLut = Boards::getAnalogNamesLookupTable(getCurrentBoard());
|
|
||||||
// TODO: we need something better here!
|
// TODO: we need something better here!
|
||||||
for (const auto& kv : calibIdxLut) {
|
for (const auto& kv : *calibIdxLut) {
|
||||||
node[kv.second] = rhs.calib[kv.first];
|
node[kv.second] = rhs.calib[kv.first];
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
@@ -78,11 +77,13 @@ 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;
|
||||||
// TODO: for efficiency construct once at an outer level possibly add to Firmware?
|
const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable();
|
||||||
const YamlLookupTable calibIdxLut = Boards::getAnalogNamesLookupTable(getCurrentBoard());
|
//for_each(calibIdxLut->begin(), calibIdxLut->end(), [=](const Int2StringMapping& row) {
|
||||||
|
// qDebug() << "index:" << row.first << "value:" << row.second.c_str();
|
||||||
|
// });
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (const auto& kv : node) {
|
for (const auto& kv : node) {
|
||||||
kv.first >> calibIdxLut >> idx;
|
kv.first >> *calibIdxLut >> idx;
|
||||||
kv.second >> rhs.calib[idx];
|
kv.second >> rhs.calib[idx];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "radiodata.h"
|
#include "radiodata.h"
|
||||||
#include "../../radio/src/definitions.h"
|
#include "../../radio/src/definitions.h"
|
||||||
#include "simulatorinterface.h"
|
#include "simulatorinterface.h"
|
||||||
|
#include "datahelpers.h"
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@@ -287,8 +288,15 @@ class Firmware
|
|||||||
board(board),
|
board(board),
|
||||||
variantBase(0),
|
variantBase(0),
|
||||||
base(base),
|
base(base),
|
||||||
eepromInterface(nullptr)
|
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() { }
|
virtual ~Firmware() { }
|
||||||
|
|
||||||
@@ -395,6 +403,11 @@ class Firmware
|
|||||||
currentVariant = value;
|
currentVariant = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Int2StringMappingTable * getAnalogIndexNamesLookupTable()
|
||||||
|
{
|
||||||
|
return &analogInputNamesLookupTable;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString id;
|
QString id;
|
||||||
QString name;
|
QString name;
|
||||||
@@ -402,6 +415,7 @@ class Firmware
|
|||||||
unsigned int variantBase;
|
unsigned int variantBase;
|
||||||
Firmware * base;
|
Firmware * base;
|
||||||
EEPROMInterface * eepromInterface;
|
EEPROMInterface * eepromInterface;
|
||||||
|
const Int2StringMappingTable analogInputNamesLookupTable;
|
||||||
QList<const char *> languages;
|
QList<const char *> languages;
|
||||||
//QList<const char *> ttslanguages;
|
//QList<const char *> ttslanguages;
|
||||||
OptionsList opts;
|
OptionsList opts;
|
||||||
@@ -409,6 +423,7 @@ class Firmware
|
|||||||
static QVector<Firmware *> registeredFirmwares;
|
static QVector<Firmware *> registeredFirmwares;
|
||||||
static Firmware * defaultVariant;
|
static Firmware * defaultVariant;
|
||||||
static Firmware * currentVariant;
|
static Firmware * currentVariant;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Firmware * getCurrentFirmware()
|
inline Firmware * getCurrentFirmware()
|
||||||
|
|||||||
Reference in New Issue
Block a user