fix(cpn): models and settings binary import (#4890)
This commit is contained in:
@@ -305,7 +305,15 @@ int BoardJson::getInputTagOffset(const InputsTable * inputs, QString tag)
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int BoardJson::getInputExtIndex(int index)
|
||||
{
|
||||
if (getCapability(Board::Pots) > 0)
|
||||
return getInputTagOffset(m_inputs, QString("EXT%1").arg(index));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int BoardJson::getInputPotIndex(int index)
|
||||
|
||||
@@ -101,6 +101,7 @@ class BoardJson
|
||||
const int getInputIndex(const QString val, Board::LookupValueType lvt) const;
|
||||
const Board::InputInfo getInputInfo(int index) const;
|
||||
const QString getInputName(int index) const;
|
||||
const int getInputExtIndex(int index);
|
||||
const int getInputPotIndex(int index);
|
||||
const int getInputSliderIndex(int index);
|
||||
const QString getInputTag(int index) const;
|
||||
|
||||
@@ -797,6 +797,11 @@ QString Boards::getInputName(int index, Board::Type board)
|
||||
return getBoardJson(board)->getInputName(index);
|
||||
}
|
||||
|
||||
int Boards::getInputExtIndex(int index, Board::Type board)
|
||||
{
|
||||
return getBoardJson(board)->getInputExtIndex(index);
|
||||
}
|
||||
|
||||
int Boards::getInputPotIndex(int index, Board::Type board)
|
||||
{
|
||||
return getBoardJson(board)->getInputPotIndex(index);
|
||||
|
||||
@@ -331,6 +331,7 @@ class Boards
|
||||
static Board::InputInfo getInputInfo(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getInputIndex(QString val, Board::LookupValueType lvt, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static QString getInputName(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getInputExtIndex(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getInputPotIndex(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getInputSliderIndex(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static QString getInputTag(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
|
||||
@@ -126,27 +126,6 @@ bool GeneralSettings::isInputStick(int index) const
|
||||
return false;
|
||||
}
|
||||
|
||||
// pre v2.10 support
|
||||
// post refactor clean up - where do we call this from?
|
||||
bool GeneralSettings::isMultiPosPot(int index) const
|
||||
{
|
||||
return isInputMultiPosPot(Boards::getInputPotIndex(index));
|
||||
}
|
||||
|
||||
// pre v2.10 support
|
||||
// post refactor clean up - where do we call this from?
|
||||
bool GeneralSettings::isPotAvailable(int index) const
|
||||
{
|
||||
return isInputPot(Boards::getInputPotIndex(index));
|
||||
}
|
||||
|
||||
// pre v2.10 support
|
||||
// post refactor clean up - where do we call this from?
|
||||
bool GeneralSettings::isSliderAvailable(int index) const
|
||||
{
|
||||
return isInputSlider(Boards::getInputSliderIndex(index));
|
||||
}
|
||||
|
||||
bool GeneralSettings::isSwitchAvailable(int index) const
|
||||
{
|
||||
if (index < 0 || index >= Boards::getCapability(getCurrentBoard(), Board::Switches))
|
||||
@@ -839,14 +818,32 @@ bool GeneralSettings::convertLegacyConfiguration(Board::Type board)
|
||||
inputConfig[i].type = Board::AIT_STICK;
|
||||
YamlValidateName(stickName[i], board);
|
||||
strncpy(inputConfig[i].name, stickName[i], HARDWARE_NAME_LEN);
|
||||
inputConfig[i].calib.mid = calibMid[i];
|
||||
inputConfig[i].calib.spanNeg = calibSpanNeg[i];
|
||||
inputConfig[i].calib.spanPos = calibSpanPos[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_POTS && i < Boards::getCapability(board, Board::Pots); i++) {
|
||||
int idx = Boards::getInputPotIndex(i, board);
|
||||
int idx = 0;
|
||||
if (IS_FAMILY_HORUS_OR_T16(board)) {
|
||||
// 0 - 2 P1 - P3
|
||||
// 3 - 6 EXT1 - EXT4
|
||||
// 7 - 8 S1 - S2
|
||||
if (i < 3)
|
||||
idx = Boards::getInputPotIndex(i + 1, board);
|
||||
else
|
||||
idx = Boards::getInputExtIndex(i - 3 + 1, board);
|
||||
}
|
||||
else
|
||||
idx = Boards::getInputPotIndex(i + 1, board);
|
||||
|
||||
if (idx >= 0) {
|
||||
inputConfig[idx].type = Board::AIT_FLEX;
|
||||
YamlValidateName(potName[i], board);
|
||||
strncpy(inputConfig[idx].name, potName[i], HARDWARE_NAME_LEN);
|
||||
inputConfig[idx].calib.mid = calibMid[i];
|
||||
inputConfig[idx].calib.spanNeg = calibSpanNeg[i];
|
||||
inputConfig[idx].calib.spanPos = calibSpanPos[i];
|
||||
int ft = std::stoi(DataHelpers::getStringTagMappingTag(potTypesConversionTable, potConfig[i]));
|
||||
if (ft > -1)
|
||||
inputConfig[idx].flexType = (Board::FlexType)ft;
|
||||
@@ -854,23 +851,31 @@ bool GeneralSettings::convertLegacyConfiguration(Board::Type board)
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_SLIDERS && i < Boards::getCapability(board, Board::Sliders); i++) {
|
||||
int idx = Boards::getInputSliderIndex(i, board);
|
||||
int offset = 0;
|
||||
if (IS_TARANIS_X9E(board) || IS_HORUS_X12S(board)) {
|
||||
// 0 - 1 extra sliders eg L1 - L2 or S1 - S2
|
||||
// 2 - 3 LS - RS
|
||||
// hw json flips the pairs
|
||||
if (i < 2)
|
||||
offset = 2;
|
||||
else
|
||||
offset = -2;
|
||||
}
|
||||
|
||||
int idx = Boards::getInputSliderIndex(i + offset + 1, board);
|
||||
if (idx >= 0) {
|
||||
inputConfig[idx].type = Board::AIT_FLEX;
|
||||
YamlValidateName(sliderName[i], board);
|
||||
strncpy(inputConfig[idx].name, sliderName[i], HARDWARE_NAME_LEN);
|
||||
inputConfig[idx].calib.mid = calibMid[i];
|
||||
inputConfig[idx].calib.spanNeg = calibSpanNeg[i];
|
||||
inputConfig[idx].calib.spanPos = calibSpanPos[i];
|
||||
int ft = std::stoi(DataHelpers::getStringTagMappingTag(sliderTypesConversionTable, sliderConfig[i]));
|
||||
if (ft > -1)
|
||||
inputConfig[idx].flexType = (Board::FlexType)ft;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_ANALOGS && i < Boards::getInputsCalibrated(board); i++) {
|
||||
inputConfig[i].calib.mid = calibMid[i];
|
||||
inputConfig[i].calib.spanNeg = calibSpanNeg[i];
|
||||
inputConfig[i].calib.spanPos = calibSpanPos[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES && i < Boards::getCapability(board, Board::Switches); i++) {
|
||||
switchConfig[i].type = (Board::SwitchType)swtchConfig[i];
|
||||
YamlValidateName(swtchName[i], board);
|
||||
|
||||
@@ -378,11 +378,8 @@ class GeneralSettings {
|
||||
bool isInputSlider(int index) const;
|
||||
bool isInputStick(int index) const;
|
||||
bool isInputFlexSwitchAvailable(int index) const;
|
||||
bool isPotAvailable(int index) const;
|
||||
bool isSliderAvailable(int index) const;
|
||||
bool isSwitchAvailable(int index) const;
|
||||
bool isSwitchFlex(int index) const;
|
||||
bool isMultiPosPot(int index) const;
|
||||
bool unassignedInputFlexSwitches() const;
|
||||
|
||||
QString antennaModeToString() const;
|
||||
|
||||
@@ -3394,13 +3394,13 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
|
||||
else
|
||||
internalField.Append(new ZCharField<3>(this, generalData.stickName[i], "Stick name"));
|
||||
}
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::Pots); ++i) {
|
||||
for (int i = 0; i < MAX_POTS_STORAGE(board, version); ++i) {
|
||||
if (version >= 220)
|
||||
internalField.Append(new CharField<3>(this, generalData.potName[i], "Pot name"));
|
||||
else
|
||||
internalField.Append(new ZCharField<3>(this, generalData.potName[i], "Pot name"));
|
||||
}
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::Sliders); ++i) {
|
||||
for (int i = 0; i < MAX_SLIDERS_STORAGE(board, version); ++i) {
|
||||
if (version >= 220)
|
||||
internalField.Append(new CharField<3>(this, generalData.sliderName[i], "Slider name"));
|
||||
else
|
||||
|
||||
@@ -215,6 +215,12 @@ bool OpenTxEepromInterface::loadFromByteArray(T & dest, const QByteArray & data)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (board != getCurrentBoard()) {
|
||||
qDebug() << QString("%1: not a match to profile %2").arg(getName()).arg(Boards::getBoardName(getCurrentBoard()));
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << QString("%1: OK").arg(getName());
|
||||
uint8_t version = data[4];
|
||||
QByteArray raw = data.right(data.size() - 8);
|
||||
|
||||
Reference in New Issue
Block a user