5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
22 #include "ui_hardware.h"
24 void HardwarePanel::setupSwitchType(int index
, QLabel
* label
, AutoLineEdit
* name
, AutoComboBox
* type
, bool threePos
)
26 Board::Type board
= getCurrentBoard();
27 if (IS_STM32(board
) && index
< getBoardCapability(board
, Board::Switches
)) {
28 type
->addItem(tr("None"), Board::SWITCH_NOT_AVAILABLE
);
29 type
->addItem(tr("2 Positions Toggle"), Board::SWITCH_TOGGLE
);
30 type
->addItem(tr("2 Positions"), Board::SWITCH_2POS
);
32 type
->addItem(tr("3 Positions"), Board::SWITCH_3POS
);
34 name
->setField(generalSettings
.switchName
[index
], 3, this);
35 type
->setField(generalSettings
.switchConfig
[index
], this);
36 if (IS_TARANIS_X7(board
)) {
40 else if (index
== 5) {
52 void HardwarePanel::setupPotType(int index
, QLabel
* label
, AutoLineEdit
* name
, AutoComboBox
* type
)
54 Board::Type board
= firmware
->getBoard();
56 if (IS_STM32(board
) && index
< getBoardCapability(board
, Board::Pots
)) {
57 label
->setText(RawSource(SOURCE_TYPE_STICK
, CPN_MAX_STICKS
+index
).toString());
58 type
->addItem(tr("None"), Board::POT_NONE
);
59 type
->addItem(tr("Pot with detent"), Board::POT_WITH_DETENT
);
60 type
->addItem(tr("Multipos switch"), Board::POT_MULTIPOS_SWITCH
);
61 type
->addItem(tr("Pot without detent"), Board::POT_WITHOUT_DETENT
);
62 name
->setField(generalSettings
.potName
[index
], 3, this);
63 type
->setField(generalSettings
.potConfig
[index
], this);
72 void HardwarePanel::setupSliderType(int index
, QLabel
*label
, AutoLineEdit
*name
, AutoComboBox
*type
)
74 Board::Type board
= firmware
->getBoard();
76 if (IS_STM32(board
) && index
< getBoardCapability(board
, Board::Sliders
)) {
77 label
->setText(RawSource(SOURCE_TYPE_STICK
, CPN_MAX_STICKS
+getBoardCapability(board
, Board::Pots
)+index
).toString());
78 type
->addItem(tr("None"), Board::SLIDER_NONE
);
79 type
->addItem(tr("Slider with detent"), Board::SLIDER_WITH_DETENT
);
80 name
->setField(generalSettings
.sliderName
[index
], 3, this);
81 type
->setField(generalSettings
.sliderConfig
[index
], this);
90 HardwarePanel::HardwarePanel(QWidget
* parent
, GeneralSettings
& generalSettings
, Firmware
* firmware
):
91 GeneralPanel(parent
, generalSettings
, firmware
),
96 Board::Type board
= firmware
->getBoard();
98 if (IS_STM32(board
)) {
99 ui
->rudName
->setField(generalSettings
.stickName
[0], 3, this);
100 ui
->eleName
->setField(generalSettings
.stickName
[1], 3, this);
101 ui
->thrName
->setField(generalSettings
.stickName
[2], 3, this);
102 ui
->ailName
->setField(generalSettings
.stickName
[3], 3, this);
105 ui
->rudLabel
->hide();
107 ui
->eleLabel
->hide();
109 ui
->thrLabel
->hide();
111 ui
->ailLabel
->hide();
113 ui
->potsTypeSeparator_1
->hide();
114 ui
->potsTypeSeparator_2
->hide();
117 setupPotType(0, ui
->pot1Label
, ui
->pot1Name
, ui
->pot1Type
);
118 setupPotType(1, ui
->pot2Label
, ui
->pot2Name
, ui
->pot2Type
);
119 setupPotType(2, ui
->pot3Label
, ui
->pot3Name
, ui
->pot3Type
);
120 setupPotType(3, ui
->pot4Label
, ui
->pot4Name
, ui
->pot4Type
);
122 setupSliderType(0, ui
->lsLabel
, ui
->lsName
, ui
->lsType
);
123 setupSliderType(1, ui
->rsLabel
, ui
->rsName
, ui
->rsType
);
124 setupSliderType(2, ui
->ls2Label
, ui
->ls2Name
, ui
->ls2Type
);
125 setupSliderType(3, ui
->rs2Label
, ui
->rs2Name
, ui
->rs2Type
);
127 setupSwitchType(0, ui
->saLabel
, ui
->saName
, ui
->saType
);
128 setupSwitchType(1, ui
->sbLabel
, ui
->sbName
, ui
->sbType
);
129 setupSwitchType(2, ui
->scLabel
, ui
->scName
, ui
->scType
);
130 setupSwitchType(3, ui
->sdLabel
, ui
->sdName
, ui
->sdType
);
131 setupSwitchType(4, ui
->seLabel
, ui
->seName
, ui
->seType
);
132 setupSwitchType(5, ui
->sfLabel
, ui
->sfName
, ui
->sfType
, false); //switch does not support 3POS
133 setupSwitchType(6, ui
->sgLabel
, ui
->sgName
, ui
->sgType
);
134 setupSwitchType(7, ui
->shLabel
, ui
->shName
, ui
->shType
, false); //switch does not support 3POS
135 setupSwitchType(8, ui
->siLabel
, ui
->siName
, ui
->siType
);
136 setupSwitchType(9, ui
->sjLabel
, ui
->sjName
, ui
->sjType
);
137 setupSwitchType(10, ui
->skLabel
, ui
->skName
, ui
->skType
);
138 setupSwitchType(11, ui
->slLabel
, ui
->slName
, ui
->slType
);
139 setupSwitchType(12, ui
->smLabel
, ui
->smName
, ui
->smType
);
140 setupSwitchType(13, ui
->snLabel
, ui
->snName
, ui
->snType
);
141 setupSwitchType(14, ui
->soLabel
, ui
->soName
, ui
->soType
);
142 setupSwitchType(15, ui
->spLabel
, ui
->spName
, ui
->spType
);
143 setupSwitchType(16, ui
->sqLabel
, ui
->sqName
, ui
->sqType
);
144 setupSwitchType(17, ui
->srLabel
, ui
->srName
, ui
->srType
);
146 if (IS_TARANIS(board
) && !IS_TARANIS_SMALL(board
)) {
147 ui
->serialPortMode
->setCurrentIndex(generalSettings
.hw_uartMode
);
150 ui
->serialPortMode
->setCurrentIndex(0);
151 ui
->serialPortMode
->hide();
152 ui
->serialPortLabel
->hide();
155 if (!IS_SKY9X(board
)) {
156 ui
->txCurrentCalibration
->hide();
157 ui
->txCurrentCalibrationLabel
->hide();
160 if (IS_TARANIS_X9E(board
) || IS_HORUS(board
)) {
161 ui
->bluetoothEnable
->setChecked(generalSettings
.bluetoothEnable
);
162 ui
->bluetoothName
->setField(generalSettings
.bluetoothName
, 10, this);
165 ui
->bluetoothLabel
->hide();
166 ui
->bluetoothWidget
->hide();
169 if (IS_HORUS_OR_TARANIS(board
)) {
170 ui
->filterEnable
->setChecked(!generalSettings
.jitterFilter
);
173 ui
->filterEnable
->hide();
176 disableMouseScrolling();
181 HardwarePanel::~HardwarePanel()
186 void HardwarePanel::on_filterEnable_stateChanged()
188 generalSettings
.jitterFilter
= !ui
->filterEnable
->isChecked();
191 void HardwarePanel::on_PPM_MultiplierDSB_editingFinished()
193 int val
= (int)(ui
->PPM_MultiplierDSB
->value()*10)-10;
194 if (generalSettings
.PPM_Multiplier
!= val
) {
195 generalSettings
.PPM_Multiplier
= val
;
200 void HardwarePanel::on_PPM1_editingFinished()
202 if (generalSettings
.trainer
.calib
[0] != ui
->PPM1
->value()) {
203 generalSettings
.trainer
.calib
[0] = ui
->PPM1
->value();
208 void HardwarePanel::on_PPM2_editingFinished()
210 if (generalSettings
.trainer
.calib
[1] != ui
->PPM2
->value()) {
211 generalSettings
.trainer
.calib
[1] = ui
->PPM2
->value();
216 void HardwarePanel::on_PPM3_editingFinished()
218 if (generalSettings
.trainer
.calib
[2] != ui
->PPM3
->value()) {
219 generalSettings
.trainer
.calib
[2] = ui
->PPM3
->value();
224 void HardwarePanel::on_PPM4_editingFinished()
226 if (generalSettings
.trainer
.calib
[3] != ui
->PPM4
->value()) {
227 generalSettings
.trainer
.calib
[3] = ui
->PPM4
->value();
233 void HardwarePanel::on_txCurrentCalibration_editingFinished()
235 if (generalSettings
.txCurrentCalibration
!= ui
->txCurrentCalibration
->value()) {
236 generalSettings
.txCurrentCalibration
= ui
->txCurrentCalibration
->value();
241 void HardwarePanel::on_bluetoothEnable_stateChanged(int)
243 generalSettings
.bluetoothEnable
= ui
->bluetoothEnable
->isChecked();
247 void HardwarePanel::setValues()
249 ui
->txVoltageCalibration
->setValue((double)generalSettings
.txVoltageCalibration
/10);
250 ui
->txCurrentCalibration
->setValue((double)generalSettings
.txCurrentCalibration
);
252 ui
->PPM1
->setValue(generalSettings
.trainer
.calib
[0]);
253 ui
->PPM2
->setValue(generalSettings
.trainer
.calib
[1]);
254 ui
->PPM3
->setValue(generalSettings
.trainer
.calib
[2]);
255 ui
->PPM4
->setValue(generalSettings
.trainer
.calib
[3]);
256 ui
->PPM_MultiplierDSB
->setValue((qreal
)(generalSettings
.PPM_Multiplier
+10)/10);
259 void HardwarePanel::on_txVoltageCalibration_editingFinished()
261 if (generalSettings
.txVoltageCalibration
!= ui
->txVoltageCalibration
->value()*10) {
262 generalSettings
.txVoltageCalibration
= ui
->txVoltageCalibration
->value()*10;
267 void HardwarePanel::on_serialPortMode_currentIndexChanged(int index
)
269 generalSettings
.hw_uartMode
= index
;