From 806715e16659c6e49e3bd10ea2d97844502f5568 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 2 Jun 2018 18:16:51 +0200 Subject: [PATCH] Bsongis/companion r9m fixes (#5914) * Cosmetics * First part ... * First part ... * Second part ... * End? * Handle new R9M and R9M lite * Display 'mini' module in case of R9M and xlite --- companion/src/firmwares/CMakeLists.txt | 1 + companion/src/firmwares/modeldata.cpp | 4 + companion/src/firmwares/moduledata.cpp | 29 ++ companion/src/firmwares/moduledata.h | 8 + companion/src/modeledit/setup.cpp | 44 ++- companion/src/modeledit/setup_module.ui | 490 ++++++++++++++++++++++++++++---- companion/src/modelprinter.cpp | 23 +- companion/src/modelprinter.h | 2 +- radio/src/gui/128x64/model_setup.cpp | 2 +- 9 files changed, 536 insertions(+), 67 deletions(-) create mode 100644 companion/src/firmwares/moduledata.cpp diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 7671e550b..b6b8fcaba 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -9,6 +9,7 @@ set(firmwares_SRCS io_data.cpp logicalswitchdata.cpp modeldata.cpp + moduledata.cpp multiprotocols.cpp radiodata.cpp radiodataconversionstate.cpp diff --git a/companion/src/firmwares/modeldata.cpp b/companion/src/firmwares/modeldata.cpp index 9a9c71579..bb8e7ce1a 100644 --- a/companion/src/firmwares/modeldata.cpp +++ b/companion/src/firmwares/modeldata.cpp @@ -454,4 +454,8 @@ void ModelData::convert(RadioDataConversionState & cstate) for (int i=0; i +class RadioDataConversionState; + enum PulsesProtocol { PULSES_OFF, PULSES_PPM, @@ -97,6 +99,11 @@ enum TrainerProtocol { TRAINER_MASTER_SBUS_BATT_COMPARTMENT }; +enum R9MSubTypes { + R9M_FCC, + R9M_LBT +}; + class ModuleData { Q_DECLARE_TR_FUNCTIONS(ModuleData) @@ -138,6 +145,7 @@ class ModuleData { void clear() { memset(this, 0, sizeof(ModuleData)); } QString polarityToString() const { return ppm.pulsePol ? tr("Positive") : tr("Negative"); } // TODO ModelPrinter + void convert(RadioDataConversionState & cstate); }; #endif // MODULEDATA_H diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 689dfab89..8cf7928c7 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -23,7 +23,6 @@ #include "ui_setup_timer.h" #include "ui_setup_module.h" #include "switchitemmodel.h" -#include "helpers.h" #include "appdata.h" #include "modelprinter.h" #include "multiprotocols.h" @@ -228,8 +227,11 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul // The protocols available on this board for (int i=0; iisAvailable((PulsesProtocol)i, moduleIdx)) { - ui->protocol->addItem(ModelPrinter::printModuleProtocol(i), (QVariant)i); + if (firmware->isAvailable((PulsesProtocol) i, moduleIdx)) { + if (IS_TARANIS_XLITE(firmware->getBoard()) && i == PULSES_PXX_R9M) //TODO remove when mini are handled as a different module type + ui->protocol->addItem("FrSky R9M Mini", (QVariant) i); + else + ui->protocol->addItem(ModelPrinter::printModuleProtocol(i), (QVariant) i); if (i == module.protocol) ui->protocol->setCurrentIndex(ui->protocol->count()-1); } @@ -476,9 +478,37 @@ void ModulePanel::update() ui->antennaMode->setCurrentIndex(module.pxx.external_antenna); // R9M options - ui->r9mPower->setVisible((mask & MASK_R9M) && module.subType == 0); - ui->label_r9mPower->setVisible((mask & MASK_R9M) && module.subType == 0); + ui->r9mPower->setVisible(mask & MASK_R9M); + ui->label_r9mPower->setVisible(mask & MASK_R9M); + ui->warning_r9mPower->setVisible((mask & MASK_R9M) && module.subType == R9M_LBT); + if (mask & MASK_R9M) { + ui->r9mPower->clear(); + Board::Type board = firmware->getBoard(); + if (IS_TARANIS_XLITE(board)) { + if (module.subType == R9M_FCC) { + ui->r9mPower->addItem(tr("100 mW - 16CH")); + } + else { + ui->r9mPower->addItem(tr("25 mW - 8CH")); + ui->r9mPower->addItem(tr("25 mW - 16CH")); + ui->r9mPower->addItem(tr("100 mW - 16CH, no telemetry")); + } + } + else { + if (module.subType == R9M_FCC) { + ui->r9mPower->addItem(tr("10 mW - 16CH")); + ui->r9mPower->addItem(tr("100 mW - 16CH")); + ui->r9mPower->addItem(tr("500 mW - 16CH")); + ui->r9mPower->addItem(tr("1000 mW - 16CH")); + } + else { + ui->r9mPower->addItem(tr("25 mW - 8CH")); + ui->r9mPower->addItem(tr("25 mW - 16CH")); + ui->r9mPower->addItem(tr("200 mW - 16CH")); + ui->r9mPower->addItem(tr("500 mW - 16CH")); + } + } ui->r9mPower->setCurrentIndex(module.pxx.power); } @@ -508,8 +538,8 @@ void ModulePanel::update() if (mask & MASK_MULTIMODULE) { ui->multiProtocol->setCurrentIndex(module.multi.rfProtocol); - ui->autoBind->setChecked(module.multi.autoBindMode ? Qt::Checked : Qt::Unchecked); - ui->lowPower->setChecked(module.multi.lowPowerMode ? Qt::Checked : Qt::Unchecked); + ui->autoBind->setChecked(module.multi.autoBindMode); + ui->lowPower->setChecked(module.multi.lowPowerMode); } if (mask & MASK_MULTIOPTION) { diff --git a/companion/src/modeledit/setup_module.ui b/companion/src/modeledit/setup_module.ui index d07ec95ca..44ea66860 100644 --- a/companion/src/modeledit/setup_module.ui +++ b/companion/src/modeledit/setup_module.ui @@ -6,8 +6,8 @@ 0 0 - 708 - 259 + 1042 + 315 @@ -237,30 +237,9 @@ - - - - 10 mW - - - - - 100 mW - - - - - 500 mW - - - - - 1000 mW - - - + - + @@ -278,6 +257,428 @@ + + + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + 255 + 127 + 127 + + + + + + + 255 + 63 + 63 + + + + + + + 127 + 0 + 0 + + + + + + + 170 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 127 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + 255 + 127 + 127 + + + + + + + 255 + 63 + 63 + + + + + + + 127 + 0 + 0 + + + + + + + 170 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 127 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 127 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + 255 + 127 + 127 + + + + + + + 255 + 63 + 63 + + + + + + + 127 + 0 + 0 + + + + + + + 170 + 0 + 0 + + + + + + + 127 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 127 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + WARNING: changing RF Output Power needs RE-BIND + + + @@ -707,6 +1108,19 @@ + + + + Qt::Vertical + + + + 20 + 0 + + + + @@ -796,32 +1210,6 @@ QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; pad - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - diff --git a/companion/src/modelprinter.cpp b/companion/src/modelprinter.cpp index 3e3accf05..9d3b1214d 100644 --- a/companion/src/modelprinter.cpp +++ b/companion/src/modelprinter.cpp @@ -201,13 +201,13 @@ QString ModelPrinter::printModuleProtocol(unsigned int protocol) QString ModelPrinter::printMultiRfProtocol(int rfProtocol, bool custom) { - static const char *strings[] = { + static const char * strings[] = { "FlySky", "Hubsan", "FrSky", "Hisky", "V2x2", "DSM", "Devo", "YD717", "KN", "SymaX", "SLT", "CX10", "CG023", "Bayang", "ESky", "MT99XX", "MJXQ", "Shenqi", "FY326", "SFHSS", "J6 PRO","FQ777","Assan","Hontai","OLRS", "FlySky AFHDS2A", "Q2x2", "Walkera", "Q303", "GW008", "DM002", "CABELL", "Esky 150", "H8 3D", "Corona", "CFlie" }; if (custom) - return "Custom - proto " + QString::number(rfProtocol); + return QObject::tr("Custom - proto %1)").arg(QString::number(rfProtocol)); else return CHECK_IN_ARRAY(strings, rfProtocol); } @@ -228,13 +228,22 @@ QString ModelPrinter::printMultiSubType(unsigned rfProtocol, bool custom, unsign QString ModelPrinter::printR9MPowerValue(unsigned subType, unsigned val, bool telem) { - static const QStringList strFTC = QStringList() << tr("10mW") << tr("100mW") << tr("500mW") << tr("1W"); - static const QStringList strLBT = QStringList() << tr("25mW") << tr("500mW"); + QStringList strFCC; + QStringList strLBT; + + if (IS_TARANIS_XLITE(firmware->getBoard())) { + strFCC = QStringList() << tr("100mW - 16CH"); + strLBT = QStringList() << tr("25mW - 8CH") << tr("25mW - 16CH") << tr("100mW 16CH"); + } + else { + strFCC = QStringList() << tr("10mW") << tr("100mW") << tr("500mW") << tr("1W"); + strLBT = QStringList() << tr("25mW - 8CH") << tr("25mW - 16CH") << tr("200mW 16CH") << tr("500mW 16CH"); + } - if (subType == 0 && (int)val < strFTC.size()) - return strFTC.at(val); - else if (subType == 1) + if (subType == R9M_FCC && (int)val < strFCC.size()) + return strFCC.at(val); + else if (subType == R9M_LBT) return (telem ? strLBT.at(0) : strLBT.at(1)); else return "???"; diff --git a/companion/src/modelprinter.h b/companion/src/modelprinter.h index 777772164..fd1df94a2 100644 --- a/companion/src/modelprinter.h +++ b/companion/src/modelprinter.h @@ -59,7 +59,7 @@ class ModelPrinter: public QObject QString printThrottle(); static QString printModuleProtocol(unsigned int protocol); static QString printMultiRfProtocol(int rfProtocol, bool custom); - static QString printR9MPowerValue(unsigned subType, unsigned val, bool telem); + QString printR9MPowerValue(unsigned subType, unsigned val, bool telem); static QString printMultiSubType(unsigned rfProtocol, bool custom, unsigned int subType); static QString printModuleSubType(unsigned protocol, unsigned subType, unsigned rfProtocol = 0, bool custom = false); QString printFlightModeSwitch(const RawSwitch & swtch); diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index 3ff3e6459..5c79385c6 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -1320,7 +1320,7 @@ void menuModelSetup(event_t event) uint8_t moduleIdx = CURRENT_MODULE_EDITED(k); if (IS_MODULE_R9M(moduleIdx)) { lcdDrawTextAlignedLeft(y, TR_MULTI_RFPOWER); - if(IS_MODULE_R9M_FCC(moduleIdx)) { + if (IS_MODULE_R9M_FCC(moduleIdx)) { g_model.moduleData[moduleIdx].pxx.power = min((uint8_t)g_model.moduleData[moduleIdx].pxx.power, (uint8_t)R9M_FCC_POWER_MAX); // Lite FCC has only one setting #if defined(MODULE_R9M_FULLSIZE) lcdDrawTextAtIndex(MODEL_SETUP_2ND_COLUMN, y, STR_R9M_FCC_POWER_VALUES, g_model.moduleData[moduleIdx].pxx.power, LEFT | attr); -- 2.11.4.GIT