From bf7919bd8d35a68a3df642fb73219db93ebf2f9f Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 3 Mar 2014 12:24:42 +0100 Subject: [PATCH] Issue #731 - Conversion issues (Inputs) fixed --- companion/src/eeprominterface.cpp | 24 +++++- companion/src/eeprominterface.h | 13 +++- .../src/firmwares/opentx/opentxeeprom.cpp | 77 ++++++++++++++----- companion/src/firmwares/opentx/opentxeeprom.h | 9 ++- .../src/firmwares/opentx/opentxinterface.cpp | 14 ++-- companion/src/modeledit/inputs.cpp | 36 ++++----- companion/src/modeledit/mixerslist.h | 15 ++-- companion/src/modeledit/mixes.cpp | 26 ++++--- companion/src/modelslist.cpp | 44 +++++------ 9 files changed, 159 insertions(+), 99 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 38a4787c7..60f3f1324 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -242,10 +242,13 @@ QString RawSource::toString() } switch (type) { case SOURCE_TYPE_VIRTUAL_INPUT: - if (model && strlen(model->inputNames[index]) > 0) - return QString(model->inputNames[index]); - else - return QObject::tr("Input %1").arg(index+1); + { + QString result = QObject::tr("[I%1]").arg(index+1); + if (model && strlen(model->inputNames[index]) > 0) { + result += QString(model->inputNames[index]); + } + return result; + } case SOURCE_TYPE_STICK: return AnalogString(index); case SOURCE_TYPE_TRIM: @@ -893,6 +896,19 @@ ModelData::ModelData() clear(); } +ExpoData * ModelData::insertInput(const int idx) +{ + memmove(&expoData[idx+1], &expoData[idx], (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); + expoData[idx].clear(); + return &expoData[idx]; +} + +void ModelData::removeInput(const int idx) +{ + memmove(&expoData[idx], &expoData[idx+1], (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); + expoData[C9X_MAX_EXPOS-1].clear(); +} + void ModelData::clearInputs() { for (int i=0; i= 216) { internalField.Append(new UnsignedField<8>(_destCh)); @@ -878,6 +879,14 @@ class MixField: public TransformedField { virtual void afterImport() { + if (IS_TARANIS(board) || version < 216) { + if (mix.srcRaw.type == SOURCE_TYPE_STICK && mix.srcRaw.index < NUM_STICKS) { + if (!mix.noExpo) { + mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, mix.srcRaw.index, model); + } + } + } + if (mix.srcRaw.type != SOURCE_TYPE_NONE) { mix.destCh = _destCh + 1; if (!IS_ARM(board) || version < 216) { @@ -908,6 +917,7 @@ class MixField: public TransformedField { MixData & mix; BoardEnum board; unsigned int version; + ModelData * model; unsigned int _destCh; bool _curveMode; int _curveParam; @@ -917,11 +927,11 @@ class MixField: public TransformedField { unsigned int _offsetMode; }; -class ExpoField: public TransformedField { +class InputField: public TransformedField { public: - ExpoField(ExpoData & expo, BoardEnum board, unsigned int version): + InputField(ExpoData & expo, BoardEnum board, unsigned int version): TransformedField(internalField), - internalField("Expo"), + internalField("Input"), expo(expo), board(board), version(version) @@ -940,11 +950,11 @@ class ExpoField: public TransformedField { internalField.Append(new SpareBitsField<8>()); } else if (IS_ARM(board)) { - internalField.Append(new UnsignedField<8>(expo.mode)); - internalField.Append(new UnsignedField<8>(expo.chn)); + internalField.Append(new UnsignedField<8>(expo.mode, "Mode")); + internalField.Append(new UnsignedField<8>(expo.chn, "Channel")); internalField.Append(new SwitchField<8>(expo.swtch, board, version)); - internalField.Append(new UnsignedField<16>(expo.phases)); - internalField.Append(new SignedField<8>(_weight)); + internalField.Append(new UnsignedField<16>(expo.phases, "Phases")); + internalField.Append(new SignedField<8>(_weight, "Weight")); internalField.Append(new BoolField<8>(_curveMode)); if (HAS_LARGE_LCD(board)) { internalField.Append(new ZCharField<8>(expo.name)); @@ -979,6 +989,7 @@ class ExpoField: public TransformedField { virtual void beforeExport() { _weight = smallGvarToEEPROM(expo.weight); + if (!IS_TARANIS(board) || version < 216) { if (expo.curve.type==CurveReference::CURVE_REF_FUNC && expo.curve.value) { _curveMode = true; @@ -998,7 +1009,9 @@ class ExpoField: public TransformedField { virtual void afterImport() { if (IS_TARANIS(board) && version < 216) { - expo.srcRaw = RawSource(SOURCE_TYPE_STICK, expo.chn); + if (expo.mode) { + expo.srcRaw = RawSource(SOURCE_TYPE_STICK, expo.chn); + } } expo.weight = smallGvarToC9x(_weight); @@ -1278,13 +1291,14 @@ class AndSwitchesConversionTable: public ConversionTable { class LogicalSwitchField: public TransformedField { public: - LogicalSwitchField(LogicalSwitchData & csw, BoardEnum board, unsigned int version, unsigned int variant): + LogicalSwitchField(LogicalSwitchData & csw, BoardEnum board, unsigned int version, unsigned int variant, ModelData * model=NULL): TransformedField(internalField), internalField("LogicalSwitch"), csw(csw), board(board), version(version), variant(variant), + model(model), functionsConversionTable(board, version), sourcesConversionTable(SourcesConversionTable::getInstance(board, version, variant, (version >= 214 || (!IS_ARM(board) && version >= 213)) ? 0 : FLAG_NOSWITCHES)), switchesConversionTable(SwitchesConversionTable::getInstance(board, version)), @@ -1374,7 +1388,7 @@ class LogicalSwitchField: public TransformedField { else if (csw.func != LS_FN_OFF) { sourcesConversionTable->importValue((uint8_t)v1, csw.val1); csw.val2 = v2; - RawSource val1(csw.val1); + RawSource val1(csw.val1, model); if (IS_ARM(board) && version < 216 && val1.type == SOURCE_TYPE_TELEMETRY) { switch (val1.index) { case TELEMETRY_SOURCE_TIMER1: @@ -1426,6 +1440,7 @@ class LogicalSwitchField: public TransformedField { BoardEnum board; unsigned int version; unsigned int variant; + ModelData * model; LogicalSwitchesFunctionsTable functionsConversionTable; SourcesConversionTable * sourcesConversionTable; SwitchesConversionTable * switchesConversionTable; @@ -2143,11 +2158,12 @@ class MavlinkField: public StructField { int exportPpmDelay(int delay) { return (delay - 300) / 50; } int importPpmDelay(int delay) { return 300 + 50 * delay; } -Open9xModelDataNew::Open9xModelDataNew(ModelData & modelData, BoardEnum board, unsigned int version, unsigned int variant): +OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigned int version, unsigned int variant): TransformedField(internalField), internalField("ModelData"), modelData(modelData), board(board), + version(version), variant(variant), protocolsConversionTable(board) { @@ -2237,14 +2253,14 @@ Open9xModelDataNew::Open9xModelDataNew(ModelData & modelData, BoardEnum board, u internalField.Append(new UnsignedField<8>(modelData.beepANACenter)); for (int i=0; imode == INPUT_MODE_BOTH && expo->chn == i && expo->phases == 0 && expo->swtch.type == SWITCH_TYPE_NONE) + break; + if (expo->mode == 0 || expo->chn > i) { + ExpoData * newExpo = modelData.insertInput(j); + newExpo->mode = INPUT_MODE_BOTH; + newExpo->srcRaw = RawSource(SOURCE_TYPE_STICK, i); + newExpo->chn = i; + newExpo->weight = 100; + break; + } + } + strncpy(modelData.inputNames[i], AnalogString(i).toLatin1().constData(), sizeof(modelData.inputNames[i])-1); + } + } + for (int module=0; module<3; module++) { if (modelData.moduleData[module].protocol == PXX_XJT_X16 || modelData.moduleData[module].protocol == LP45) { if (subprotocols[module] >= 0) @@ -2384,7 +2419,7 @@ void Open9xModelDataNew::afterImport() } } -Open9xGeneralDataNew::Open9xGeneralDataNew(GeneralSettings & generalData, BoardEnum board, unsigned int version, unsigned int variant): +OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, BoardEnum board, unsigned int version, unsigned int variant): TransformedField(internalField), internalField("General Settings"), generalData(generalData), @@ -2521,7 +2556,7 @@ Open9xGeneralDataNew::Open9xGeneralDataNew(GeneralSettings & generalData, BoardE } } -void Open9xGeneralDataNew::beforeExport() +void OpenTxGeneralData::beforeExport() { uint16_t sum = 0; if (version >= 216) { @@ -2544,6 +2579,6 @@ void Open9xGeneralDataNew::beforeExport() chkSum = sum; } -void Open9xGeneralDataNew::afterImport() +void OpenTxGeneralData::afterImport() { } diff --git a/companion/src/firmwares/opentx/opentxeeprom.h b/companion/src/firmwares/opentx/opentxeeprom.h index 3a5f3ffa0..10f01fa50 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.h +++ b/companion/src/firmwares/opentx/opentxeeprom.h @@ -51,9 +51,9 @@ #define O9X_ARM_MAX_CSFUNCOLD 13 #define O9X_ARM_MAX_CSFUNC 15 -class Open9xGeneralDataNew: public TransformedField { +class OpenTxGeneralData: public TransformedField { public: - Open9xGeneralDataNew(GeneralSettings & generalData, BoardEnum board, unsigned int version, unsigned int variant=0); + OpenTxGeneralData(GeneralSettings & generalData, BoardEnum board, unsigned int version, unsigned int variant=0); protected: virtual void beforeExport(); @@ -113,9 +113,9 @@ class ChannelsConversionTable: public ConversionTable }; -class Open9xModelDataNew: public TransformedField { +class OpenTxModelData: public TransformedField { public: - Open9xModelDataNew(ModelData & modelData, BoardEnum board, unsigned int version, unsigned int variant); + OpenTxModelData(ModelData & modelData, BoardEnum board, unsigned int version, unsigned int variant); const char * getName() { return name; } @@ -126,6 +126,7 @@ class Open9xModelDataNew: public TransformedField { StructField internalField; ModelData & modelData; BoardEnum board; + unsigned int version; unsigned int variant; private: diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index cc08bf028..b77532130 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -236,11 +236,11 @@ bool OpenTxInterface::loadModel(uint8_t version, ModelData &model, uint8_t *data return loadModel(model, data, index); } else { - return loadModelVariant(index, model, data, version, variant); + return loadModelVariant(index, model, data, version, variant); } } else if (version >= 213) { - return loadModelVariant(index, model, data, version, variant); + return loadModelVariant(index, model, data, version, variant); } std::cout << " ko\n"; @@ -336,7 +336,7 @@ bool OpenTxInterface::load(RadioData &radioData, const uint8_t *eeprom, int size return false; } - if (!loadGeneral(radioData.generalSettings, version)) { + if (!loadGeneral(radioData.generalSettings, version)) { std::cout << " ko\n"; return false; } @@ -383,14 +383,14 @@ int OpenTxInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t varian variant |= M128_VARIANT; } - int result = saveGeneral(radioData.generalSettings, board, version, variant); + int result = saveGeneral(radioData.generalSettings, board, version, variant); if (!result) { return 0; } for (int i=0; i(i, radioData.models[i], version, variant); + result = saveModel(i, radioData.models[i], version, variant); if (!result) { return 0; } @@ -417,7 +417,7 @@ int OpenTxInterface::getSize(ModelData &model) uint8_t tmp[EESIZE_RLC_MAX]; efile->EeFsCreate(tmp, EESIZE_RLC_MAX, board); - Open9xModelDataNew open9xModel(model, board, 255, GetCurrentFirmwareVariant()); + OpenTxModelData open9xModel(model, board, 255, GetCurrentFirmwareVariant()); QByteArray eeprom; open9xModel.Export(eeprom); @@ -436,7 +436,7 @@ int OpenTxInterface::getSize(GeneralSettings &settings) uint8_t tmp[EESIZE_RLC_MAX]; efile->EeFsCreate(tmp, EESIZE_RLC_MAX, board); - Open9xGeneralDataNew open9xGeneral(settings, board, 255, GetCurrentFirmwareVariant()); + OpenTxGeneralData open9xGeneral(settings, board, 255, GetCurrentFirmwareVariant()); // open9xGeneral.Dump(); QByteArray eeprom; diff --git a/companion/src/modeledit/inputs.cpp b/companion/src/modeledit/inputs.cpp index c140585ee..a6e1f6eac 100644 --- a/companion/src/modeledit/inputs.cpp +++ b/companion/src/modeledit/inputs.cpp @@ -29,9 +29,9 @@ InputsPanel::InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & g exposLayout->addWidget(qbClear,2,2); exposLayout->addWidget(qbDown,2,3); - connect(ExposlistWidget, SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(expolistWidget_customContextMenuRequested(QPoint))); - connect(ExposlistWidget, SIGNAL(doubleClicked(QModelIndex)),this,SLOT(expolistWidget_doubleClicked(QModelIndex))); - connect(ExposlistWidget, SIGNAL(mimeDropped(int,const QMimeData*,Qt::DropAction)),this,SLOT(mimeExpoDropped(int,const QMimeData*,Qt::DropAction))); + connect(ExposlistWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(expolistWidget_customContextMenuRequested(QPoint))); + connect(ExposlistWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(expolistWidget_doubleClicked(QModelIndex))); + connect(ExposlistWidget, SIGNAL(mimeDropped(int,const QMimeData*,Qt::DropAction)), this, SLOT(mimeExpoDropped(int, const QMimeData*, Qt::DropAction))); connect(qbUp, SIGNAL(pressed()),SLOT(moveExpoUp())); connect(qbDown, SIGNAL(pressed()),SLOT(moveExpoDown())); @@ -58,7 +58,7 @@ void InputsPanel::update() ExposlistWidget->clear(); int curDest = -1; - for(int i=0; imode==0) break; @@ -144,26 +144,24 @@ void InputsPanel::update() bool InputsPanel::gm_insertExpo(int idx) { - if (idx<0 || idx>=C9X_MAX_EXPOS || model.expoData[C9X_MAX_EXPOS-1].mode > 0) { - QMessageBox::information(this, "companion", tr("Not enough available inputs!")); - return false; - } + if (idx<0 || idx>=C9X_MAX_EXPOS || model.expoData[C9X_MAX_EXPOS-1].mode > 0) { + QMessageBox::information(this, "Companion", tr("Not enough available inputs!")); + return false; + } - int chn = model.expoData[idx].chn; - memmove(&model.expoData[idx+1],&model.expoData[idx], - (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData) ); - memset(&model.expoData[idx],0,sizeof(ExpoData)); - model.expoData[idx].chn = chn; - model.expoData[idx].weight = 100; - model.expoData[idx].mode = 3 /* TODO enum */; - return true; + int chn = model.expoData[idx].chn; + + ExpoData * newExpo = model.insertInput(idx); + newExpo->chn = chn; + newExpo->weight = 100; + newExpo->mode = INPUT_MODE_BOTH; + + return true; } void InputsPanel::gm_deleteExpo(int index) { - memmove(&model.expoData[index],&model.expoData[index+1], - (C9X_MAX_EXPOS-(index+1))*sizeof(ExpoData)); - memset(&model.expoData[C9X_MAX_EXPOS-1],0,sizeof(ExpoData)); + model.removeInput(index); } void InputsPanel::gm_openExpo(int index) diff --git a/companion/src/modeledit/mixerslist.h b/companion/src/modeledit/mixerslist.h index 01b225a39..52e9ffebb 100644 --- a/companion/src/modeledit/mixerslist.h +++ b/companion/src/modeledit/mixerslist.h @@ -6,24 +6,19 @@ class MixersList : public QListWidget { Q_OBJECT -public: - explicit MixersList(QWidget *parent, bool expo); -// QMimeData * mimeData ( const QList items ); + public: + explicit MixersList(QWidget *parent, bool expo); void keyPressEvent(QKeyEvent *event); - -signals: + signals: void mimeDropped(int index, const QMimeData *data, Qt::DropAction action); void keyWasPressed(QKeyEvent *event); - -protected: - -public slots: + public slots: bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action); -private: + private: QPoint dragStartPosition; bool expo; diff --git a/companion/src/modeledit/mixes.cpp b/companion/src/modeledit/mixes.cpp index ed6016e57..df92f5ecb 100644 --- a/companion/src/modeledit/mixes.cpp +++ b/companion/src/modeledit/mixes.cpp @@ -53,15 +53,16 @@ void MixesPanel::update() int i; unsigned int outputs = GetEepromInterface()->getCapability(Outputs); int showNames = false; // TODO in a menu ui->showNames_Ckb->isChecked(); - for(i=0; igetCapability(Mixes); i++) { + for (i=0; igetCapability(Mixes); i++) { MixData *md = &model.mixData[i]; if ((md->destCh==0) || (md->destCh>outputs+(unsigned int)GetEepromInterface()->getCapability(ExtraChannels))) continue; QString str = ""; - while(curDest<(md->destCh-1)) { + while (curDest<(md->destCh-1)) { curDest++; if (curDest > outputs) { str = tr("X%1 ").arg(curDest-outputs); - } else { + } + else { str = tr("CH%1%2").arg(curDest/10).arg(curDest%10); if (GetEepromInterface()->getCapability(HasChNames) && showNames) { QString name=model.limitData[curDest-1].name; @@ -80,7 +81,8 @@ void MixesPanel::update() if (md->destCh > outputs) { str = tr("X%1 ").arg(md->destCh-outputs); - } else { + } + else { str = tr("CH%1%2").arg(md->destCh/10).arg(md->destCh%10); str.append(" "); if (GetEepromInterface()->getCapability(HasChNames) && showNames) { @@ -97,7 +99,7 @@ void MixesPanel::update() str.fill(' '); } - switch(md->mltpx) { + switch (md->mltpx) { case (1): str += " *"; break; case (2): str += " R"; break; default: str += " "; break; @@ -110,7 +112,9 @@ void MixesPanel::update() QString phasesStr = getPhasesStr(md->phases, model); if (!phasesStr.isEmpty()) str += " " + phasesStr; - if (md->swtch.type != SWITCH_TYPE_NONE) str += " " + tr("Switch(%1)").arg(md->swtch.toString()); + if (md->swtch.type != SWITCH_TYPE_NONE) { + str += " " + tr("Switch(%1)").arg(md->swtch.toString()); + } if (!GetEepromInterface()->getCapability(VirtualInputs)) { if (md->carryTrim>0) { @@ -125,9 +129,9 @@ void MixesPanel::update() if (md->sOffset) str += " " + tr("Offset(%1)").arg(getGVarString(md->sOffset)); if (md->curve.value) str += " " + md->curve.toString(); - int scale=GetEepromInterface()->getCapability(SlowScale); - if (scale==0) - scale=1; + int scale = GetEepromInterface()->getCapability(SlowScale); + if (scale == 0) + scale = 1; if (md->delayDown || md->delayUp) str += tr(" Delay(u%1:d%2)").arg((double)md->delayUp/scale).arg((double)md->delayDown/scale); if (md->speedDown || md->speedUp) @@ -144,8 +148,8 @@ void MixesPanel::update() qba.append((quint8)i); qba.append((const char*)md, sizeof(MixData)); QListWidgetItem *itm = new QListWidgetItem(str); - itm->setData(Qt::UserRole,qba); // mix number - MixerlistWidget->addItem(itm);//(str); + itm->setData(Qt::UserRole, qba); // mix number + MixerlistWidget->addItem(itm); //(str); } while(curDestgetCapability(ExtraChannels)) { diff --git a/companion/src/modelslist.cpp b/companion/src/modelslist.cpp index 088945f12..d6e72b219 100644 --- a/companion/src/modelslist.cpp +++ b/companion/src/modelslist.cpp @@ -44,36 +44,36 @@ #include "helpers.h" class DragDropHeader { -public: - DragDropHeader(): - general_settings(false), - models_count(0) - { - } - bool general_settings; - uint8_t models_count; - uint8_t models[C9X_MAX_MODELS]; + public: + DragDropHeader(): + general_settings(false), + models_count(0) + { + } + bool general_settings; + uint8_t models_count; + uint8_t models[C9X_MAX_MODELS]; }; ModelsListWidget::ModelsListWidget(QWidget *parent): QListWidget(parent) { - this->setFont(QFont("Courier New",12)); - radioData = &((MdiChild *)parent)->radioData; - refreshList(); + setFont(QFont("Courier New",12)); + radioData = &((MdiChild *)parent)->radioData; + refreshList(); - connect(this, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(OpenEditWindow())); - connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&))); - connect(this, SIGNAL(currentRowChanged(int)), this, SLOT(viableModelSelected(int))); + connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(OpenEditWindow())); + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&))); + connect(this, SIGNAL(currentRowChanged(int)), this, SLOT(viableModelSelected(int))); - setContextMenuPolicy(Qt::CustomContextMenu); - setSelectionMode(QAbstractItemView::ExtendedSelection); - setDragEnabled(true); - setAcceptDrops(true); - setDragDropOverwriteMode(true); - setDropIndicatorShown(true); + setContextMenuPolicy(Qt::CustomContextMenu); + setSelectionMode(QAbstractItemView::ExtendedSelection); + setDragEnabled(true); + setAcceptDrops(true); + setDragDropOverwriteMode(true); + setDropIndicatorShown(true); - active_highlight_color = this->palette().color(QPalette::Active, QPalette::Highlight); + active_highlight_color = palette().color(QPalette::Active, QPalette::Highlight); } void ModelsListWidget::ShowContextMenu(const QPoint& pos)