Skip to content

Commit

Permalink
fix(cpn): models and settings binary import (#4890)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Horne authored Apr 23, 2024
1 parent 4e2608f commit 25bf333
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 35 deletions.
10 changes: 9 additions & 1 deletion companion/src/firmwares/boardjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/boardjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions companion/src/firmwares/boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 34 additions & 29 deletions companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -839,38 +818,64 @@ 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;
}
}

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);
Expand Down
3 changes: 0 additions & 3 deletions companion/src/firmwares/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions companion/src/firmwares/opentx/opentxeeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions companion/src/firmwares/opentx/opentxinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 25bf333

Please sign in to comment.