diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index a39fe3369..5e0ceeb86 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -289,7 +289,7 @@ int Boards::getCapability(Board::Type board, Board::Capability capability) return 0; case MouseAnalogs: - if (IS_FAMILY_HORUS_OR_T16(board)) + if (IS_HORUS_X12S(board)) return 2; else return 0; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index b7e4d8644..63b79d147 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -128,6 +128,14 @@ inline int SWITCHES_CONFIG_SIZE(Board::Type board, int version) return 16; } +inline int MAX_MOUSE_ANALOG_SOURCES(Board::Type board, int version) +{ + if (IS_FAMILY_HORUS_OR_T16(board)) + return 2; + else + return 0; +} + #define MAX_ROTARY_ENCODERS(board) 0 #define MAX_FLIGHT_MODES(board, version) 9 #define MAX_TIMERS(board, version) 3 @@ -300,7 +308,7 @@ class SourcesConversionTable: public ConversionTable { } } - for (int i=0; i= CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version)) offset += 2; @@ -2569,7 +2577,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type generalData(generalData), board(board), version(version), - inputsCount(CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version) + MAX_SLIDERS_STORAGE(board, version) + Boards::getCapability(board, Board::MouseAnalogs)) + inputsCount(CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version) + MAX_SLIDERS_STORAGE(board, version) + MAX_MOUSE_ANALOG_SOURCES(board, version)) { qCDebug(eepromImport) << QString("OpenTxGeneralData::OpenTxGeneralData(board: %1, version:%2, variant:%3)").arg(board).arg(version).arg(variant); diff --git a/companion/src/firmwares/rawsource.cpp b/companion/src/firmwares/rawsource.cpp index ef38dc236..92377fe0a 100644 --- a/companion/src/firmwares/rawsource.cpp +++ b/companion/src/firmwares/rawsource.cpp @@ -344,111 +344,40 @@ RawSource RawSource::convert(RadioDataConversionState & cstate) RadioDataConversionState::LogField oldData(index, toString(cstate.fromModel(), cstate.fromGS(), cstate.fromType)); if (type == SOURCE_TYPE_STICK) { - if (cstate.toBoard.getCapability(Board::Sliders)) { - if (index >= cstate.fromBoard.getCapability(Board::Sticks) + cstate.fromBoard.getCapability(Board::Pots)) { - // 1st slider alignment - index += cstate.toBoard.getCapability(Board::Pots) - cstate.fromBoard.getCapability(Board::Pots); - } - - if (isSlider(0, cstate.fromType)) { - // LS and RS sliders are after 2 aux sliders on X12 and X9E - if ((IS_HORUS_X12S(cstate.toType) || IS_TARANIS_X9E(cstate.toType)) && !IS_HORUS_X12S(cstate.fromType) && !IS_TARANIS_X9E(cstate.fromType)) { - if (index >= 7) { - index += 2; // LS/RS to LS/RS - } - } - else if (!IS_TARANIS_X9E(cstate.toType) && !IS_HORUS_X12S(cstate.toType) && (IS_HORUS_X12S(cstate.fromType) || IS_TARANIS_X9E(cstate.fromType))) { - if (index >= 7 && index <= 8) { - index += 2; // aux sliders to spare analogs (which may not exist, this is validated later) - evt = RadioDataConversionState::EVT_CVRT; - } - else if (index >= 9 && index <= 10) { - index -= 2; // LS/RS to LS/RS - } - } - } - } - - if (IS_TARANIS(cstate.toType) && IS_FAMILY_HORUS_OR_T16(cstate.fromType)) { - if (index == 6) - index = 5; // pot S2 to S2 - else if (index == 5) - index = -1; // 6P on Horus doesn't exist on Taranis - } - else if (IS_FAMILY_HORUS_OR_T16(cstate.toType) && IS_TARANIS(cstate.fromType) && index == 5) - { - index = 6; // pot S2 to S2 - } - - } // SOURCE_TYPE_STICK + QStringList fromStickList(getStickList(cstate.fromBoard)); + QStringList toStickList(getStickList(cstate.toBoard)); + index = toStickList.indexOf(fromStickList.at(oldData.id)); + // index set to -1 if no match found + // perform forced mapping + } if (type == SOURCE_TYPE_SWITCH) { - // SWI to SWR don't exist on !X9E board - if (!IS_TARANIS_X9E(cstate.toType) && IS_TARANIS_X9E(cstate.fromType)) { - if (index >= 8) { - index = index % 8; - evt = RadioDataConversionState::EVT_CVRT; + QStringList fromSwitchList(getSwitchList(cstate.fromBoard)); + QStringList toSwitchList(getSwitchList(cstate.toBoard)); + index = toSwitchList.indexOf(fromSwitchList.at(oldData.id)); + // index set to -1 if no match found + // perform forced mapping + if (index < 0) { + 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 + index = toSwitchList.indexOf("SD"); + if (index >= 0) + evt = RadioDataConversionState::EVT_CVRT; + } + else if (IS_JUMPER_T12(cstate.toType) && (IS_TARANIS_X9(cstate.fromType) || IS_FAMILY_HORUS_OR_T16(cstate.fromType))) { + // No SE and SG on T12 board + index = toSwitchList.indexOf("SD"); + if (index >= 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 - if (index == 4 || index == 6) { - index = 3; // SG and SE to SD - evt = RadioDataConversionState::EVT_CVRT; - } - else if (index == 5) { - index = 4; // SF to SF - } - else if (index == 7) { - index = 5; // SH to SH - } - } - else if (IS_JUMPER_T12(cstate.toType) && (IS_TARANIS_X9(cstate.fromType) || IS_FAMILY_HORUS_OR_T16(cstate.fromType))) { - // No SE and SG on T12 board - if (index == 4 || index == 6) { - index = 3; // SG and SE to SD - evt = RadioDataConversionState::EVT_CVRT; - } - else if (index == 5) { - index = 4; // SF to SF - } - else if (index == 7) { - index = 5; // 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 (index == 4) { - index = 5; // SF to SF - } - else if (index == 5) { - index = 7; // SH to SH - } - } - else if ((IS_TARANIS_X9(cstate.toType) || IS_FAMILY_HORUS_OR_T16(cstate.toType)) && IS_JUMPER_T12(cstate.fromType)) { - if (index == 4) { - index = 5; // SF to SF - } - else if (index == 5) { - index = 7; // SH to SH - } - } - else if ((IS_TARANIS_X9(cstate.toType) || IS_FAMILY_HORUS_OR_T16(cstate.toType)) && IS_JUMPER_T12(cstate.fromType)) { - if (index == 4) { - index = 5; // SF to SF - } - else if (index == 5) { - index = 7; // SH to SH - } - } - } // SOURCE_TYPE_SWITCH + } // 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 (index < 0 || !isAvailable(NULL, cstate.toGS(), cstate.toType)) { cstate.setInvalid(oldData); - index = -1; // TODO: better way to flag invalid sources? - type = MAX_SOURCE_TYPE; + // no source is safer than an invalid one + clear(); } else if (evt == RadioDataConversionState::EVT_CVRT) { cstate.setConverted(oldData, RadioDataConversionState::LogField(index, toString(cstate.toModel(), cstate.toGS(), cstate.toType))); @@ -460,3 +389,24 @@ RawSource RawSource::convert(RadioDataConversionState & cstate) return *this; } + +QStringList RawSource::getStickList(Boards board) const +{ + QStringList ret; + + for (int i = 0; i < board.getCapability(Board::MaxAnalogs); i++) { + ret.append(board.getAnalogInputName(i)); + } + return ret; +} + +QStringList RawSource::getSwitchList(Boards board) const +{ + QStringList ret; + + for (int i = 0; i < board.getCapability(Board::Switches); i++) { + ret.append(board.getSwitchInfo(i).name); + } + return ret; +} + diff --git a/companion/src/firmwares/rawsource.h b/companion/src/firmwares/rawsource.h index b3220dbd3..9d0b19450 100644 --- a/companion/src/firmwares/rawsource.h +++ b/companion/src/firmwares/rawsource.h @@ -252,6 +252,8 @@ class RawSource { bool isAvailable(const ModelData * const model = NULL, const GeneralSettings * const gs = NULL, Board::Type board = Board::BOARD_UNKNOWN) const; bool isSet() const { return type != SOURCE_TYPE_NONE || index != 0; } void clear() { type = SOURCE_TYPE_NONE; index = 0; } + QStringList getStickList(Boards board) const; + QStringList getSwitchList(Boards board) const; bool operator == ( const RawSource & other) const { return (this->type == other.type) && (this->index == other.index);