From 23c84633da0d56cbd91e059434b04421343a7ac6 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 11 Dec 2021 09:06:14 +1100 Subject: [PATCH] Companion support for EXT3 EXT4 and FlySky gimbals --- companion/src/constants.h | 5 ++--- companion/src/firmwares/boards.cpp | 6 +++--- companion/src/firmwares/edgetx/yaml_switchconfig.cpp | 5 ++--- companion/src/firmwares/edgetx/yaml_switchconfig.h | 2 +- companion/src/firmwares/eeprominterface.h | 3 ++- companion/src/firmwares/generalsettings.cpp | 8 ++++++-- companion/src/firmwares/generalsettings.h | 4 ++-- companion/src/firmwares/modeldata.h | 4 ++-- companion/src/firmwares/opentx/opentxeeprom.cpp | 11 ++++++++++- companion/src/firmwares/opentx/opentxinterface.cpp | 9 +++++++++ companion/src/generaledit/calibration.cpp | 11 +++++++++-- companion/src/generaledit/hardware.cpp | 3 ++- companion/src/simulation/joystickdialog.cpp | 2 +- 13 files changed, 51 insertions(+), 22 deletions(-) diff --git a/companion/src/constants.h b/companion/src/constants.h index 4e66ff214..3bc547d81 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -38,15 +38,14 @@ #define CPN_MAX_MODULES 2 #define CPN_MAX_STICKS Board::STICK_AXIS_COUNT #define CPN_MAX_TRIMS Board::TRIM_AXIS_COUNT -#define CPN_MAX_KNOBS 8 +#define CPN_MAX_POTS 8 #define CPN_MAX_SLIDERS 4 -#define CPN_MAX_POTS (CPN_MAX_KNOBS + CPN_MAX_SLIDERS) #define CPN_MAX_CYC 3 #define CPN_MAX_SWITCHES 32 #define CPN_MAX_FUNCTION_SWITCHES 6 #define CPN_MAX_MOUSE_ANALOGS 2 #define CPN_MAX_GYRO_ANALOGS 2 -#define CPN_MAX_ANALOGS (CPN_MAX_STICKS + CPN_MAX_POTS + CPN_MAX_MOUSE_ANALOGS + CPN_MAX_GYRO_ANALOGS) +#define CPN_MAX_ANALOGS (CPN_MAX_STICKS + CPN_MAX_POTS + CPN_MAX_SLIDERS + CPN_MAX_MOUSE_ANALOGS + CPN_MAX_GYRO_ANALOGS) #define CPN_STR_APP_NAME QCoreApplication::translate("Companion", "EdgeTX Companion") #define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 014b63cca..3f498b804 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -374,7 +374,7 @@ int Boards::getCapability(Board::Type board, Board::Capability capability) else if (IS_TARANIS_X9E(board)) return 4; else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) - return 5; + return 7; else if (IS_HORUS_X12S(board)) return 3; else if (IS_FLYSKY_NV14(board)) @@ -570,8 +570,8 @@ StringTagMappingTable Boards::getAnalogNamesLookupTable(Board::Type board) {"S2", "S2"}, {"EX1", "EXT1"}, {"EX2", "EXT2"}, - // {"EX3", "EXT3"}, - // {"EX4", "EXT4"}, + {"EX3", "EXT3"}, + {"EX4", "EXT4"}, {"LS", "LS"}, {"RS", "RS"}, }); diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 25d8ea75d..f10b21a80 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -41,9 +41,8 @@ const YamlLookupTable switchConfigLut = { }; const YamlLookupTable potsLut = { - {0, "S1"}, {1, "6POS"}, {2, "S2"}, {3, "EXT1"}, {4, "EXT2"}, - // { 5, "EXT3" }, - // { 6, "EXT4" }, + {0, "S1"}, {1, "6POS"}, {2, "S2"}, + {3, "EXT1"}, {4, "EXT2"}, {5, "EXT3"}, {6, "EXT4"}, }; const YamlLookupTable potConfigLut = { diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h index 0a846d15b..fbdd5b8b6 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.h +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -79,7 +79,7 @@ typedef YamlKnobConfig // name: extern const YamlLookupTable potsLut; extern const YamlLookupTable potConfigLut; -typedef YamlKnobConfig YamlPotConfig; +typedef YamlKnobConfig YamlPotConfig; // S1: // type: with_detent diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index cba7362fb..99a2a3953 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -167,7 +167,8 @@ enum Capability { TopBarZones, FunctionSwitches, Has, - HasModelsList + HasModelsList, + HasFlySkyGimbals }; class EEPROMInterface diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index 2ccb66254..c5b09e76f 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -54,14 +54,18 @@ bool GeneralSettings::switchSourceAllowedTaranis(int index) const bool GeneralSettings::isPotAvailable(int index) const { - if (index < 0 || index > Boards::getCapability(getCurrentBoard(), Board::Pots)) + int numPots = Boards::getCapability(getCurrentBoard(), Board::Pots); + if (getCurrentFirmware()->getCapability(HasFlySkyGimbals)) + numPots -= 2; + + if (index < 0 || index >= numPots) return false; return potConfig[index] != Board::POT_NONE; } bool GeneralSettings::isSliderAvailable(int index) const { - if (index < 0 || index > Boards::getCapability(getCurrentBoard(), Board::Sliders)) + if (index < 0 || index >= Boards::getCapability(getCurrentBoard(), Board::Sliders)) return false; return sliderConfig[index] != Board::SLIDER_NONE; } diff --git a/companion/src/firmwares/generalsettings.h b/companion/src/firmwares/generalsettings.h index 6904cc1a4..f7115cc46 100644 --- a/companion/src/firmwares/generalsettings.h +++ b/companion/src/firmwares/generalsettings.h @@ -231,8 +231,8 @@ class GeneralSettings { char switchName[CPN_MAX_SWITCHES][HARDWARE_NAME_LEN + 1]; unsigned int switchConfig[CPN_MAX_SWITCHES]; char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; - char potName[CPN_MAX_KNOBS][HARDWARE_NAME_LEN + 1]; - unsigned int potConfig[CPN_MAX_KNOBS]; + char potName[CPN_MAX_POTS][HARDWARE_NAME_LEN + 1]; + unsigned int potConfig[CPN_MAX_POTS]; char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1]; unsigned int sliderConfig[CPN_MAX_SLIDERS]; diff --git a/companion/src/firmwares/modeldata.h b/companion/src/firmwares/modeldata.h index 6a1443c12..9eb918982 100644 --- a/companion/src/firmwares/modeldata.h +++ b/companion/src/firmwares/modeldata.h @@ -145,8 +145,8 @@ class ModelData { unsigned int switchWarningEnable; unsigned int thrTrimSwitch; unsigned int potsWarningMode; - bool potsWarnEnabled[CPN_MAX_POTS]; - int potsWarnPosition[CPN_MAX_POTS]; + bool potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]; + int potsWarnPosition[CPN_MAX_POTS + CPN_MAX_SLIDERS]; bool displayChecklist; GVarData gvarData[CPN_MAX_GVARS]; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 421138999..5017308cc 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -79,6 +79,8 @@ inline int MAX_POTS(Board::Type board, int version) { if (version <= 218 && IS_FAMILY_HORUS_OR_T16(board)) return 3; + if (version <= 220 && (IS_HORUS_X10(board) || IS_FAMILY_T16(board))) + return 5; if (IS_FAMILY_T12(board)) return 2; return Boards::getCapability(board, Board::Pots); @@ -95,7 +97,7 @@ inline int MAX_POTS_STORAGE(Board::Type board, int version) { if (version <= 218 && IS_FAMILY_HORUS_OR_T16(board)) return 3; - if (version >= 219 && IS_FAMILY_HORUS_OR_T16(board)) + if (version <= 220 && IS_FAMILY_HORUS_OR_T16(board) && !IS_FLYSKY_NV14(board)) return 5; if (IS_FAMILY_T12(board)) return 2; @@ -105,6 +107,8 @@ inline int MAX_POTS_STORAGE(Board::Type board, int version) inline int MAX_POTS_SOURCES(Board::Type board, int version) { if (version <= 218 && IS_FAMILY_HORUS_OR_T16(board)) + return 3; + if (version <= 220 && (IS_HORUS_X10(board) || IS_FAMILY_T16(board))) return 5; if (IS_FAMILY_T12(board)) return 2; @@ -340,6 +344,8 @@ class SourcesConversionTable: public ConversionTable { int offset = 0; if (version <= 218 && IS_HORUS_X10(board) && i >= CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version)) offset += 2; + if (version <= 220 && (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) && i >= CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version)) + offset += 2; addConversion(RawSource(SOURCE_TYPE_STICK, i + offset), val++); } @@ -2947,6 +2953,9 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type if (version <= 218 && IS_HORUS_X10(board) && (i == CPN_MAX_STICKS + 3)) { input += 2; } + if (version <= 220 && IS_FAMILY_HORUS_OR_T16(board) && (i == CPN_MAX_STICKS + 5)) { // make room for EXT3 and EXT4 + input += 2; + } internalField.Append(new SignedField<16>(this, generalData.calibMid[input])); internalField.Append(new SignedField<16>(this, generalData.calibSpanNeg[input])); internalField.Append(new SignedField<16>(this, generalData.calibSpanPos[input])); diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index e3e9761b5..4a9f7ea44 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -761,6 +761,8 @@ int OpenTxFirmware::getCapability(::Capability capability) return IS_JUMPER_TPRO(board) ? 6 : 0; case HasModelsList: return IS_FAMILY_HORUS_OR_T16(board); + case HasFlySkyGimbals: + return (IS_RADIOMASTER_TX16S(board) && id.contains("flyskygimbals")); default: return 0; } @@ -982,6 +984,12 @@ EepromLoadErrors OpenTxEepromInterface::checkVersion(unsigned int version) // ALL: TimerData countdownStart invert value // ALL: convert more fields from zchar to normal string // COLORLCD: change CustomScreenData and TopBarPersistentData + return OLD_VERSION; + + case 221: + // ALL: YAML storage + // X10PCB: add pots EXT3 and EXT4 (conversion required as shifts slider settings in multiple fields) + // RM TX16S: add Flysky gimbals firmware build option and repurpose EXT3 and EXT4 if selected break; default: @@ -1444,6 +1452,7 @@ void registerOpenTxFirmwares() static const Firmware::Option opt_internal_gps("internalgps", Firmware::tr("Support internal GPS")); firmware->addOptionsGroup({opt_bt, opt_internal_gps}); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); + firmware->addOption("flyskygimbals", Firmware::tr("Support hardware mod: FlySky Paladin EV Gimbals")); registerOpenTxFirmware(firmware); /* Jumper T18 board */ diff --git a/companion/src/generaledit/calibration.cpp b/companion/src/generaledit/calibration.cpp index e43b61a53..d955e0e6b 100644 --- a/companion/src/generaledit/calibration.cpp +++ b/companion/src/generaledit/calibration.cpp @@ -25,15 +25,22 @@ CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware): GeneralPanel(parent, generalSettings, firmware) { - int rows = Boards::getCapability(getCurrentBoard(), Board::MaxAnalogs); + Board::Type board = getCurrentBoard(); + int rows = Boards::getCapability(board, Board::MaxAnalogs); QStringList headerLabels; headerLabels << "" << tr("Negative span") << tr("Mid value") << tr("Positive span"); TableLayout * tableLayout = new TableLayout(this, rows, headerLabels); - for (int i = 0; i < rows; i++) { + for (int i = 0, row = 0; i < rows; i++) { int col = 0; + if (firmware->getCapability(HasFlySkyGimbals) && + i >= (Boards::getCapability(board, Board::Sticks) + 5) && + i < (Boards::getCapability(board, Board::Sticks) + 7)) + continue; + + row++; QLabel * label = new QLabel(this); label->setText(firmware->getAnalogInputName(i)); tableLayout->addWidget(i, col++, label); diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index 477287b2e..69a2a6de4 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -64,7 +64,8 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings } count = Boards::getCapability(board, Board::Pots); - if (count) { + count -= firmware->getCapability(HasFlySkyGimbals) ? 2 : 0; + if (count > 0) { for (int i = 0; i < count; i++) { addPot(i, row); } diff --git a/companion/src/simulation/joystickdialog.cpp b/companion/src/simulation/joystickdialog.cpp index 223e2d77d..1be3dd508 100644 --- a/companion/src/simulation/joystickdialog.cpp +++ b/companion/src/simulation/joystickdialog.cpp @@ -103,7 +103,7 @@ void joystickDialog::populateSourceCombo(QComboBox * cb) for (i=0; i < Board::STICK_AXIS_COUNT; ++i) { cb->addItem(Boards::getAxisName(i) % tr(" Stick"), i); } - for (; i < Board::STICK_AXIS_COUNT + CPN_MAX_POTS; ++i) { + for (; i < Board::STICK_AXIS_COUNT + CPN_MAX_POTS + CPN_MAX_SLIDERS; ++i) { cb->addItem(tr("Knob/Slider %1").arg(i - Board::STICK_AXIS_COUNT + 1), i); } }