diff --git a/companion/src/generaledit/CMakeLists.txt b/companion/src/generaledit/CMakeLists.txt index 81415e5bd..471705b4a 100644 --- a/companion/src/generaledit/CMakeLists.txt +++ b/companion/src/generaledit/CMakeLists.txt @@ -4,13 +4,15 @@ set(generaledit_NAMES generaledit generalsetup trainer - calibration + hardware ) set(generaledit_SRCS + calibration.cpp ) set(generaledit_HDRS + calibration.h ) set(generaledit_UIS diff --git a/companion/src/generaledit/calibration.cpp b/companion/src/generaledit/calibration.cpp index 1cc155b21..85366b633 100644 --- a/companion/src/generaledit/calibration.cpp +++ b/companion/src/generaledit/calibration.cpp @@ -1,429 +1,90 @@ +#include +#include +#include #include "calibration.h" -#include "ui_calibration.h" -void CalibrationPanel::setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos = true) -{ - bool enabled = false; - - if (IS_TARANIS(firmware->getBoard())) { - if (IS_TARANIS_X9E(firmware->getBoard())) { - enabled = true; - type->addItem(tr("None"), GeneralSettings::SWITCH_NONE); - } - else if (index < 8) { - enabled = true; - } - } - - if (enabled) { - type->addItem(tr("2 Positions Toggle"), GeneralSettings::SWITCH_TOGGLE); - type->addItem(tr("2 Positions"), GeneralSettings::SWITCH_2POS); - if (threePos) type->addItem(tr("3 Positions"), GeneralSettings::SWITCH_3POS); - name->setField(generalSettings.switchName[index], 3, this); - type->setField(generalSettings.switchConfig[index], this); - } - else { - label->hide(); - name->hide(); - type->hide(); - } -} - -void CalibrationPanel::setupPotConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type) -{ - bool enabled = false; - - if (IS_TARANIS_X9E(firmware->getBoard()) && index < 4) { - label->setText(RawSource(SOURCE_TYPE_STICK, index+NUM_STICKS).toString()); - enabled = true; - } - else if (IS_TARANIS_PLUS(firmware->getBoard()) && index < 3) { - enabled = true; - } - else if (IS_TARANIS(firmware->getBoard()) && index < 2) { - enabled = true; - } - - if (enabled) { - type->addItem(tr("None"), GeneralSettings::POT_NONE); - type->addItem(tr("Pot with detent"), GeneralSettings::POT_WITH_DETENT); - type->addItem(tr("Multipos switch"), GeneralSettings::POT_MULTIPOS_SWITCH); - type->addItem(tr("Pot without detent"), GeneralSettings::POT_WITHOUT_DETENT); - name->setField(generalSettings.potName[index], 3, this); - type->setField(generalSettings.potConfig[index], this); - } - else { - label->hide(); - name->hide(); - type->hide(); - } -} - -void CalibrationPanel::setupSliderConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type) -{ - bool enabled = false; - - if (IS_TARANIS(firmware->getBoard()) && index < 2) { - type->setEnabled(false); - enabled = true; - } - else if (IS_TARANIS_X9E(firmware->getBoard()) && index < 4) { - enabled = true; - } - - if (IS_TARANIS_X9E(firmware->getBoard())) { - label->setText(RawSource(SOURCE_TYPE_STICK, index+NUM_STICKS+4).toString()); - } - - if (enabled) { - type->addItem(tr("None"), GeneralSettings::SLIDER_NONE); - type->addItem(tr("Slider with detent"), GeneralSettings::SLIDER_WITH_DETENT); - name->setField(generalSettings.sliderName[index], 3, this); - type->setField(generalSettings.sliderConfig[index], this); - } - else { - label->hide(); - name->hide(); - type->hide(); - } -} CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware): - GeneralPanel(parent, generalSettings, firmware), - ui(new Ui::Calibration) + GeneralPanel(parent, generalSettings, firmware) { - ui->setupUi(this); - if (!firmware->getCapability(MultiposPots)) { - ui->potsTypeSeparator->hide(); + tableWidget = new QTableWidget(); + QVBoxLayout * layout = new QVBoxLayout(); + layout->addWidget(tableWidget); + layout->setContentsMargins(0, 0, 0, 0); + this->setLayout(layout); + + tableWidget->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); + tableWidget->setColumnCount(3); + tableWidget->setShowGrid(false); + tableWidget->setSelectionMode(QAbstractItemView::NoSelection); + tableWidget->setFrameStyle(QFrame::NoFrame | QFrame::Plain); + tableWidget->setStyleSheet("QTableWidget {background-color: transparent;}"); + QStringList headerLabels; + headerLabels << QObject::tr("Negative span") << QObject::tr("Mid value") << QObject::tr("Positive span"); + tableWidget->setHorizontalHeaderLabels(headerLabels); + + int rows = NUM_STICKS + GetCurrentFirmware()->getCapability(Pots) + GetCurrentFirmware()->getCapability(Sliders); + tableWidget->setRowCount(rows); + + for(int i = 0; i < rows; ++i) { + + QTableWidgetItem *newItem = new QTableWidgetItem(AnalogString(i)); + newItem->setTextAlignment(Qt::AlignLeft); + tableWidget->setVerticalHeaderItem(i, newItem); + + for(int j = 0; j < 3; ++j) { + QSpinBox * newItem = new QSpinBox(); + newItem->setMinimum(-9999); + newItem->setMaximum(9999); + newItem->setSingleStep(1); + newItem->setValue(getCalibrationValue(i, j)); + newItem->setProperty("row", i); + newItem->setProperty("column", j); + tableWidget->setCellWidget(i, j, newItem); + connect(newItem, SIGNAL(valueChanged(int)), this, SLOT(onCellChanged(int))); + } } - - if (IS_TARANIS(firmware->getBoard())) { - ui->rudName->setField(generalSettings.stickName[0], 3, this); - ui->eleName->setField(generalSettings.stickName[1], 3, this); - ui->thrName->setField(generalSettings.stickName[2], 3, this); - ui->ailName->setField(generalSettings.stickName[3], 3, this); - } - else { - ui->rudLabel->hide(); - ui->rudName->hide(); - ui->eleLabel->hide(); - ui->eleName->hide(); - ui->thrLabel->hide(); - ui->thrName->hide(); - ui->ailLabel->hide(); - ui->ailName->hide(); - } - - setupPotConfig(0, ui->pot1Label, ui->pot1Name, ui->pot1Type); - setupPotConfig(1, ui->pot2Label, ui->pot2Name, ui->pot2Type); - setupPotConfig(2, ui->pot3Label, ui->pot3Name, ui->pot3Type); - setupPotConfig(3, ui->pot4Label, ui->pot4Name, ui->pot4Type); - - setupSliderConfig(0, ui->lsLabel, ui->lsName, ui->lsType); - setupSliderConfig(1, ui->rsLabel, ui->rsName, ui->rsType); - setupSliderConfig(2, ui->ls2Label, ui->ls2Name, ui->ls2Type); - setupSliderConfig(3, ui->rs2Label, ui->rs2Name, ui->rs2Type); - - setupSwitchConfig(0, ui->saLabel, ui->saName, ui->saType); - setupSwitchConfig(1, ui->sbLabel, ui->sbName, ui->sbType); - setupSwitchConfig(2, ui->scLabel, ui->scName, ui->scType); - setupSwitchConfig(3, ui->sdLabel, ui->sdName, ui->sdType); - setupSwitchConfig(4, ui->seLabel, ui->seName, ui->seType); - setupSwitchConfig(5, ui->sfLabel, ui->sfName, ui->sfType, false); //switch does not support 3POS - setupSwitchConfig(6, ui->sgLabel, ui->sgName, ui->sgType); - setupSwitchConfig(7, ui->shLabel, ui->shName, ui->shType, false); //switch does not support 3POS - setupSwitchConfig(8, ui->siLabel, ui->siName, ui->siType); - setupSwitchConfig(9, ui->sjLabel, ui->sjName, ui->sjType); - setupSwitchConfig(10, ui->skLabel, ui->skName, ui->skType); - setupSwitchConfig(11, ui->slLabel, ui->slName, ui->slType); - setupSwitchConfig(12, ui->smLabel, ui->smName, ui->smType); - setupSwitchConfig(13, ui->snLabel, ui->snName, ui->snType); - setupSwitchConfig(14, ui->soLabel, ui->soName, ui->soType); - setupSwitchConfig(15, ui->spLabel, ui->spName, ui->spType); - setupSwitchConfig(16, ui->sqLabel, ui->sqName, ui->sqType); - setupSwitchConfig(17, ui->srLabel, ui->srName, ui->srType); - - int potsCount = GetCurrentFirmware()->getCapability(Pots); - if (potsCount == 3) { - ui->ana8Neg->hide(); - ui->ana8Mid->hide(); - ui->ana8Pos->hide(); - } - - if (IS_TARANIS(firmware->getBoard())) { - ui->serialPortMode->setCurrentIndex(generalSettings.hw_uartMode); - } - else { - ui->serialPortMode->hide(); - ui->serialPortLabel->hide(); - } - - if (!IS_SKY9X(firmware->getBoard())) { - ui->txCurrentCalibration->hide(); - ui->txCurrentCalibrationLabel->hide(); - } - - if (IS_TARANIS_X9E(firmware->getBoard())) { - ui->bluetoothEnable->setChecked(generalSettings.bluetoothEnable); - ui->bluetoothName->setField(generalSettings.bluetoothName, 10, this); - } - else { - ui->bluetoothLabel->hide(); - ui->bluetoothEnable->hide(); - ui->bluetoothName->hide(); - } - disableMouseScrolling(); - - setValues(); } -CalibrationPanel::~CalibrationPanel() +void CalibrationPanel::onCellChanged(int value) { - delete ui; -} + QSpinBox * sb = qobject_cast(sender()); + int row = sb->property("row").toInt(); + int column = sb->property("column").toInt(); -/*void CalibrationPanel::update() + if (value != getCalibrationValue(row, column)) { + setCalibrationValue(row,column, value); + qDebug() << "CalibrationPanel::onCellChanged" << row << column << "to" << value; + emit modified(); + } +} + +int CalibrationPanel::getCalibrationValue(int row, int column) { + switch(column) { + case 0: + return generalSettings.calibSpanNeg[row]; + case 1: + return generalSettings.calibMid[row]; + case 2: + return generalSettings.calibSpanPos[row]; + } + return 0; } -*/ -void CalibrationPanel::on_PPM_MultiplierDSB_editingFinished() + +void CalibrationPanel::setCalibrationValue(int row, int column, int value) { - generalSettings.PPM_Multiplier = (int)(ui->PPM_MultiplierDSB->value()*10)-10; - emit modified(); -} - -void CalibrationPanel::on_PPM1_editingFinished() -{ - generalSettings.trainer.calib[0] = ui->PPM1->value(); - emit modified(); -} - -void CalibrationPanel::on_PPM2_editingFinished() -{ - generalSettings.trainer.calib[1] = ui->PPM2->value(); - emit modified(); -} - -void CalibrationPanel::on_PPM3_editingFinished() -{ - generalSettings.trainer.calib[2] = ui->PPM3->value(); - emit modified(); -} - -void CalibrationPanel::on_PPM4_editingFinished() -{ - generalSettings.trainer.calib[3] = ui->PPM4->value(); - emit modified(); -} - - -void CalibrationPanel::on_txCurrentCalibration_editingFinished() -{ - generalSettings.txCurrentCalibration = ui->txCurrentCalibration->value(); - emit modified(); -} - -void CalibrationPanel::on_bluetoothEnable_stateChanged(int) -{ - generalSettings.bluetoothEnable = ui->bluetoothEnable->isChecked(); - emit modified(); -} - -void CalibrationPanel::setValues() -{ - ui->txVoltageCalibration->setValue((double)generalSettings.txVoltageCalibration/10); - ui->txCurrentCalibration->setValue((double)generalSettings.txCurrentCalibration); - - ui->ana1Neg->setValue(generalSettings.calibSpanNeg[0]); - ui->ana2Neg->setValue(generalSettings.calibSpanNeg[1]); - ui->ana3Neg->setValue(generalSettings.calibSpanNeg[2]); - ui->ana4Neg->setValue(generalSettings.calibSpanNeg[3]); - ui->ana5Neg->setValue(generalSettings.calibSpanNeg[4]); - ui->ana6Neg->setValue(generalSettings.calibSpanNeg[5]); - ui->ana7Neg->setValue(generalSettings.calibSpanNeg[6]); - ui->ana8Neg->setValue(generalSettings.calibSpanNeg[7]); - - ui->ana1Mid->setValue(generalSettings.calibMid[0]); - ui->ana2Mid->setValue(generalSettings.calibMid[1]); - ui->ana3Mid->setValue(generalSettings.calibMid[2]); - ui->ana4Mid->setValue(generalSettings.calibMid[3]); - ui->ana5Mid->setValue(generalSettings.calibMid[4]); - ui->ana6Mid->setValue(generalSettings.calibMid[5]); - ui->ana7Mid->setValue(generalSettings.calibMid[6]); - ui->ana8Mid->setValue(generalSettings.calibMid[7]); - - ui->ana1Pos->setValue(generalSettings.calibSpanPos[0]); - ui->ana2Pos->setValue(generalSettings.calibSpanPos[1]); - ui->ana3Pos->setValue(generalSettings.calibSpanPos[2]); - ui->ana4Pos->setValue(generalSettings.calibSpanPos[3]); - ui->ana5Pos->setValue(generalSettings.calibSpanPos[4]); - ui->ana6Pos->setValue(generalSettings.calibSpanPos[5]); - ui->ana7Pos->setValue(generalSettings.calibSpanPos[6]); - ui->ana8Pos->setValue(generalSettings.calibSpanPos[7]); - - ui->PPM1->setValue(generalSettings.trainer.calib[0]); - ui->PPM2->setValue(generalSettings.trainer.calib[1]); - ui->PPM3->setValue(generalSettings.trainer.calib[2]); - ui->PPM4->setValue(generalSettings.trainer.calib[3]); - ui->PPM_MultiplierDSB->setValue((qreal)(generalSettings.PPM_Multiplier+10)/10); -} - -void CalibrationPanel::on_txVoltageCalibration_editingFinished() -{ - generalSettings.txVoltageCalibration = ui->txVoltageCalibration->value()*10; - emit modified(); -} - - -void CalibrationPanel::on_ana1Neg_editingFinished() -{ - generalSettings.calibSpanNeg[0] = ui->ana1Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana2Neg_editingFinished() -{ - generalSettings.calibSpanNeg[1] = ui->ana2Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana3Neg_editingFinished() -{ - generalSettings.calibSpanNeg[2] = ui->ana3Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana4Neg_editingFinished() -{ - generalSettings.calibSpanNeg[3] = ui->ana4Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana5Neg_editingFinished() -{ - generalSettings.calibSpanNeg[4] = ui->ana5Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana6Neg_editingFinished() -{ - generalSettings.calibSpanNeg[5] = ui->ana6Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana7Neg_editingFinished() -{ - generalSettings.calibSpanNeg[6] = ui->ana7Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana8Neg_editingFinished() -{ - generalSettings.calibSpanNeg[7] = ui->ana8Neg->value(); - emit modified(); -} - -void CalibrationPanel::on_ana1Mid_editingFinished() -{ - generalSettings.calibMid[0] = ui->ana1Mid->value(); - emit modified(); -} - -void CalibrationPanel::on_ana2Mid_editingFinished() -{ - generalSettings.calibMid[1] = ui->ana2Mid->value(); - emit modified(); -} - -void CalibrationPanel::on_ana3Mid_editingFinished() -{ - generalSettings.calibMid[2] = ui->ana3Mid->value(); - emit modified(); -} - -void CalibrationPanel::on_ana4Mid_editingFinished() -{ - generalSettings.calibMid[3] = ui->ana4Mid->value(); - emit modified(); -} - -void CalibrationPanel::on_ana5Mid_editingFinished() -{ - generalSettings.calibMid[4] = ui->ana5Mid->value(); - emit modified(); -} - -void CalibrationPanel::on_ana6Mid_editingFinished() -{ - generalSettings.calibMid[5] = ui->ana6Mid->value(); - emit modified(); -} - -void CalibrationPanel::on_ana7Mid_editingFinished() -{ - generalSettings.calibMid[6] = ui->ana7Mid->value(); - emit modified(); -} - -void CalibrationPanel::on_ana8Mid_editingFinished() -{ - generalSettings.calibMid[7] = ui->ana8Mid->value(); - emit modified(); -} - - -void CalibrationPanel::on_ana1Pos_editingFinished() -{ - generalSettings.calibSpanPos[0] = ui->ana1Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_ana2Pos_editingFinished() -{ - generalSettings.calibSpanPos[1] = ui->ana2Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_ana3Pos_editingFinished() -{ - generalSettings.calibSpanPos[2] = ui->ana3Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_ana4Pos_editingFinished() -{ - generalSettings.calibSpanPos[3] = ui->ana4Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_ana5Pos_editingFinished() -{ - generalSettings.calibSpanPos[4] = ui->ana5Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_ana6Pos_editingFinished() -{ - generalSettings.calibSpanPos[5] = ui->ana6Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_ana7Pos_editingFinished() -{ - generalSettings.calibSpanPos[6] = ui->ana7Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_ana8Pos_editingFinished() -{ - generalSettings.calibSpanPos[7] = ui->ana8Pos->value(); - emit modified(); -} - -void CalibrationPanel::on_serialPortMode_currentIndexChanged(int index) -{ - generalSettings.hw_uartMode = index; - emit modified(); + switch(column) { + case 0: + generalSettings.calibSpanNeg[row] = value; + break; + case 1: + generalSettings.calibMid[row] = value; + break; + case 2: + generalSettings.calibSpanPos[row] = value; + break; + } } diff --git a/companion/src/generaledit/calibration.h b/companion/src/generaledit/calibration.h index 731423472..c7ef92d9a 100644 --- a/companion/src/generaledit/calibration.h +++ b/companion/src/generaledit/calibration.h @@ -1,6 +1,7 @@ #ifndef CALIBRATION_H #define CALIBRATION_H +#include #include "generaledit.h" namespace Ui { @@ -17,58 +18,16 @@ class CalibrationPanel : public GeneralPanel public: CalibrationPanel(QWidget *parent, GeneralSettings & generalSettings, Firmware * firmware); - virtual ~CalibrationPanel(); - // virtual void update(); + virtual ~CalibrationPanel() {}; private slots: - void on_txVoltageCalibration_editingFinished(); - void on_PPM1_editingFinished(); - void on_PPM2_editingFinished(); - void on_PPM3_editingFinished(); - void on_PPM4_editingFinished(); - void on_PPM_MultiplierDSB_editingFinished(); - - void on_txCurrentCalibration_editingFinished(); - void on_bluetoothEnable_stateChanged(int); - - void on_ana1Neg_editingFinished(); - void on_ana2Neg_editingFinished(); - void on_ana3Neg_editingFinished(); - void on_ana4Neg_editingFinished(); - void on_ana5Neg_editingFinished(); - void on_ana6Neg_editingFinished(); - void on_ana7Neg_editingFinished(); - void on_ana8Neg_editingFinished(); - - void on_ana1Mid_editingFinished(); - void on_ana2Mid_editingFinished(); - void on_ana3Mid_editingFinished(); - void on_ana4Mid_editingFinished(); - void on_ana5Mid_editingFinished(); - void on_ana6Mid_editingFinished(); - void on_ana7Mid_editingFinished(); - void on_ana8Mid_editingFinished(); - - void on_ana1Pos_editingFinished(); - void on_ana2Pos_editingFinished(); - void on_ana3Pos_editingFinished(); - void on_ana4Pos_editingFinished(); - void on_ana5Pos_editingFinished(); - void on_ana6Pos_editingFinished(); - void on_ana7Pos_editingFinished(); - void on_ana8Pos_editingFinished(); - - void on_serialPortMode_currentIndexChanged(int index); - - protected: - void setupPotConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type); - void setupSliderConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type); - void setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos); + void onCellChanged(int value); private: - Ui::Calibration *ui; + QTableWidget * tableWidget; - void setValues(); + int getCalibrationValue(int row, int column); + void setCalibrationValue(int row, int column, int value); }; #endif // CALIBRATION_H diff --git a/companion/src/generaledit/generaledit.cpp b/companion/src/generaledit/generaledit.cpp index 127d87cf7..271693d14 100644 --- a/companion/src/generaledit/generaledit.cpp +++ b/companion/src/generaledit/generaledit.cpp @@ -8,6 +8,7 @@ #include "generalsetup.h" #include "trainer.h" #include "calibration.h" +#include "hardware.h" #include "../modeledit/customfunctions.h" #include "verticalscrollarea.h" @@ -42,7 +43,8 @@ GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * fir addTab(new CustomFunctionsPanel(this, NULL, generalSettings, firmware), tr("Global Functions")); } addTab(new TrainerPanel(this, generalSettings, firmware), tr("Trainer")); - addTab(new CalibrationPanel(this, generalSettings, firmware), tr("Hardware / Calibration")); + addTab(new HardwarePanel(this, generalSettings, firmware), tr("Hardware")); + addTab(new CalibrationPanel(this, generalSettings, firmware), tr("Calibration")); ui->tabWidget->setCurrentIndex( g.generalEditTab() ); } diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp new file mode 100644 index 000000000..8ddb32a51 --- /dev/null +++ b/companion/src/generaledit/hardware.cpp @@ -0,0 +1,241 @@ +#include "hardware.h" +#include "ui_hardware.h" + +void HardwarePanel::setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos = true) +{ + bool enabled = false; + + if (IS_TARANIS(firmware->getBoard())) { + if (IS_TARANIS_X9E(firmware->getBoard())) { + enabled = true; + type->addItem(tr("None"), GeneralSettings::SWITCH_NONE); + } + else if (index < 8) { + enabled = true; + } + } + + if (enabled) { + type->addItem(tr("2 Positions Toggle"), GeneralSettings::SWITCH_TOGGLE); + type->addItem(tr("2 Positions"), GeneralSettings::SWITCH_2POS); + if (threePos) type->addItem(tr("3 Positions"), GeneralSettings::SWITCH_3POS); + name->setField(generalSettings.switchName[index], 3, this); + type->setField(generalSettings.switchConfig[index], this); + } + else { + label->hide(); + name->hide(); + type->hide(); + } +} + +void HardwarePanel::setupPotConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type) +{ + bool enabled = false; + + if (IS_TARANIS_X9E(firmware->getBoard()) && index < 4) { + label->setText(RawSource(SOURCE_TYPE_STICK, index+NUM_STICKS).toString()); + enabled = true; + } + else if (IS_TARANIS_PLUS(firmware->getBoard()) && index < 3) { + enabled = true; + } + else if (IS_TARANIS(firmware->getBoard()) && index < 2) { + enabled = true; + } + + if (enabled) { + type->addItem(tr("None"), GeneralSettings::POT_NONE); + type->addItem(tr("Pot with detent"), GeneralSettings::POT_WITH_DETENT); + type->addItem(tr("Multipos switch"), GeneralSettings::POT_MULTIPOS_SWITCH); + type->addItem(tr("Pot without detent"), GeneralSettings::POT_WITHOUT_DETENT); + name->setField(generalSettings.potName[index], 3, this); + type->setField(generalSettings.potConfig[index], this); + } + else { + label->hide(); + name->hide(); + type->hide(); + } +} + +void HardwarePanel::setupSliderConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type) +{ + bool enabled = false; + + if (IS_TARANIS(firmware->getBoard()) && index < 2) { + type->setEnabled(false); + enabled = true; + } + else if (IS_TARANIS_X9E(firmware->getBoard()) && index < 4) { + enabled = true; + } + + if (IS_TARANIS_X9E(firmware->getBoard())) { + label->setText(RawSource(SOURCE_TYPE_STICK, index+NUM_STICKS+4).toString()); + } + + if (enabled) { + type->addItem(tr("None"), GeneralSettings::SLIDER_NONE); + type->addItem(tr("Slider with detent"), GeneralSettings::SLIDER_WITH_DETENT); + name->setField(generalSettings.sliderName[index], 3, this); + type->setField(generalSettings.sliderConfig[index], this); + } + else { + label->hide(); + name->hide(); + type->hide(); + } +} + +HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware): + GeneralPanel(parent, generalSettings, firmware), + ui(new Ui::Hardware) +{ + ui->setupUi(this); + + if (IS_TARANIS(firmware->getBoard())) { + ui->rudName->setField(generalSettings.stickName[0], 3, this); + ui->eleName->setField(generalSettings.stickName[1], 3, this); + ui->thrName->setField(generalSettings.stickName[2], 3, this); + ui->ailName->setField(generalSettings.stickName[3], 3, this); + } + else { + ui->rudLabel->hide(); + ui->rudName->hide(); + ui->eleLabel->hide(); + ui->eleName->hide(); + ui->thrLabel->hide(); + ui->thrName->hide(); + ui->ailLabel->hide(); + ui->ailName->hide(); + } + + setupPotConfig(0, ui->pot1Label, ui->pot1Name, ui->pot1Type); + setupPotConfig(1, ui->pot2Label, ui->pot2Name, ui->pot2Type); + setupPotConfig(2, ui->pot3Label, ui->pot3Name, ui->pot3Type); + setupPotConfig(3, ui->pot4Label, ui->pot4Name, ui->pot4Type); + + setupSliderConfig(0, ui->lsLabel, ui->lsName, ui->lsType); + setupSliderConfig(1, ui->rsLabel, ui->rsName, ui->rsType); + setupSliderConfig(2, ui->ls2Label, ui->ls2Name, ui->ls2Type); + setupSliderConfig(3, ui->rs2Label, ui->rs2Name, ui->rs2Type); + + setupSwitchConfig(0, ui->saLabel, ui->saName, ui->saType); + setupSwitchConfig(1, ui->sbLabel, ui->sbName, ui->sbType); + setupSwitchConfig(2, ui->scLabel, ui->scName, ui->scType); + setupSwitchConfig(3, ui->sdLabel, ui->sdName, ui->sdType); + setupSwitchConfig(4, ui->seLabel, ui->seName, ui->seType); + setupSwitchConfig(5, ui->sfLabel, ui->sfName, ui->sfType, false); //switch does not support 3POS + setupSwitchConfig(6, ui->sgLabel, ui->sgName, ui->sgType); + setupSwitchConfig(7, ui->shLabel, ui->shName, ui->shType, false); //switch does not support 3POS + setupSwitchConfig(8, ui->siLabel, ui->siName, ui->siType); + setupSwitchConfig(9, ui->sjLabel, ui->sjName, ui->sjType); + setupSwitchConfig(10, ui->skLabel, ui->skName, ui->skType); + setupSwitchConfig(11, ui->slLabel, ui->slName, ui->slType); + setupSwitchConfig(12, ui->smLabel, ui->smName, ui->smType); + setupSwitchConfig(13, ui->snLabel, ui->snName, ui->snType); + setupSwitchConfig(14, ui->soLabel, ui->soName, ui->soType); + setupSwitchConfig(15, ui->spLabel, ui->spName, ui->spType); + setupSwitchConfig(16, ui->sqLabel, ui->sqName, ui->sqType); + setupSwitchConfig(17, ui->srLabel, ui->srName, ui->srType); + + if (IS_TARANIS(firmware->getBoard())) { + ui->serialPortMode->setCurrentIndex(generalSettings.hw_uartMode); + } + else { + ui->serialPortMode->hide(); + ui->serialPortLabel->hide(); + } + + if (!IS_SKY9X(firmware->getBoard())) { + ui->txCurrentCalibration->hide(); + ui->txCurrentCalibrationLabel->hide(); + } + + if (IS_TARANIS_X9E(firmware->getBoard())) { + ui->bluetoothEnable->setChecked(generalSettings.bluetoothEnable); + ui->bluetoothName->setField(generalSettings.bluetoothName, 10, this); + } + else { + ui->bluetoothLabel->hide(); + ui->bluetoothEnable->hide(); + ui->bluetoothName->hide(); + } + + disableMouseScrolling(); + + setValues(); +} + +HardwarePanel::~HardwarePanel() +{ + delete ui; +} + +void HardwarePanel::on_PPM_MultiplierDSB_editingFinished() +{ + generalSettings.PPM_Multiplier = (int)(ui->PPM_MultiplierDSB->value()*10)-10; + emit modified(); +} + +void HardwarePanel::on_PPM1_editingFinished() +{ + generalSettings.trainer.calib[0] = ui->PPM1->value(); + emit modified(); +} + +void HardwarePanel::on_PPM2_editingFinished() +{ + generalSettings.trainer.calib[1] = ui->PPM2->value(); + emit modified(); +} + +void HardwarePanel::on_PPM3_editingFinished() +{ + generalSettings.trainer.calib[2] = ui->PPM3->value(); + emit modified(); +} + +void HardwarePanel::on_PPM4_editingFinished() +{ + generalSettings.trainer.calib[3] = ui->PPM4->value(); + emit modified(); +} + + +void HardwarePanel::on_txCurrentHardware_editingFinished() +{ + generalSettings.txCurrentCalibration = ui->txCurrentCalibration->value(); + emit modified(); +} + +void HardwarePanel::on_bluetoothEnable_stateChanged(int) +{ + generalSettings.bluetoothEnable = ui->bluetoothEnable->isChecked(); + emit modified(); +} + +void HardwarePanel::setValues() +{ + ui->txVoltageCalibration->setValue((double)generalSettings.txVoltageCalibration/10); + ui->txCurrentCalibration->setValue((double)generalSettings.txCurrentCalibration); + + ui->PPM1->setValue(generalSettings.trainer.calib[0]); + ui->PPM2->setValue(generalSettings.trainer.calib[1]); + ui->PPM3->setValue(generalSettings.trainer.calib[2]); + ui->PPM4->setValue(generalSettings.trainer.calib[3]); + ui->PPM_MultiplierDSB->setValue((qreal)(generalSettings.PPM_Multiplier+10)/10); +} + +void HardwarePanel::on_txVoltageHardware_editingFinished() +{ + generalSettings.txVoltageCalibration = ui->txVoltageCalibration->value()*10; + emit modified(); +} + +void HardwarePanel::on_serialPortMode_currentIndexChanged(int index) +{ + generalSettings.hw_uartMode = index; + emit modified(); +} diff --git a/companion/src/generaledit/hardware.h b/companion/src/generaledit/hardware.h new file mode 100644 index 000000000..2d6481ffb --- /dev/null +++ b/companion/src/generaledit/hardware.h @@ -0,0 +1,46 @@ +#ifndef HARDWARE_H +#define HARDWARE_H + +#include "generaledit.h" + +namespace Ui { + class Hardware; +} + +class QLabel; +class AutoLineEdit; +class AutoComboBox; + +class HardwarePanel : public GeneralPanel +{ + Q_OBJECT + + public: + HardwarePanel(QWidget *parent, GeneralSettings & generalSettings, Firmware * firmware); + virtual ~HardwarePanel(); + + private slots: + void on_txVoltageHardware_editingFinished(); + void on_PPM1_editingFinished(); + void on_PPM2_editingFinished(); + void on_PPM3_editingFinished(); + void on_PPM4_editingFinished(); + void on_PPM_MultiplierDSB_editingFinished(); + + void on_txCurrentHardware_editingFinished(); + void on_bluetoothEnable_stateChanged(int); + + void on_serialPortMode_currentIndexChanged(int index); + + protected: + void setupPotConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type); + void setupSliderConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type); + void setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos); + + private: + Ui::Hardware *ui; + + void setValues(); +}; + +#endif // HARDWARE_H diff --git a/companion/src/generaledit/calibration.ui b/companion/src/generaledit/hardware.ui similarity index 68% rename from companion/src/generaledit/calibration.ui rename to companion/src/generaledit/hardware.ui index 26ad4e2b6..7ff18ac4e 100644 --- a/companion/src/generaledit/calibration.ui +++ b/companion/src/generaledit/hardware.ui @@ -1,187 +1,151 @@ - Calibration - + Hardware + 0 0 - 805 - 1313 + 359 + 1594 Form - - - - - - - - -9999 - - - 9999 - - - - - - - Serial Port - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + + SQ - + 3 - + SR - + 3 - - - - - - - -9999 - - - 9999 - - - - + 3 - + LS2 - + + + + + + + + + + + + + + 3 - + SP - + SO - + S4 - - - - - - - -9999 - - - 9999 - - - - + 3 - + RS - + SB - - - - - - - -9999 - - - 9999 - - - - - + + - Stick 3 + PPM 2 - + + + + + 0 + 10 + + + + Qt::Horizontal + + + + 3 - + @@ -200,20 +164,7 @@ - - - - - 0 - 10 - - - - Qt::Horizontal - - - - + @@ -232,7 +183,7 @@ - + @@ -261,314 +212,123 @@ - + 3 - + 3 - + 3 - + Rud - - - - Mid value - - - Qt::AlignCenter - - - - - - - - + + - -9999 + -49 - 9999 + 49 - - - - - - - -9999 - - - 9999 - - - - - + + - Pot. 4 + PPM 3 - - - - Qt::Vertical + + + + 3 - - + + - Pot. 3 + S1 - - - - - - - -9999 - - - 9999 + + + + 3 - - + + - Pot. 2 + S2 - - + + - Pot. 1 + S3 - + PPM 1 - - + + + + + + + + + + + + + -9999 + + + 9999 + + + + + - Negative span + Serial Port - Qt::AlignCenter + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - Mid value - - - Qt::AlignCenter - - - - - - - Positive span - - - Qt::AlignCenter - - - - - - - Stick 1 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - 0 - - - - - - - PPM 2 - - - - - - - Stick 2 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - Stick 4 - - - - - - - - - - -9999 - - - 9999 - - - 0 - - - - - - - - - - -9999 - - - 9999 - - - - - - - Battery Offset - - - - + @@ -590,52 +350,14 @@ - + PPM Multiplier - - - - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - - - - - - - -9999 - - - 9999 - - - - + @@ -654,70 +376,7 @@ - - - - - - - - - - - - - -9999 - - - 9999 - - - - - - - -49 - - - 49 - - - - - - - PPM 3 - - - - - - - PPM 4 - - - - - - - Current Offset - - - - - - - - - - -9999 - - - 9999 - - - - + @@ -730,208 +389,70 @@ - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - - - -9999 - - - 9999 - - - - - - - - 0 - 10 - - - - Qt::Horizontal - - - - - + + - Negative span - - - Qt::AlignCenter + Current Offset - - - - 3 - - - - - + + - Positive span - - - Qt::AlignCenter + PPM 4 - - - - S1 - - - - - - - S2 - - - - - - - S3 - - - - - - - 3 - - - - - - - SA - - - - - - - Ele - - - - + 3 - - + + - Ail + SA - + + + + Ele + + + + 3 - + 3 - + + + + Ail + + + + + + + 3 + + + + Thr @@ -939,41 +460,41 @@ - - - 3 - - - - - - - SC - - - - 3 - - + + - LS + SC - + 3 - + + + + LS + + + + + + + 3 + + + + @@ -986,21 +507,21 @@ - - + + 3 - + SD - + @@ -1013,21 +534,66 @@ - - + + + + + + + + + + + + + -9999 + + + 9999 + + + + + + + Battery Offset + + + + + + + + + + + + + + + + -9999 + + + 9999 + + + + + 3 - + SE - + @@ -1040,21 +606,21 @@ - - + + 3 - + SF - + @@ -1067,21 +633,21 @@ - - + + 3 - + SG - + @@ -1094,91 +660,77 @@ - - - - 3 - - - - - - - SH - - - - + 3 - - + + - SI + SH - + 3 - - + + - SJ + SI - + 3 - - + + - SK + SJ - + 3 - - + + - SL + SK - + 3 - - + + - SM + SL - + @@ -1191,7 +743,7 @@ - + @@ -1204,14 +756,28 @@ - + + + + SM + + + + + + + 3 + + + + SN - + 1 @@ -1224,41 +790,21 @@ - - - - 3 - - - - - - - RS2 - - - - + 3 - - - - - - - - - - + + + + RS2 - + @@ -1271,7 +817,20 @@ - + + + + + + + + + + + + + + @@ -1284,20 +843,7 @@ - - - - - - - - - - - - - - + @@ -1310,7 +856,7 @@ - + @@ -1323,7 +869,7 @@ - + @@ -1336,7 +882,7 @@ - + @@ -1349,7 +895,7 @@ - + @@ -1362,7 +908,7 @@ - + @@ -1375,7 +921,7 @@ - + @@ -1394,7 +940,7 @@ - + @@ -1413,7 +959,7 @@ - + @@ -1432,7 +978,7 @@ - + @@ -1451,7 +997,7 @@ - + @@ -1470,7 +1016,7 @@ - + @@ -1489,7 +1035,7 @@ - + @@ -1508,7 +1054,7 @@ - + @@ -1527,7 +1073,7 @@ - + Bluetooth @@ -1537,7 +1083,14 @@ - + + + + 3 + + + + @@ -1555,13 +1108,6 @@ - - - - 3 - - -