From 286ae00678458522116585268351212b2188b2a1 Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Sun, 16 Jul 2023 11:06:36 +1000 Subject: [PATCH] feat(cpn): External module form factor set in Radio Profile (#3628) (to allow aligning with firmware compile option) * feat(cpn): External module form factor set in Radio Profile to allow aligning with firmware compile option * Note tweak --- companion/src/apppreferencesdialog.cpp | 7 + companion/src/apppreferencesdialog.ui | 622 +++++++++++++------------ companion/src/firmwares/boards.cpp | 58 +++ companion/src/firmwares/boards.h | 18 + companion/src/firmwares/moduledata.cpp | 84 ++-- companion/src/mainwindow.cpp | 1 + companion/src/modeledit/setup.cpp | 9 +- companion/src/storage/appdata.h | 1 + 8 files changed, 458 insertions(+), 342 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index aca3a8dc5..4696cad10 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -153,6 +153,7 @@ void AppPreferencesDialog::accept() } profile.defaultInternalModule(ui->defaultInternalModuleCB->currentData().toInt()); + profile.externalModuleSize(ui->externalModuleSizeCB->currentData().toInt()); profile.channelOrder(ui->channelorderCB->currentIndex()); profile.defaultMode(ui->stickmodeCB->currentIndex()); profile.renameFwFiles(ui->renameFirmware->isChecked()); @@ -300,6 +301,8 @@ void AppPreferencesDialog::initSettings() // Profile Tab Inits ui->defaultInternalModuleCB->setModel(ModuleData::internalModuleItemModel()); ui->defaultInternalModuleCB->setCurrentIndex(ui->defaultInternalModuleCB->findData(profile.defaultInternalModule())); + ui->externalModuleSizeCB->setModel(Boards::externalModuleSizeItemModel()); + ui->externalModuleSizeCB->setCurrentIndex(ui->externalModuleSizeCB->findData(profile.externalModuleSize())); ui->channelorderCB->setCurrentIndex(profile.channelOrder()); ui->stickmodeCB->setCurrentIndex(profile.defaultMode()); ui->renameFirmware->setChecked(profile.renameFwFiles()); @@ -682,6 +685,10 @@ void AppPreferencesDialog::onBaseFirmwareChanged() profile.defaultInternalModule(Boards::getDefaultInternalModules(newfw->getBoard())); ui->defaultInternalModuleCB->setModel(ModuleData::internalModuleItemModel(newfw->getBoard())); ui->defaultInternalModuleCB->setCurrentIndex(ui->defaultInternalModuleCB->findData(profile.defaultInternalModule())); + + profile.externalModuleSize(Boards::getDefaultExternalModuleSize(newfw->getBoard())); + ui->externalModuleSizeCB->setModel(Boards::externalModuleSizeItemModel()); + ui->externalModuleSizeCB->setCurrentIndex(ui->externalModuleSizeCB->findData(profile.externalModuleSize())); } Firmware *AppPreferencesDialog::getBaseFirmware() const diff --git a/companion/src/apppreferencesdialog.ui b/companion/src/apppreferencesdialog.ui index 0183d77a8..b69843db0 100644 --- a/companion/src/apppreferencesdialog.ui +++ b/companion/src/apppreferencesdialog.ui @@ -7,7 +7,7 @@ 0 0 865 - 673 + 692 @@ -52,33 +52,26 @@ Radio Profile - - + + - + 0 0 - Default Stick Mode + Options + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - If set it will override the application general setting - - - false - - - - - + + - + 0 0 @@ -90,85 +83,40 @@ - Profile Name - - - - - - - Qt::Vertical - - - - 20 - 5 - - - - - - - - - 0 - 0 - - - - SD Structure path + Radio Type Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - 0 - 0 - + + + + true - Language + - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + false - - - - - - - - 0 - 0 - - - - General Settings - - - - - + + 0 0 - - Prompt to write firmware to radio after update + + Qt::Horizontal - + @@ -304,6 +252,36 @@ + + + + Default Int. Module + + + + + + + Select Folder + + + + + + + + 0 + 0 + + + + SD Structure path + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + @@ -320,223 +298,14 @@ - - - - - 0 - 0 - - + + - Options - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Prompt to run SD Sync after update - - - - - 0 - 0 - - - - - 75 - true - - - - Other Settings - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - if set, will override general backup enable - - - Enable automatic backup before writing firmware - - - - - - - - 0 - 0 - - - - The profile specific folder, if set, will override general Backup folder - - - Backup folder - - - - - - - The profile specific folder, if set, will override general Backup folder - - - Select Folder - - - - - - - - 16777215 - 16777215 - - - - Mode selection: - -Mode 1: - Left stick: Elevator, Rudder - Right stick: Throttle, Aileron - -Mode 2: - Left stick: Throttle, Rudder - Right stick: Elevator, Aileron - -Mode 3: - Left stick: Elevator, Aileron - Right stick: Throttle, Rudder - -Mode 4: - Left stick: Throttle, Aileron - Right stick: Elevator, Rudder - - - - - 1 - - - - Mode 1 (RUD ELE THR AIL) - - - - - Mode 2 (RUD THR ELE AIL) - - - - - Mode 3 (AIL ELE THR RUD) - - - - - Mode 4 (AIL THR ELE RUD) - - - - - - - - Default Int. Module - - - - - - - - 0 - 0 - - - - - 75 - true - - - - Radio Type - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Select Folder - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Append version number to firmware file name - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - + @@ -552,6 +321,19 @@ Mode 4: + + + + + + + + 0 + 0 + + + + @@ -666,28 +448,95 @@ Mode 4: - - - - true + + + + The profile specific folder, if set, will override general Backup folder - - - - false + Select Folder - - - - true + + + + + 0 + 0 + + + + General Settings - - + + + + Qt::Vertical + + + + 20 + 5 + + + + + + + + + 16777215 + 16777215 + + + + Mode selection: + +Mode 1: + Left stick: Elevator, Rudder + Right stick: Throttle, Aileron + +Mode 2: + Left stick: Throttle, Rudder + Right stick: Elevator, Aileron + +Mode 3: + Left stick: Elevator, Aileron + Right stick: Throttle, Rudder + +Mode 4: + Left stick: Throttle, Aileron + Right stick: Elevator, Rudder + + + + + 1 + + + + Mode 1 (RUD ELE THR AIL) + + + + + Mode 2 (RUD THR ELE AIL) + + + + + Mode 3 (AIL ELE THR RUD) + + + + + Mode 4 (AIL THR ELE RUD) + + + @@ -719,13 +568,174 @@ Mode 4: - - + + + + + 0 + 0 + + - Prompt to run SD Sync after update + Default Stick Mode + + + + + 0 + 0 + + + + if set, will override general backup enable + + + Enable automatic backup before writing firmware + + + + + + + + 0 + 0 + + + + Language + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Other Settings + + + + + + + + 0 + 0 + + + + Prompt to write firmware to radio after update + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Profile Name + + + + + + + true + + + + + + + + + + + 0 + 0 + + + + Append version number to firmware file name + + + + + + + If set it will override the application general setting + + + false + + + + + + + + 0 + 0 + + + + The profile specific folder, if set, will override general Backup folder + + + Backup folder + + + + + + + External Module + + + + + + diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index d969c8dd7..2667772ea 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -769,6 +769,9 @@ QString Boards::getBoardName(Board::Type board) return "BETAFPV LR3PRO"; case BOARD_IFLIGHT_COMMANDO8: return "iFlight Commando 8"; + // not supported yet + //case BOARD_FLYSKY_EL18: + // return "FlySky EL18"; default: return CPN_STR_UNKNOWN_ITEM; } @@ -994,3 +997,58 @@ int Boards::getDefaultInternalModules(Board::Type board) return (int)MODULE_TYPE_NONE; } } + +// static +int Boards::getDefaultExternalModuleSize(Board::Type board) +{ + if (!getCapability(board, HasExternalModuleSupport)) + return EXTMODSIZE_NONE; + + if (getCapability(board, HasColorLcd)) { + if (IS_FLYSKY_EL18(board)) + return EXTMODSIZE_BOTH; + else + return EXTMODSIZE_STD; + } + + if (IS_TARANIS_X9LITE(board) || + IS_TARANIS_X9DP_2019(board) || + IS_RADIOMASTER_ZORRO(board) || + IS_JUMPER_TLITE(board) || + IS_JUMPER_TPRO(board) || + IS_BETAFPV_LR3PRO(board)) + return EXTMODSIZE_SMALL; + + return EXTMODSIZE_STD; +} + +// static +QString Boards::externalModuleSizeToString(int value) +{ + switch(value) { + case EXTMODSIZE_NONE: + return tr("None"); + case EXTMODSIZE_STD: + return tr("Standard"); + case EXTMODSIZE_SMALL: + return tr("Small"); + case EXTMODSIZE_BOTH: + return tr("Both"); + default: + return CPN_STR_UNKNOWN_ITEM; + } +} + +// static +AbstractStaticItemModel * Boards::externalModuleSizeItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName(AIM_BOARDS_MODULE_SIZE); + + for (int i = 0; i < EXTMODSIZE_COUNT; i++) { + mdl->appendToItemList(externalModuleSizeToString(i), i); + } + + mdl->loadItemList(); + return mdl; +} diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 48e29a0bd..c2ec9e94d 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -31,6 +31,7 @@ class AbstractStaticItemModel; constexpr char AIM_BOARDS_POT_TYPE[] {"boards.pottype"}; constexpr char AIM_BOARDS_SLIDER_TYPE[] {"boards.slidertype"}; constexpr char AIM_BOARDS_SWITCH_TYPE[] {"boards.switchtype"}; +constexpr char AIM_BOARDS_MODULE_SIZE[] {"boards.extmodulesize"}; // TODO create a Board class with all these functions @@ -70,6 +71,7 @@ namespace Board { BOARD_JUMPER_TPRO, BOARD_BETAFPV_LR3PRO, BOARD_IFLIGHT_COMMANDO8, + BOARD_FLYSKY_EL18, BOARD_TYPE_COUNT, BOARD_TYPE_MAX = BOARD_TYPE_COUNT - 1 }; @@ -183,6 +185,14 @@ namespace Board { SwitchTypeContext3Pos = SwitchTypeFlag2Pos | SwitchTypeFlag3Pos }; + enum ExternalModuleSizes { + EXTMODSIZE_NONE, + EXTMODSIZE_STD, + EXTMODSIZE_SMALL, + EXTMODSIZE_BOTH, + EXTMODSIZE_COUNT + }; + } class Boards @@ -229,6 +239,9 @@ class Boards static StringTagMappingTable getTrimSourcesLookupTable(Board::Type board); static QList getSupportedInternalModules(Board::Type board); static int getDefaultInternalModules(Board::Type board); + static int getDefaultExternalModuleSize(Board::Type board); + static QString externalModuleSizeToString(int value); + static AbstractStaticItemModel * externalModuleSizeItemModel(); protected: @@ -338,6 +351,11 @@ inline bool IS_FLYSKY_NV14(Board::Type board) return (board == Board::BOARD_FLYSKY_NV14); } +inline bool IS_FLYSKY_EL18(Board::Type board) +{ + return (board == Board::BOARD_FLYSKY_EL18); +} + inline bool IS_TARANIS_XLITE(Board::Type board) { return board == Board::BOARD_TARANIS_XLITE || board == Board::BOARD_TARANIS_XLITES; diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index bea6aa142..42ab5ad6b 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -25,6 +25,7 @@ #include "radiodataconversionstate.h" #include "compounditemmodels.h" #include "generalsettings.h" +#include "appdata.h" #include #include @@ -259,7 +260,7 @@ QString ModuleData::subTypeToString(int type) const case PULSES_MULTIMODULE: return Multiprotocols::subTypeToString((int)multi.rfProtocol, (unsigned)type); case PULSES_PPM: - return CHECK_IN_ARRAY(ppmSubTypeStrings, type); + return CHECK_IN_ARRAY(ppmSubTypeStrings, type); case PULSES_PXX_R9M: return CHECK_IN_ARRAY(strings, type); case PULSES_AFHDS3: @@ -528,44 +529,59 @@ bool ModuleData::isProtocolAvailable(int moduleidx, unsigned int protocol, Gener if (moduleidx == 0) return (int)generalSettings.internalModule == getTypeFromProtocol(protocol); - QString id = fw->getId(); - if (IS_HORUS_OR_TARANIS(board)) { switch (moduleidx) { - case 1: - switch (protocol) { - case PULSES_OFF: - case PULSES_PPM: - return true; - case PULSES_PXX_XJT_X16: - case PULSES_PXX_XJT_D8: - case PULSES_PXX_XJT_LR12: - return !(IS_TARANIS_XLITES(board) || IS_TARANIS_X9LITE(board)); - case PULSES_PXX_R9M: - case PULSES_LP45: - case PULSES_DSM2: - case PULSES_DSMX: - case PULSES_SBUS: - case PULSES_MULTIMODULE: - case PULSES_CROSSFIRE: - case PULSES_AFHDS3: - case PULSES_GHOST: - case PULSES_LEMON_DSMP: - return true; - case PULSES_ACCESS_R9M: - return (IS_ACCESS_RADIO(board, id) || - generalSettings.serialPort[GeneralSettings::SP_AUX1] == GeneralSettings::AUX_SERIAL_EXT_MODULE); - case PULSES_PXX_R9M_LITE: - case PULSES_ACCESS_R9M_LITE: - case PULSES_ACCESS_R9M_LITE_PRO: - case PULSES_XJT_LITE_X16: - case PULSES_XJT_LITE_D8: - case PULSES_XJT_LITE_LR12: - return (IS_TARANIS_XLITE(board) || IS_TARANIS_X9LITE(board) || IS_RADIOMASTER_ZORRO(board)); + case 1: { + const int moduleSize = g.currentProfile().externalModuleSize(); + const int moduleType = getTypeFromProtocol(protocol); + + switch(moduleSize) { + case Board::EXTMODSIZE_NONE: + return false; + case Board::EXTMODSIZE_BOTH: + switch (moduleType) { + case MODULE_TYPE_XJT_PXX1: + case MODULE_TYPE_ISRM_PXX2: + case MODULE_TYPE_R9M_PXX1: + case MODULE_TYPE_R9M_PXX2: + case MODULE_TYPE_DSM2: + case MODULE_TYPE_FLYSKY: + case MODULE_TYPE_LEMON_DSMP: + case MODULE_TYPE_R9M_LITE_PXX1: + case MODULE_TYPE_R9M_LITE_PXX2: + case MODULE_TYPE_R9M_LITE_PRO_PXX2: + case MODULE_TYPE_XJT_LITE_PXX2: + return true; + default: + return false; + } + case Board::EXTMODSIZE_STD: + switch (moduleType) { + case MODULE_TYPE_XJT_PXX1: + case MODULE_TYPE_ISRM_PXX2: + case MODULE_TYPE_R9M_PXX1: + case MODULE_TYPE_R9M_PXX2: + case MODULE_TYPE_DSM2: + case MODULE_TYPE_FLYSKY: + case MODULE_TYPE_LEMON_DSMP: + return true; + default: + return false; + } + case Board::EXTMODSIZE_SMALL: + switch (moduleType) { + case MODULE_TYPE_R9M_LITE_PXX1: + case MODULE_TYPE_R9M_LITE_PXX2: + case MODULE_TYPE_R9M_LITE_PRO_PXX2: + case MODULE_TYPE_XJT_LITE_PXX2: + return true; + default: + return false; + } default: return false; } - + } case -1: switch (protocol) { case PULSES_PPM: diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 95e84e6fe..a63b7e5d1 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -1272,6 +1272,7 @@ int MainWindow::newProfile(bool loadProfile) g.profile[i].name("New Radio"); g.profile[i].fwType(newfw->getId()); g.profile[i].defaultInternalModule(Boards::getDefaultInternalModules(newfw->getBoard())); + g.profile[i].externalModuleSize(Boards::getDefaultExternalModuleSize(newfw->getBoard())); if (loadProfile) { if (loadProfileId(i)) diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 3b1fa09bb..f7b081b2f 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -264,11 +264,16 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul if (panelFilteredItemModels) { if (moduleIdx >= 0) { int id = panelFilteredItemModels->registerItemModel(new FilteredItemModel(ModuleData::protocolItemModel(generalSettings), moduleIdx + 1/*flag cannot be 0*/), QString("Module Protocol %1").arg(moduleIdx)); + panelFilteredItemModels->getItemModel(id)->setSortCaseSensitivity(Qt::CaseInsensitive); + panelFilteredItemModels->getItemModel(id)->sort(0); ui->protocol->setModel(panelFilteredItemModels->getItemModel(id)); if (ui->protocol->findData(module.protocol) < 0) { - QString msg = tr("Warning: The internal module protocol %1 is incompatible with the hardware internal module %2 and has been set to OFF!"); - msg = msg.arg(module.protocolToString(module.protocol)).arg(ModuleData::typeToString(generalSettings.internalModule)); + const QString moduleIdxDesc = moduleIdx == 0 ? tr("internal") : tr("external"); + const QString compareDesc = moduleIdx == 0 ? tr("hardware") : tr("profile"); + const QString intModuleDesc = moduleIdx == 0 ? ModuleData::typeToString(generalSettings.internalModule) : ""; + QString msg = tr("Warning: The %1 module protocol %2 is incompatible with the %3 %1 module %4 and has been set to OFF!"); + msg = msg.arg(moduleIdxDesc).arg(module.protocolToString(module.protocol)).arg(compareDesc).arg(intModuleDesc); QMessageBox *msgBox = new QMessageBox(this); msgBox->setIcon( QMessageBox::Warning ); diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 93163b538..37fcffa99 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -486,6 +486,7 @@ class Profile: public CompStoreObj PROPERTYSTR(pBackupDir) PROPERTY (int, defaultInternalModule, 0) + PROPERTY (int, externalModuleSize, 1) // added 2.9 - Board::EXTMODSIZE_STD used for existing profiles PROPERTY4(int, channelOrder, "default_channel_order", 0) PROPERTY4(int, defaultMode, "default_mode", 1) PROPERTY (int, volumeGain, 10)