diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 98804b3d1..f2d39810a 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -170,6 +170,19 @@ enum HeliSwashTypes { extern const char * switches9X[]; extern const char * switchesX9D[]; +enum ThrottleSource { + THROTTLE_SOURCE_THR, + THROTTLE_SOURCE_P1, + THROTTLE_SOURCE_P2, + THROTTLE_SOURCE_P3, + THROTTLE_SOURCE_S1 = THROTTLE_SOURCE_P1, + THROTTLE_SOURCE_S2, + THROTTLE_SOURCE_S3, + THROTTLE_SOURCE_LS, + THROTTLE_SOURCE_RS, + THROTTLE_SOURCE_FIRST_CHANNEL, +}; + enum TelemetrySource { TELEMETRY_SOURCE_TX_BATT, TELEMETRY_SOURCE_TIMER1, diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index db597bb1f..36663659d 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -294,6 +294,32 @@ class SourcesConversionTable: public ConversionTable { } }; +ThrottleSourceConversionTable::ThrottleSourceConversionTable(BoardEnum board, unsigned int version) +{ + int val=0; + + addConversion(THROTTLE_SOURCE_THR, val++); + + if (IS_TARANIS(board)) { + addConversion(THROTTLE_SOURCE_S1, val++); + addConversion(THROTTLE_SOURCE_S2, val++); + if (version >= 216) + addConversion(THROTTLE_SOURCE_S3, val++); + addConversion(THROTTLE_SOURCE_LS, val++); + addConversion(THROTTLE_SOURCE_RS, val++); + } + else { + addConversion(THROTTLE_SOURCE_P1, val++); + addConversion(THROTTLE_SOURCE_P2, val++); + addConversion(THROTTLE_SOURCE_P3, val++); + } + + for (int i=0; i class SwitchField: public ConversionField< SignedField > { public: @@ -2178,7 +2204,8 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne board(board), version(version), variant(variant), - protocolsConversionTable(board) + protocolsConversionTable(board), + throttleSourceConversionTable(board, version) { sprintf(name, "Model %s", modelData.name); @@ -2288,7 +2315,7 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne internalField.Append(new SignedField<8>(modelData.moduleData[0].ppmFrameLength)); } - internalField.Append(new UnsignedField<8>(modelData.thrTraceSrc)); + internalField.Append(new ConversionField< UnsignedField<8> >(modelData.thrTraceSrc, &throttleSourceConversionTable, "Throttle Source")); if (!afterrelease21March2013) { internalField.Append(new UnsignedField<8>(modelData.modelId)); diff --git a/companion/src/firmwares/opentx/opentxeeprom.h b/companion/src/firmwares/opentx/opentxeeprom.h index 10f01fa50..b49f94055 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.h +++ b/companion/src/firmwares/opentx/opentxeeprom.h @@ -102,6 +102,12 @@ class ProtocolsConversionTable: public ConversionTable } }; +class ThrottleSourceConversionTable: public ConversionTable { + + public: + ThrottleSourceConversionTable(BoardEnum board, unsigned int version); +}; + class ChannelsConversionTable: public ConversionTable { public: @@ -133,6 +139,7 @@ class OpenTxModelData: public TransformedField { char name[256]; int subprotocols[C9X_NUM_MODULES+1/*trainer*/]; ProtocolsConversionTable protocolsConversionTable; + ThrottleSourceConversionTable throttleSourceConversionTable; ChannelsConversionTable channelsConversionTable; }; diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 52871a32e..381aded98 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -63,27 +63,6 @@ void populateVoiceLangCB(QComboBox *b, QString language) } } -void populateTTraceCB(QComboBox *b, int value) -{ - const QString strings9x[] = { QObject::tr("THR"), QObject::tr("P1"), QObject::tr("P2"), QObject::tr("P3")}; - const QString stringstaranis[] = { QObject::tr("THR"), QObject::tr("S1"), QObject::tr("S2"), QObject::tr("LS"), QObject::tr("RS")}; - b->clear(); - if (IS_TARANIS(GetEepromInterface()->getBoard())) { - for (int i=0; i< 5; i++) { - b->addItem(stringstaranis[i]); - } - } else { - for (int i=0; i< 4; i++) { - b->addItem(strings9x[i]); - } - } - int channels=(IS_ARM(GetEepromInterface()->getBoard()) ? 32 : 16); - for (int i=1; i<= channels; i++) { - b->addItem(QObject::tr("CH%1").arg(i, 2, 10, QChar('0'))); - } - b->setCurrentIndex(value); -} - void populateRotEncCB(QComboBox *b, int value, int renumber) { QString strings[] = { QObject::tr("No"), QObject::tr("RotEnc A"), QObject::tr("Rot Enc B"), QObject::tr("Rot Enc C"), QObject::tr("Rot Enc D"), QObject::tr("Rot Enc E")}; diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 53bff4d2f..684d3492f 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -27,7 +27,6 @@ void populateGvSourceCB(QComboBox *b, int value); void populateVoiceLangCB(QComboBox *b, QString language); -void populateTTraceCB(QComboBox *b, int value); void populateRotEncCB(QComboBox *b, int value, int renumber); void populateBacklightCB(QComboBox *b, const uint8_t value); diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 6dd46c3e0..78bbfac84 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -500,7 +500,7 @@ void Setup::on_trimIncrement_currentIndexChanged(int index) void Setup::on_throttleSource_currentIndexChanged(int index) { - model.thrTraceSrc = index; + model.thrTraceSrc = ui->throttleSource->itemData(index).toInt(); emit modified(); } @@ -543,12 +543,39 @@ void Setup::on_image_currentIndexChanged(int index) } } +void Setup::populateThrottleSourceCB() +{ + const QString sources9x[] = { QObject::tr("THR"), QObject::tr("P1"), QObject::tr("P2"), QObject::tr("P3")}; + const QString sourcesTaranis[] = { QObject::tr("THR"), QObject::tr("S1"), QObject::tr("S2"), QObject::tr("S3"), QObject::tr("LS"), QObject::tr("RS")}; + + unsigned int i; + + if (IS_TARANIS(GetEepromInterface()->getBoard())) { + for (i=0; i<6; i++) { + ui->throttleSource->addItem(sourcesTaranis[i], i); + } + } + else { + for (i=0; i<4; i++) { + ui->throttleSource->addItem(sources9x[i], i); + } + } + + if (model.thrTraceSrc < i) ui->throttleSource->setCurrentIndex(model.thrTraceSrc); + + int channels = (IS_ARM(GetEepromInterface()->getBoard()) ? 32 : 16); + for (int i=0; ithrottleSource->addItem(QObject::tr("CH%1").arg(i+1, 2, 10, QChar('0')), THROTTLE_SOURCE_FIRST_CHANNEL+i); + if (model.thrTraceSrc == unsigned(THROTTLE_SOURCE_FIRST_CHANNEL+i)) ui->throttleSource->setCurrentIndex(ui->throttleSource->count()-1); + } +} + void Setup::update() { ui->name->setText(model.name); ui->throttleReverse->setChecked(model.throttleReversed); - populateTTraceCB(ui->throttleSource, model.thrTraceSrc); + populateThrottleSourceCB(); ui->throttleWarning->setChecked(!model.disableThrottleWarning); //trim inc, thro trim, thro expo, instatrim diff --git a/companion/src/modeledit/setup.h b/companion/src/modeledit/setup.h index b785e2750..6880c363f 100644 --- a/companion/src/modeledit/setup.h +++ b/companion/src/modeledit/setup.h @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace Ui { @@ -104,6 +105,7 @@ class Setup : public ModelPanel void updateStartupSwitches(); void updatePotWarnings(); void updateBeepCenter(); + void populateThrottleSourceCB(); }; #endif // SETUP_H