Companion improve switch conversions (#7895)

* Companion refactor rawswitch conversions

* Consistency
This commit is contained in:
Neil Horne
2020-08-28 15:57:24 +02:00
committed by GitHub
parent bed9c529d7
commit bb19720edf
2 changed files with 33 additions and 60 deletions
+32 -60
View File
@@ -184,77 +184,39 @@ RawSwitch RawSwitch::convert(RadioDataConversionState & cstate)
RadioDataConversionState::EventType evt = RadioDataConversionState::EVT_NONE; RadioDataConversionState::EventType evt = RadioDataConversionState::EVT_NONE;
RadioDataConversionState::LogField oldData(index, toString(cstate.fromType, cstate.fromGS(), cstate.fromModel())); RadioDataConversionState::LogField oldData(index, toString(cstate.fromType, cstate.fromGS(), cstate.fromModel()));
int newIdx = 0;
if (type == SWITCH_TYPE_SWITCH) { if (type == SWITCH_TYPE_SWITCH) {
int srcIdx = div(abs(index)-1, 3).quot; // raw source index div_t swtch = div(abs(index) - 1, 3); // rawsource index
int delta = 0; QStringList fromSwitchList(getSwitchList(cstate.fromBoard));
QStringList toSwitchList(getSwitchList(cstate.toBoard));
// SWI to SWR don't exist on !X9E board // set to -1 if no match found
if (!IS_TARANIS_X9E(cstate.toType) && IS_TARANIS_X9E(cstate.fromType)) { newIdx = toSwitchList.indexOf(fromSwitchList.at(swtch.quot));
if (srcIdx > 7) { // perform forced mapping
index %= 24; if (newIdx < 0) {
evt = RadioDataConversionState::EVT_CVRT; if (IS_TARANIS_X7(cstate.toType) && (IS_TARANIS_X9(cstate.fromType) || IS_FAMILY_HORUS_OR_T16(cstate.fromType))) {
} // No SE and SG on X7 board
} newIdx = toSwitchList.indexOf("SD");
if (newIdx >= 0)
// No SE and SG on X7 board
if (IS_TARANIS_X7(cstate.toType) && (IS_TARANIS_X9(cstate.fromType) || IS_FAMILY_HORUS_OR_T16(cstate.fromType))) {
if (srcIdx == 4 || srcIdx == 5) {
delta = 3; // SE to SD & SF to SF
if (srcIdx == 4)
evt = RadioDataConversionState::EVT_CVRT; evt = RadioDataConversionState::EVT_CVRT;
} }
else if (srcIdx == 6) { else if (IS_JUMPER_T12(cstate.toType) && (IS_TARANIS_X9(cstate.fromType) || IS_FAMILY_HORUS_OR_T16(cstate.fromType))) {
delta = 9; // SG to SD // No SE and SG on T12 board
evt = RadioDataConversionState::EVT_CVRT; newIdx = toSwitchList.indexOf("SD");
} if (newIdx >= 0)
else if (srcIdx == 7) {
delta = 6; // SH to SH
}
}
else if (IS_JUMPER_T12(cstate.toType) && (IS_TARANIS_X9(cstate.fromType) || IS_FAMILY_HORUS_OR_T16(cstate.fromType))) {
if (srcIdx == 4 || srcIdx == 5) {
delta = 3; // SE to SD & SF to SF
if (srcIdx == 4)
evt = RadioDataConversionState::EVT_CVRT; evt = RadioDataConversionState::EVT_CVRT;
} }
else if (srcIdx == 6) {
delta = 9; // SG to SD
evt = RadioDataConversionState::EVT_CVRT;
}
else if (srcIdx == 7) {
delta = 6; // SH to SH
}
}
// Compensate for SE and SG on X9/Horus board if converting from X7
else if ((IS_TARANIS_X9(cstate.toType) || IS_FAMILY_HORUS_OR_T16(cstate.toType)) && IS_TARANIS_X7(cstate.fromType)) {
if (srcIdx == 4) {
delta = -3; // SF to SF
}
else if (srcIdx == 5) {
delta = -6; // SH to SH
}
}
else if ((IS_TARANIS_X9(cstate.toType) || IS_FAMILY_HORUS_OR_T16(cstate.toType)) && IS_JUMPER_T12(cstate.fromType)) {
if (srcIdx == 4) {
delta = -3; // SF to SF
}
else if (srcIdx == 5) {
delta = -6; // SH to SH
}
} }
if (index < 0) { if (newIdx >= 0)
delta = -delta; // invert for !switch index = (newIdx * 3 + 1 + swtch.rem) * (index < 0 ? -1 : 1);
}
index -= delta;
} // SWITCH_TYPE_SWITCH } // SWITCH_TYPE_SWITCH
// final validation (we do not pass model to isAvailable() because we don't know what has or hasn't been converted) // final validation (we do not pass model to isAvailable() because we don't know what has or hasn't been converted)
if (!isAvailable(NULL, cstate.toGS(), cstate.toType)) { if (newIdx < 0 || !isAvailable(NULL, cstate.toGS(), cstate.toType)) {
cstate.setInvalid(oldData); cstate.setInvalid(oldData);
type = MAX_SWITCH_TYPE; // TODO: better way to flag invalid switches? // no switch is safer than an invalid one
clear();
} }
else if (evt == RadioDataConversionState::EVT_CVRT) { else if (evt == RadioDataConversionState::EVT_CVRT) {
cstate.setConverted(oldData, RadioDataConversionState::LogField(index, toString(cstate.toType, cstate.toGS(), cstate.toModel()))); cstate.setConverted(oldData, RadioDataConversionState::LogField(index, toString(cstate.toType, cstate.toGS(), cstate.toModel())));
@@ -266,3 +228,13 @@ RawSwitch RawSwitch::convert(RadioDataConversionState & cstate)
return *this; return *this;
} }
QStringList RawSwitch::getSwitchList(Boards board) const
{
QStringList ret;
for (int i = 0; i < board.getCapability(Board::Switches); i++) {
ret.append(board.getSwitchInfo(i).name);
}
return ret;
}
+1
View File
@@ -89,6 +89,7 @@ class RawSwitch {
bool isAvailable(const ModelData * const model = NULL, const GeneralSettings * const gs = NULL, Board::Type board = Board::BOARD_UNKNOWN) const; bool isAvailable(const ModelData * const model = NULL, const GeneralSettings * const gs = NULL, Board::Type board = Board::BOARD_UNKNOWN) const;
bool isSet() const { return type != SWITCH_TYPE_NONE || index != 0; } bool isSet() const { return type != SWITCH_TYPE_NONE || index != 0; }
void clear() { type = SWITCH_TYPE_NONE; index = 0; } void clear() { type = SWITCH_TYPE_NONE; index = 0; }
QStringList getSwitchList(Boards board) const;
bool operator== ( const RawSwitch& other) const { bool operator== ( const RawSwitch& other) const {
return (this->type == other.type) && (this->index == other.index); return (this->type == other.type) && (this->index == other.index);