Use analog lookup table in RawSource conversion as well
This commit is contained in:
@@ -19,25 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "yaml_rawsource.h"
|
#include "yaml_rawsource.h"
|
||||||
|
#include "eeprominterface.h"
|
||||||
// SOURCE_TYPE_STICK
|
|
||||||
const YamlLookupTable analogSourceLut = {
|
|
||||||
{ 0, "Rud" },
|
|
||||||
{ 1, "Ele" },
|
|
||||||
{ 2, "Thr" },
|
|
||||||
{ 3, "Ail" },
|
|
||||||
{ 4, "S1" },
|
|
||||||
{ 5, "6POS" },
|
|
||||||
{ 6, "S2" },
|
|
||||||
{ 7, "EXT1" }, { 7, "S3" }, // rename to use only S3
|
|
||||||
{ 8, "EXT2" }, { 8, "S4" }, // rename to use only S4
|
|
||||||
// { 9, "EXT3" },
|
|
||||||
// { 10, "EXT4" },
|
|
||||||
{ 9, "LS" },
|
|
||||||
{ 10, "RS" },
|
|
||||||
{ 11, "MOUSE1" },
|
|
||||||
{ 12, "MOUSE2" },
|
|
||||||
};
|
|
||||||
|
|
||||||
// SOURCE_TYPE_TRIM
|
// SOURCE_TYPE_TRIM
|
||||||
const YamlLookupTable trimSourceLut = {
|
const YamlLookupTable trimSourceLut = {
|
||||||
@@ -85,7 +67,7 @@ Node convert<RawSource>::encode(const RawSource& rhs)
|
|||||||
src_str += ")";
|
src_str += ")";
|
||||||
break;
|
break;
|
||||||
case SOURCE_TYPE_STICK:
|
case SOURCE_TYPE_STICK:
|
||||||
src_str = LookupValue(analogSourceLut, rhs.index);
|
src_str = getCurrentFirmware()->getAnalogInputTag(rhs.index);
|
||||||
break;
|
break;
|
||||||
case SOURCE_TYPE_TRIM:
|
case SOURCE_TYPE_TRIM:
|
||||||
src_str = LookupValue(trimSourceLut, rhs.index);
|
src_str = LookupValue(trimSourceLut, rhs.index);
|
||||||
@@ -239,35 +221,36 @@ bool convert<RawSource>::decode(const Node& node, RawSource& rhs)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
YAML::Node conv = node >> analogSourceLut;
|
std::string ana_str;
|
||||||
if (conv.IsScalar()) {
|
node >> ana_str;
|
||||||
rhs.type = SOURCE_TYPE_STICK;
|
int ana_idx = getCurrentFirmware()->getAnalogInputIndex(ana_str.c_str());
|
||||||
rhs.index = conv.as<int>();
|
if (ana_idx >= 0) {
|
||||||
}
|
rhs.type = SOURCE_TYPE_STICK;
|
||||||
|
rhs.index = ana_idx;
|
||||||
|
}
|
||||||
|
|
||||||
conv = node >> trimSourceLut;
|
YAML::Node conv = node >> trimSourceLut;
|
||||||
if (conv.IsScalar()) {
|
if (conv.IsScalar()) {
|
||||||
rhs.type = SOURCE_TYPE_TRIM;
|
rhs.type = SOURCE_TYPE_TRIM;
|
||||||
rhs.index = conv.as<int>();
|
rhs.index = conv.as<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
conv = node >> cycSourceLut;
|
conv = node >> cycSourceLut;
|
||||||
if (conv.IsScalar()) {
|
if (conv.IsScalar()) {
|
||||||
rhs.type = SOURCE_TYPE_CYC;
|
rhs.type = SOURCE_TYPE_CYC;
|
||||||
rhs.index = conv.as<int>();
|
rhs.index = conv.as<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
conv = node >> specialSourceLut;
|
conv = node >> specialSourceLut;
|
||||||
if (conv.IsScalar()) {
|
if (conv.IsScalar()) {
|
||||||
rhs.type = SOURCE_TYPE_SPECIAL;
|
rhs.type = SOURCE_TYPE_SPECIAL;
|
||||||
rhs.index = conv.as<int>();
|
rhs.index = conv.as<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.IsScalar()
|
if (node.IsScalar() && node.as<std::string>() == "MAX") {
|
||||||
&& node.as<std::string>() == "MAX") {
|
rhs.type = SOURCE_TYPE_MAX;
|
||||||
rhs.type = SOURCE_TYPE_MAX;
|
rhs.index = 0;
|
||||||
rhs.index = 0;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO: raw analogs
|
// TODO: raw analogs
|
||||||
|
|
||||||
|
|||||||
@@ -195,3 +195,12 @@ int Firmware::getAnalogInputIndex(const char * tag)
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Firmware::getAnalogInputTag(unsigned int index)
|
||||||
|
{
|
||||||
|
const StringTagMappingTable& lut = analogInputNamesLookupTable;
|
||||||
|
if (index < lut.size())
|
||||||
|
return lut[index].tag;
|
||||||
|
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
const uint8_t modn12x3[4][4]= {
|
const uint8_t modn12x3[4][4]= {
|
||||||
{1, 2, 3, 4},
|
{1, 2, 3, 4},
|
||||||
@@ -404,6 +405,7 @@ class Firmware
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getAnalogInputIndex(const char * tag);
|
int getAnalogInputIndex(const char * tag);
|
||||||
|
std::string getAnalogInputTag(unsigned int index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString id;
|
QString id;
|
||||||
|
|||||||
Reference in New Issue
Block a user