From 854af385847aa533824a7e8a04677a34f88e5f19 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 17 Jul 2023 06:48:12 +1000 Subject: [PATCH] enh(cpn): more support for afhds2a and 3 --- companion/src/firmwares/CMakeLists.txt | 1 - companion/src/firmwares/afhds3.cpp | 12 ---- companion/src/firmwares/afhds3.h | 12 ---- companion/src/firmwares/moduledata.cpp | 74 ++++++++++++++++++++++++- companion/src/firmwares/moduledata.h | 25 ++++++++- companion/src/modeledit/setup.cpp | 64 ++++++++++++++++++--- companion/src/modeledit/setup_module.ui | 37 +++++++++---- 7 files changed, 179 insertions(+), 46 deletions(-) delete mode 100644 companion/src/firmwares/afhds3.cpp delete mode 100644 companion/src/firmwares/afhds3.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 0724ea28606..a96617f9933 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -24,7 +24,6 @@ set(firmwares_SRCS sensordata.cpp telem_data.cpp timerdata.cpp - afhds3.cpp ersky9x/ersky9xeeprom.cpp ersky9x/ersky9xinterface.cpp opentx/opentxeeprom.cpp diff --git a/companion/src/firmwares/afhds3.cpp b/companion/src/firmwares/afhds3.cpp deleted file mode 100644 index 000fb252c0a..00000000000 --- a/companion/src/firmwares/afhds3.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "afhds3.h" -#include "macros.h" - -QString Afhds3Data::protocolToString(unsigned int protocol) { - const char * const afhds3Protocols[] = { - "PWM/IBUS", - "PWM/SBUS", - "PPM/IBUS", - "PPM/SBUS", - }; - return CHECK_IN_ARRAY(afhds3Protocols, protocol); -} diff --git a/companion/src/firmwares/afhds3.h b/companion/src/firmwares/afhds3.h deleted file mode 100644 index ea4257fba7e..00000000000 --- a/companion/src/firmwares/afhds3.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef AFHDS3_H -#define AFHDS3_H - -#include - -class Afhds3Data -{ - Q_DECLARE_TR_FUNCTIONS(Afhds3) -public: - static QString protocolToString(unsigned int protocol); -}; -#endif // AFHDS3_H diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index 8fd4077c6f7..96bcf2e067e 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -21,10 +21,10 @@ #include "moduledata.h" #include "eeprominterface.h" #include "multiprotocols.h" -#include "afhds3.h" #include "radiodataconversionstate.h" #include "compounditemmodels.h" #include "generalsettings.h" +#include "helpers.h" #include #include @@ -665,3 +665,75 @@ AbstractStaticItemModel * ModuleData::telemetryBaudrateItemModel(unsigned int p mdl->loadItemList(); return mdl; } + +QString ModuleData::afhds2aMode1ToString() const +{ + return afhds2aMode1List.at(Helpers::getBitmappedValue(flysky.mode, 1)); +} + +QString ModuleData::afhds2aMode2ToString() const +{ + return afhds2aMode2List.at(Helpers::getBitmappedValue(flysky.mode, 2)); +} + +QString ModuleData::afhds3PhyModeToString() const +{ + return afhds3PhyModeList.at(afhds3.phyMode); +} + +QString ModuleData::afhds3EmiToString() const +{ + return afhds3EmiList.at(afhds3.emi); +} + +AbstractStaticItemModel * ModuleData::afhds2aMode1ItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("moduledata.afhds2aMode1"); + + for (int i = 0; i < afhds2aMode1List.size(); i++) { + mdl->appendToItemList(afhds2aMode1List.at(i), i); + } + + mdl->loadItemList(); + return mdl; +} + +AbstractStaticItemModel * ModuleData::afhds2aMode2ItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("moduledata.afhds2aMode2"); + + for (int i = 0; i < afhds2aMode2List.size(); i++) { + mdl->appendToItemList(afhds2aMode2List.at(i), i); + } + + mdl->loadItemList(); + return mdl; +} + +AbstractStaticItemModel * ModuleData::afhds3PhyModeItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("moduledata.afhds3PhyMode"); + + for (int i = 0; i < afhds3PhyModeList.size(); i++) { + mdl->appendToItemList(afhds3PhyModeList.at(i), i); + } + + mdl->loadItemList(); + return mdl; +} + +AbstractStaticItemModel * ModuleData::afhds3EmiItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("moduledata.afhds3Emi"); + + for (int i = 0; i < afhds3EmiList.size(); i++) { + mdl->appendToItemList(afhds3EmiList.at(i), i + 1); // Note: 1 based + } + + mdl->loadItemList(); + return mdl; +} diff --git a/companion/src/firmwares/moduledata.h b/companion/src/firmwares/moduledata.h index 2d84ddec57c..1f750f3b9f7 100644 --- a/companion/src/firmwares/moduledata.h +++ b/companion/src/firmwares/moduledata.h @@ -104,6 +104,11 @@ enum ModuleSubtypeR9M { constexpr int PXX2_MAX_RECEIVERS_PER_MODULE = 3; constexpr int PXX2_LEN_RX_NAME = 8; +static const QStringList afhds2aMode1List({"PWM", "PPM"}); +static const QStringList afhds2aMode2List({"IBUS", "SBUS"}); +static const QStringList afhds3PhyModeList({"Classic 18ch", "C-Fast 10ch", "Routine 18ch", "Fast 8ch", "Lora 12ch"}); +static const QStringList afhds3EmiList({"CE", "FCC"}); + class ModuleData { Q_DECLARE_TR_FUNCTIONS(ModuleData) @@ -161,6 +166,14 @@ class ModuleData { unsigned int phyMode; unsigned int reserved; unsigned int rfPower; + + void setDefault() { + emi = 1; + telemetry = 0; + phyMode = 0; + reserved = 0; + rfPower = 0; + } } afhds3; struct PXX { @@ -208,6 +221,16 @@ class ModuleData { static AbstractStaticItemModel * internalModuleItemModel(int board = -1); static bool isProtocolAvailable(int moduleidx, unsigned int protocol, GeneralSettings & generalSettings); static AbstractStaticItemModel * protocolItemModel(GeneralSettings & settings); - static AbstractStaticItemModel * telemetryBaudrateItemModel(unsigned int protocol); + static AbstractStaticItemModel * telemetryBaudrateItemModel(unsigned int protocol); static bool isAvailable(PulsesProtocol proto, int port = 0); // moved from OpenTxFirmware EdgeTX v2.9 - TODO remove and use isProtocolAvailable + + QString afhds2aMode1ToString() const; + QString afhds2aMode2ToString() const; + QString afhds3PhyModeToString() const; + QString afhds3EmiToString() const; + + static AbstractStaticItemModel * afhds2aMode1ItemModel(); + static AbstractStaticItemModel * afhds2aMode2ItemModel(); + static AbstractStaticItemModel * afhds3PhyModeItemModel(); + static AbstractStaticItemModel * afhds3EmiItemModel(); }; diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index fe5a520bd15..a652300feb4 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -224,6 +224,7 @@ void TimerPanel::onModeChanged(int index) #define MASK_MULTI_DSM_OPT (1<<19) #define MASK_CHANNELMAP (1<<20) #define MASK_MULTI_BAYANG_OPT (1<<21) +#define MASK_AFHDS (1<<22) quint8 ModulePanel::failsafesValueDisplayType = ModulePanel::FAILSAFE_DISPLAY_PERCENT; @@ -314,9 +315,32 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul connect(ui->clearRx1, SIGNAL(clicked()), this, SLOT(onClearAccessRxClicked())); connect(ui->clearRx2, SIGNAL(clicked()), this, SLOT(onClearAccessRxClicked())); connect(ui->clearRx3, SIGNAL(clicked()), this, SLOT(onClearAccessRxClicked())); + connect(ui->cboAfhdsOpt1, static_cast(&QComboBox::currentIndexChanged), [=] (int index) + { + if (lock) + return; - lock = false; + if (this->module.protocol == PULSES_FLYSKY_AFHDS2A) + Helpers::setBitmappedValue(this->module.flysky.mode, ui->cboAfhdsOpt1->currentData().toInt(), 1); + else + this->module.afhds3.phyMode = ui->cboAfhdsOpt1->currentData().toInt(); + + emit modified(); + }); + connect(ui->cboAfhdsOpt2, static_cast(&QComboBox::currentIndexChanged), [=] (int index) + { + if (lock) + return; + + if (this->module.protocol == PULSES_FLYSKY_AFHDS2A) + Helpers::setBitmappedValue(this->module.flysky.mode, ui->cboAfhdsOpt2->currentData().toInt(), 0); + else + this->module.afhds3.emi = ui->cboAfhdsOpt2->currentData().toInt(); + emit modified(); + }); + + lock = false; } ModulePanel::~ModulePanel() @@ -523,13 +547,10 @@ void ModulePanel::update() if (pdef.disableChannelMap) mask |= MASK_CHANNELMAP; break; - case PULSES_FLYSKY_AFHDS2A: - mask |= MASK_CHANNELS_RANGE| MASK_CHANNELS_COUNT | MASK_FAILSAFES; - mask |= MASK_RX_FREQ | MASK_RF_POWER; - break; case PULSES_FLYSKY_AFHDS3: - mask |= MASK_CHANNELS_RANGE| MASK_CHANNELS_COUNT | MASK_FAILSAFES; - mask |= MASK_RF_POWER; + mask |= MASK_RX_NUMBER; + case PULSES_FLYSKY_AFHDS2A: + mask |= MASK_CHANNELS_RANGE| MASK_CHANNELS_COUNT | MASK_FAILSAFES | MASK_AFHDS; break; case PULSES_LEMON_DSMP: mask |= MASK_CHANNELS_RANGE; @@ -749,11 +770,33 @@ void ModulePanel::update() ui->clearRx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 2))); ui->rx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 2))); + // AFHFS + if (mask & MASK_AFHDS) { + if (protocol == PULSES_FLYSKY_AFHDS2A) { + ui->label_afhds->setText(tr("Options")); + ui->cboAfhdsOpt1->setModel(ModuleData::afhds2aMode1ItemModel()); + ui->cboAfhdsOpt1->setCurrentIndex(Helpers::getBitmappedValue(module.flysky.mode, 1)); + + ui->cboAfhdsOpt2->setModel(ModuleData::afhds2aMode2ItemModel()); + ui->cboAfhdsOpt2->setCurrentIndex(Helpers::getBitmappedValue(module.flysky.mode, 0)); + } + else { + ui->label_afhds->setText(tr("Type")); + ui->cboAfhdsOpt1->setModel(ModuleData::afhds3PhyModeItemModel()); + ui->cboAfhdsOpt1->setCurrentIndex(ui->cboAfhdsOpt1->findData(module.afhds3.phyMode)); + + ui->cboAfhdsOpt2->setModel(ModuleData::afhds3EmiItemModel()); + ui->cboAfhdsOpt2->setCurrentIndex(ui->cboAfhdsOpt2->findData(module.afhds3.emi)); + } + } + + ui->label_afhds->setVisible(mask & MASK_AFHDS); + ui->cboAfhdsOpt1->setVisible(mask & MASK_AFHDS); + ui->cboAfhdsOpt2->setVisible(mask & MASK_AFHDS); + // Failsafes ui->label_failsafeMode->setVisible(mask & MASK_FAILSAFES); ui->failsafeMode->setVisible(mask & MASK_FAILSAFES); - //hide receiver mode for afhds2a or afhds3 - qobject_cast(ui->failsafeMode->view())->setRowHidden(FAILSAFE_RECEIVER, (protocol == PULSES_FLYSKY_AFHDS2A || protocol == PULSES_FLYSKY_AFHDS3)); if ((mask & MASK_FAILSAFES) && module.failsafeMode == FAILSAFE_CUSTOM) { if (ui->failsafesGroupBox->isHidden()) { @@ -810,6 +853,9 @@ void ModulePanel::onProtocolChanged(int index) else if (module.protocol == PULSES_FLYSKY_AFHDS2A) { module.flysky.setDefault(); } + else if (module.protocol == PULSES_FLYSKY_AFHDS3) { + module.afhds3.setDefault(); + } emit updateItemModels(); emit modified(); diff --git a/companion/src/modeledit/setup_module.ui b/companion/src/modeledit/setup_module.ui index 3adbb69e569..51e71f6f9c3 100644 --- a/companion/src/modeledit/setup_module.ui +++ b/companion/src/modeledit/setup_module.ui @@ -232,7 +232,7 @@ - + @@ -276,7 +276,7 @@ - + @@ -292,7 +292,7 @@ - + @@ -336,7 +336,7 @@ - + @@ -352,7 +352,7 @@ - + @@ -371,35 +371,35 @@ - + Disable Telemetry - + Disable Ch. Map - + Racing Mode - + Raw 12 bits - + Qt::Horizontal @@ -412,6 +412,23 @@ + + + + Options + + + + + + + + + + + + +