Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / config / configoplinkwidget.cpp
blob37a01b77341a9d2e9003ac26277478524684c34f
1 /**
2 ****************************************************************************************
4 * @file configoplinkwidget.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015-2016.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup ConfigPlugin Config Plugin
10 * @{
11 * @brief The Configuration Gadget used to configure the OPLink, Revo and Sparky2 modems
12 ***************************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "configoplinkwidget.h"
31 #include "ui_oplink.h"
33 #include <uavobjectutilmanager.h>
35 #include <oplinksettings.h>
36 #include <oplinkstatus.h>
38 #include <QMessageBox>
39 #include <QDebug>
41 // Channel range and Frequency display
42 static const int MAX_CHANNEL_NUM = 250;
43 static const int MIN_CHANNEL_RANGE = 10;
44 static const float FREQUENCY_STEP = 0.040;
46 ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(parent, OPLink), statusUpdated(false)
48 m_oplink = new Ui_OPLinkWidget();
49 m_oplink->setupUi(this);
51 // must be done before auto binding !
52 setWikiURL("OPLink+Configuration");
54 addAutoBindings();
56 disableMouseWheelEvents();
58 connect(this, SIGNAL(connected()), this, SLOT(connected()));
60 oplinkStatusObj = dynamic_cast<OPLinkStatus *>(getObject("OPLinkStatus"));
61 Q_ASSERT(oplinkStatusObj);
63 oplinkSettingsObj = dynamic_cast<OPLinkSettings *>(getObject("OPLinkSettings"));
64 Q_ASSERT(oplinkSettingsObj);
66 addWidget(m_oplink->FirmwareVersion);
67 addWidget(m_oplink->SerialNumber);
68 addWidget(m_oplink->MinFreq);
69 addWidget(m_oplink->MaxFreq);
70 addWidget(m_oplink->UnbindButton);
71 addWidget(m_oplink->ClearDeviceButton);
72 addWidget(m_oplink->SignalStrengthBar);
73 addWidget(m_oplink->SignalStrengthLabel);
75 addWidgetBinding("OPLinkSettings", "Protocol", m_oplink->Protocol);
76 addWidgetBinding("OPLinkSettings", "LinkType", m_oplink->LinkType);
77 addWidgetBinding("OPLinkSettings", "CoordID", m_oplink->CoordID);
78 addWidgetBinding("OPLinkSettings", "CustomDeviceID", m_oplink->CustomDeviceID);
79 addWidgetBinding("OPLinkSettings", "RFBand", m_oplink->RFBand);
80 addWidgetBinding("OPLinkSettings", "MinChannel", m_oplink->MinimumChannel);
81 addWidgetBinding("OPLinkSettings", "MaxChannel", m_oplink->MaximumChannel);
82 addWidgetBinding("OPLinkSettings", "MaxRFPower", m_oplink->MaxRFTxPower);
83 addWidgetBinding("OPLinkSettings", "MainPort", m_oplink->MainPort);
84 addWidgetBinding("OPLinkSettings", "FlexiPort", m_oplink->FlexiPort);
85 addWidgetBinding("OPLinkSettings", "PPMOutRSSI", m_oplink->PPMoutRssi);
86 addWidgetBinding("OPLinkSettings", "RadioPriStream", m_oplink->RadioPriStream);
87 addWidgetBinding("OPLinkSettings", "RadioAuxStream", m_oplink->RadioAuxStream);
88 addWidgetBinding("OPLinkSettings", "VCPBridge", m_oplink->VCPBridge);
89 addWidgetBinding("OPLinkSettings", "MainComSpeed", m_oplink->MainComSpeed);
90 addWidgetBinding("OPLinkSettings", "FlexiComSpeed", m_oplink->FlexiComSpeed);
91 addWidgetBinding("OPLinkSettings", "AirDataRate", m_oplink->AirDataRate);
93 addWidgetBinding("OPLinkSettings", "RFXtalCap", m_oplink->RFXtalCapValue);
94 addWidgetBinding("OPLinkSettings", "RFXtalCap", m_oplink->RFXtalCapSlider);
96 addWidgetBinding("OPLinkStatus", "DeviceID", m_oplink->DeviceID);
97 addWidgetBinding("OPLinkStatus", "RxGood", m_oplink->Good);
98 addWidgetBinding("OPLinkStatus", "RxCorrected", m_oplink->Corrected);
99 addWidgetBinding("OPLinkStatus", "RxErrors", m_oplink->Errors);
100 addWidgetBinding("OPLinkStatus", "RxMissed", m_oplink->Missed);
101 addWidgetBinding("OPLinkStatus", "RxFailure", m_oplink->RxFailure);
102 addWidgetBinding("OPLinkStatus", "UAVTalkErrors", m_oplink->UAVTalkErrors);
103 addWidgetBinding("OPLinkStatus", "TxDropped", m_oplink->Dropped);
104 addWidgetBinding("OPLinkStatus", "TxFailure", m_oplink->TxFailure);
105 addWidgetBinding("OPLinkStatus", "Resets", m_oplink->Resets);
106 addWidgetBinding("OPLinkStatus", "Timeouts", m_oplink->Timeouts);
107 addWidgetBinding("OPLinkStatus", "RSSI", m_oplink->RSSI);
108 addWidgetBinding("OPLinkStatus", "HeapRemaining", m_oplink->FreeHeap);
109 addWidgetBinding("OPLinkStatus", "LinkQuality", m_oplink->LinkQuality);
110 addWidgetBinding("OPLinkStatus", "RXSeq", m_oplink->RXSeq);
111 addWidgetBinding("OPLinkStatus", "TXSeq", m_oplink->TXSeq);
112 addWidgetBinding("OPLinkStatus", "RXRate", m_oplink->RXRate);
113 addWidgetBinding("OPLinkStatus", "TXRate", m_oplink->TXRate);
114 addWidgetBinding("OPLinkStatus", "RXPacketRate", m_oplink->RXPacketRate);
115 addWidgetBinding("OPLinkStatus", "TXPacketRate", m_oplink->TXPacketRate);
116 addWidgetBinding("OPLinkStatus", "AFCCorrection", m_oplink->AFCCorrection);
118 // initially hide Oplink Mini options
119 setOPLMOptionsVisible(false);
121 // Connect the selection changed signals.
122 connect(m_oplink->Protocol, SIGNAL(currentIndexChanged(int)), this, SLOT(protocolChanged()));
123 connect(m_oplink->LinkType, SIGNAL(currentIndexChanged(int)), this, SLOT(linkTypeChanged()));
124 connect(m_oplink->CustomDeviceID, SIGNAL(textChanged(QString)), this, SLOT(customIDChanged()));
125 connect(m_oplink->CoordID, SIGNAL(textChanged(QString)), this, SLOT(coordIDChanged()));
126 connect(m_oplink->RFBand, SIGNAL(currentIndexChanged(int)), this, SLOT(rfBandChanged()));
127 connect(m_oplink->MinimumChannel, SIGNAL(valueChanged(int)), this, SLOT(minChannelChanged()));
128 connect(m_oplink->MaximumChannel, SIGNAL(valueChanged(int)), this, SLOT(maxChannelChanged()));
129 connect(m_oplink->MainPort, SIGNAL(currentIndexChanged(int)), this, SLOT(mainPortChanged()));
130 connect(m_oplink->FlexiPort, SIGNAL(currentIndexChanged(int)), this, SLOT(flexiPortChanged()));
131 connect(m_oplink->RadioPriStream, SIGNAL(currentIndexChanged(int)), this, SLOT(radioPriStreamChanged()));
132 connect(m_oplink->RadioAuxStream, SIGNAL(currentIndexChanged(int)), this, SLOT(radioAuxStreamChanged()));
133 connect(m_oplink->VCPBridge, SIGNAL(currentIndexChanged(int)), this, SLOT(vcpBridgeChanged()));
135 // Connect the Unbind and ClearDevice buttons
136 connect(m_oplink->UnbindButton, SIGNAL(released()), this, SLOT(unbind()));
137 connect(m_oplink->ClearDeviceButton, SIGNAL(released()), this, SLOT(clearDeviceID()));
139 // all upper case hex
140 m_oplink->CustomDeviceID->setInputMask(">HHHHHHHH");
141 m_oplink->CustomDeviceID->setPlaceholderText("AutoGen");
143 m_oplink->CoordID->setInputMask(">HHHHHHHH");
145 m_oplink->MinimumChannel->setKeyboardTracking(false);
146 m_oplink->MaximumChannel->setKeyboardTracking(false);
148 m_oplink->MaximumChannel->setMaximum(MAX_CHANNEL_NUM);
149 m_oplink->MinimumChannel->setMaximum(MAX_CHANNEL_NUM - MIN_CHANNEL_RANGE);
152 ConfigOPLinkWidget::~ConfigOPLinkWidget()
155 void ConfigOPLinkWidget::connected()
157 // qDebug() << "ConfigOPLinkWidget::connected()";
158 statusUpdated = false;
160 // Request and update of the setting object if we haven't received it yet.
161 // this is only really needed for OPLM
162 oplinkSettingsObj->requestUpdate();
164 updateSettings();
167 void ConfigOPLinkWidget::refreshWidgetsValuesImpl(UAVObject *obj)
169 // qDebug() << "ConfigOPLinkWidget::refreshWidgetsValuesImpl()" << obj;
170 if (obj == oplinkStatusObj) {
171 updateStatus();
172 } else if (obj == oplinkSettingsObj) {
173 updateSettings();
177 void ConfigOPLinkWidget::updateStatus()
179 // qDebug() << "ConfigOPLinkWidget::updateStatus";
181 // Update the link state
182 UAVObjectField *linkField = oplinkStatusObj->getField("LinkState");
184 m_oplink->LinkState->setText(linkField->getValue().toString());
185 bool linkConnected = (oplinkStatusObj->linkState() == OPLinkStatus_LinkState::Connected);
187 m_oplink->SignalStrengthBar->setValue(linkConnected ? m_oplink->RSSI->text().toInt() : -127);
188 m_oplink->SignalStrengthLabel->setText(QString("%1dBm").arg(m_oplink->SignalStrengthBar->value()));
190 int afc_valueKHz = m_oplink->AFCCorrection->text().toInt() / 1000;
191 m_oplink->AFCCorrectionBar->setValue(afc_valueKHz);
193 // Enable components based on the board type connected.
194 switch (oplinkStatusObj->boardType()) {
195 case 0x09: // Revolution, DiscoveryF4Bare, RevoNano, RevoProto
196 case 0x92: // Sparky2
197 setOPLMOptionsVisible(false);
198 break;
199 case 0x03: // OPLinkMini
200 setOPLMOptionsVisible(true);
201 break;
202 default:
203 // This shouldn't happen.
204 break;
207 if (!statusUpdated) {
208 statusUpdated = true;
209 // update static info
210 updateInfo();
214 void ConfigOPLinkWidget::setOPLMOptionsVisible(bool visible)
216 m_oplink->UartsGroupBox->setVisible(visible);
217 m_oplink->ConnectionsGroupBox->setVisible(visible);
220 void ConfigOPLinkWidget::updateInfo()
222 // qDebug() << "ConfigOPLinkWidget::updateInfo";
224 // Update the Description field
226 // extract desc into byte array
227 OPLinkStatus::DataFields oplinkStatusData = oplinkStatusObj->getData();
228 quint8 *desc = oplinkStatusData.Description;
229 QByteArray ba;
231 for (unsigned int i = 0; i < OPLinkStatus::DESCRIPTION_NUMELEM; i++) {
232 ba.append(desc[i]);
235 // parse byte array into device descriptor
236 deviceDescriptorStruct dds;
237 UAVObjectUtilManager::descriptionToStructure(ba, dds);
239 // update UI
240 if (!dds.gitTag.isEmpty()) {
241 m_oplink->FirmwareVersion->setText(dds.gitTag + " " + dds.gitDate);
242 } else {
243 m_oplink->FirmwareVersion->setText(tr("Unknown"));
246 // Update the serial number field
247 char buf[OPLinkStatus::CPUSERIAL_NUMELEM * 2 + 1];
248 for (unsigned int i = 0; i < OPLinkStatus::CPUSERIAL_NUMELEM; ++i) {
249 unsigned char val = oplinkStatusObj->cpuSerial(i) >> 4;
250 buf[i * 2] = ((val < 10) ? '0' : '7') + val;
251 val = oplinkStatusObj->cpuSerial(i) & 0xf;
252 buf[i * 2 + 1] = ((val < 10) ? '0' : '7') + val;
254 buf[OPLinkStatus::CPUSERIAL_NUMELEM * 2] = '\0';
255 m_oplink->SerialNumber->setText(buf);
258 void ConfigOPLinkWidget::updateSettings()
260 // qDebug() << "ConfigOPLinkWidget::updateSettings";
262 bool is_openlrs = isComboboxOptionSelected(m_oplink->Protocol, OPLinkSettings::PROTOCOL_OPENLRS);
263 bool is_coordinator = isComboboxOptionSelected(m_oplink->Protocol, OPLinkSettings::PROTOCOL_OPLINKCOORDINATOR);
264 bool is_receiver = isComboboxOptionSelected(m_oplink->Protocol, OPLinkSettings::PROTOCOL_OPLINKRECEIVER);
265 bool is_oplink = (is_receiver || is_coordinator);
266 bool is_ppm_only = isComboboxOptionSelected(m_oplink->LinkType, OPLinkSettings::LINKTYPE_CONTROL);
267 bool is_ppm = isComboboxOptionSelected(m_oplink->LinkType, OPLinkSettings::LINKTYPE_DATAANDCONTROL);
268 bool is_main_serial = isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL);
269 bool is_main_telem = isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_TELEMETRY);
270 bool is_flexi_serial = isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL);
271 bool is_flexi_telem = isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_TELEMETRY);
272 bool is_vcp_main = isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_MAIN);
273 bool is_vcp_flexi = isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_FLEXI);
274 bool is_custom_id = !m_oplink->CustomDeviceID->text().isEmpty();
275 bool is_bound = !m_oplink->CoordID->text().isEmpty();
277 bool is_stream_main = isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_MAIN) ||
278 isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_MAIN);
279 bool is_stream_flexi = isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_FLEXI) ||
280 isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_FLEXI);
282 bool is_flexi_ppm = isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_PPM);
283 bool is_main_ppm = isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_PPM);
285 if (!is_stream_main && !is_vcp_main && (is_main_serial || is_main_telem)) {
286 setComboboxSelectedOption(m_oplink->MainPort, OPLinkSettings::MAINPORT_DISABLED);
287 is_main_serial = false;
288 is_main_telem = false;
290 if (!is_stream_flexi && !is_vcp_flexi && (is_flexi_serial || is_flexi_telem)) {
291 setComboboxSelectedOption(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_DISABLED);
292 is_flexi_serial = false;
293 is_flexi_telem = false;
296 enableComboBoxOptionItem(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_TELEMETRY, is_stream_flexi);
297 enableComboBoxOptionItem(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL, (is_stream_flexi || is_vcp_flexi));
298 enableComboBoxOptionItem(m_oplink->MainPort, OPLinkSettings::MAINPORT_TELEMETRY, is_stream_main);
299 enableComboBoxOptionItem(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL, (is_stream_main || is_vcp_main));
301 m_oplink->MainPort->setEnabled(is_oplink || is_vcp_main);
302 m_oplink->FlexiPort->setEnabled(is_oplink || is_vcp_flexi);
304 m_oplink->PPMoutRssi->setEnabled(is_receiver && (is_ppm || is_ppm_only) && (is_flexi_ppm || is_main_ppm));
306 m_oplink->MainComSpeed->setEnabled(is_oplink && !is_ppm_only && !is_vcp_main && (is_main_serial || is_main_telem));
307 m_oplink->FlexiComSpeed->setEnabled(is_oplink && !is_ppm_only && !is_vcp_flexi && (is_flexi_serial || is_flexi_telem));
308 m_oplink->CoordID->setEnabled(is_receiver || is_openlrs);
309 m_oplink->CoordID->setReadOnly(is_openlrs);
310 m_oplink->UnbindButton->setEnabled((is_receiver && is_bound) || is_openlrs);
312 m_oplink->CustomDeviceID->setEnabled(is_coordinator);
313 m_oplink->ClearDeviceButton->setEnabled(is_coordinator && is_custom_id);
315 m_oplink->RadioPriStream->setEnabled(is_oplink && !is_ppm_only);
316 m_oplink->RadioAuxStream->setEnabled(is_oplink && !is_ppm_only);
318 m_oplink->AirDataRate->setEnabled(is_oplink && !is_ppm_only);
319 m_oplink->RFBand->setEnabled(is_oplink);
320 m_oplink->MinimumChannel->setEnabled(is_oplink);
321 m_oplink->MaximumChannel->setEnabled(is_oplink);
323 m_oplink->LinkType->setEnabled(is_oplink);
324 m_oplink->MaxRFTxPower->setEnabled(is_oplink);
327 void ConfigOPLinkWidget::protocolChanged()
329 updateSettings();
332 void ConfigOPLinkWidget::linkTypeChanged()
334 updateSettings();
337 void ConfigOPLinkWidget::customIDChanged()
339 updateSettings();
342 void ConfigOPLinkWidget::coordIDChanged()
344 updateSettings();
347 void ConfigOPLinkWidget::minChannelChanged()
349 channelChanged(false);
352 void ConfigOPLinkWidget::maxChannelChanged()
354 channelChanged(true);
357 void ConfigOPLinkWidget::rfBandChanged()
359 switch (getComboboxSelectedOption(m_oplink->RFBand)) {
360 case OPLinkSettings::RFBAND_915MHZ:
361 frequency_base = 900.0f;
362 frequency_step = FREQUENCY_STEP * 2.0f;
363 channel_tooltip = tr("Channel 0 is 900 MHz, channel 250 is 920 MHz, and the channel spacing is 80 KHz.");
364 break;
365 case OPLinkSettings::RFBAND_868MHZ:
366 frequency_base = 860.0f;
367 frequency_step = FREQUENCY_STEP * 2.0f;
368 channel_tooltip = tr("Channel 0 is 860 MHz, channel 250 is 880 MHz, and the channel spacing is 80 KHz.");
369 break;
370 case OPLinkSettings::RFBAND_433MHZ:
371 frequency_base = 430.0f;
372 frequency_step = FREQUENCY_STEP;
373 channel_tooltip = tr("Channel 0 is 430 MHz, channel 250 is 440 MHz, and the channel spacing is 40 KHz.");
374 break;
377 // Update frequency display according to the RF band change
378 updateFrequencyDisplay();
381 void ConfigOPLinkWidget::channelChanged(bool isMax)
383 int minChannel = m_oplink->MinimumChannel->value();
384 int maxChannel = m_oplink->MaximumChannel->value();
386 if ((maxChannel - minChannel) < MIN_CHANNEL_RANGE) {
387 if (isMax) {
388 minChannel = maxChannel - MIN_CHANNEL_RANGE;
389 } else {
390 maxChannel = minChannel + MIN_CHANNEL_RANGE;
393 if (maxChannel > MAX_CHANNEL_NUM) {
394 maxChannel = MAX_CHANNEL_NUM;
395 minChannel = MAX_CHANNEL_NUM - MIN_CHANNEL_RANGE;
398 if (minChannel < 0) {
399 minChannel = 0;
400 maxChannel = MIN_CHANNEL_RANGE;
404 m_oplink->MaximumChannel->setValue(maxChannel);
405 m_oplink->MinimumChannel->setValue(minChannel);
407 updateFrequencyDisplay();
410 void ConfigOPLinkWidget::updateFrequencyDisplay()
412 // Calculate and Display frequency in MHz
413 float minFrequency = frequency_base + (m_oplink->MinimumChannel->value() * frequency_step);
414 float maxFrequency = frequency_base + (m_oplink->MaximumChannel->value() * frequency_step);
416 m_oplink->MinFreq->setText("(" + QString::number(minFrequency, 'f', 3) + " MHz)");
417 m_oplink->MaxFreq->setText("(" + QString::number(maxFrequency, 'f', 3) + " MHz)");
419 m_oplink->MinimumChannel->setToolTip(channel_tooltip);
420 m_oplink->MaximumChannel->setToolTip(channel_tooltip);
423 void ConfigOPLinkWidget::mainPortChanged()
425 switch (getComboboxSelectedOption(m_oplink->MainPort)) {
426 case OPLinkSettings::MAINPORT_PPM:
427 if (isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_PPM)) {
428 setComboboxSelectedOption(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_DISABLED);
430 case OPLinkSettings::MAINPORT_PWM:
431 case OPLinkSettings::MAINPORT_DISABLED:
432 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_MAIN)) {
433 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
435 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_MAIN)) {
436 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
438 if (isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_MAIN)) {
439 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
441 m_oplink->MainComSpeed->setEnabled(false);
442 break;
443 case OPLinkSettings::MAINPORT_TELEMETRY:
444 if (isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_TELEMETRY)) {
445 setComboboxSelectedOption(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL);
447 case OPLinkSettings::MAINPORT_SERIAL:
448 m_oplink->MainComSpeed->setEnabled(true);
449 break;
450 default:
451 break;
453 updateSettings();
456 void ConfigOPLinkWidget::flexiPortChanged()
458 switch (getComboboxSelectedOption(m_oplink->FlexiPort)) {
459 case OPLinkSettings::FLEXIPORT_PPM:
460 if (isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_PPM)) {
461 setComboboxSelectedOption(m_oplink->MainPort, OPLinkSettings::MAINPORT_DISABLED);
463 case OPLinkSettings::FLEXIPORT_PWM:
464 case OPLinkSettings::FLEXIPORT_DISABLED:
465 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_FLEXI)) {
466 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
468 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_FLEXI)) {
469 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
471 if (isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_FLEXI)) {
472 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
474 m_oplink->FlexiComSpeed->setEnabled(false);
475 break;
476 case OPLinkSettings::FLEXIPORT_TELEMETRY:
477 if (isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_TELEMETRY)) {
478 setComboboxSelectedOption(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL);
480 case OPLinkSettings::FLEXIPORT_SERIAL:
481 m_oplink->FlexiComSpeed->setEnabled(true);
482 break;
483 default:
484 break;
486 updateSettings();
489 void ConfigOPLinkWidget::radioPriStreamChanged()
491 switch (getComboboxSelectedOption(m_oplink->RadioPriStream)) {
492 case OPLinkSettings::RADIOPRISTREAM_DISABLED:
493 break;
494 case OPLinkSettings::RADIOPRISTREAM_HID:
495 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_HID)) {
496 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
498 break;
499 case OPLinkSettings::RADIOPRISTREAM_MAIN:
500 if (!isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_TELEMETRY) &&
501 !isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL)) {
502 setComboboxSelectedOption(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL);
504 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_MAIN)) {
505 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
507 if (isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_MAIN)) {
508 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
510 break;
511 case OPLinkSettings::RADIOPRISTREAM_FLEXI:
512 if (!isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_TELEMETRY) &&
513 !isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL)) {
514 setComboboxSelectedOption(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL);
516 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_FLEXI)) {
517 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
519 if (isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_FLEXI)) {
520 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
522 break;
523 case OPLinkSettings::RADIOPRISTREAM_VCP:
524 if (!isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED)) {
525 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
527 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_VCP)) {
528 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
530 break;
532 updateSettings();
535 void ConfigOPLinkWidget::radioAuxStreamChanged()
537 switch (getComboboxSelectedOption(m_oplink->RadioAuxStream)) {
538 case OPLinkSettings::RADIOAUXSTREAM_DISABLED:
539 break;
540 case OPLinkSettings::RADIOAUXSTREAM_HID:
541 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_HID)) {
542 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
544 break;
545 case OPLinkSettings::RADIOAUXSTREAM_MAIN:
546 if (!isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_TELEMETRY) &&
547 !isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL)) {
548 setComboboxSelectedOption(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL);
550 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_MAIN)) {
551 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
553 if (isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_MAIN)) {
554 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
556 break;
557 case OPLinkSettings::RADIOAUXSTREAM_FLEXI:
558 if (!isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_TELEMETRY) &&
559 !isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL)) {
560 setComboboxSelectedOption(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL);
562 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_FLEXI)) {
563 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
565 if (isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_FLEXI)) {
566 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
568 break;
569 case OPLinkSettings::RADIOAUXSTREAM_VCP:
570 if (!isComboboxOptionSelected(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED)) {
571 setComboboxSelectedOption(m_oplink->VCPBridge, OPLinkSettings::VCPBRIDGE_DISABLED);
573 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_VCP)) {
574 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
576 break;
578 updateSettings();
581 void ConfigOPLinkWidget::vcpBridgeChanged()
583 switch (getComboboxSelectedOption(m_oplink->VCPBridge)) {
584 case OPLinkSettings::VCPBRIDGE_DISABLED:
585 break;
586 case OPLinkSettings::VCPBRIDGE_MAIN:
587 if (!isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_TELEMETRY) &&
588 !isComboboxOptionSelected(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL)) {
589 setComboboxSelectedOption(m_oplink->MainPort, OPLinkSettings::MAINPORT_SERIAL);
591 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_VCP) ||
592 isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_MAIN)) {
593 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
595 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_VCP) ||
596 isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_MAIN)) {
597 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
599 break;
600 case OPLinkSettings::VCPBRIDGE_FLEXI:
601 if (!isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_TELEMETRY) &&
602 !isComboboxOptionSelected(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL)) {
603 setComboboxSelectedOption(m_oplink->FlexiPort, OPLinkSettings::FLEXIPORT_SERIAL);
605 if (isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_VCP) ||
606 isComboboxOptionSelected(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_FLEXI)) {
607 setComboboxSelectedOption(m_oplink->RadioPriStream, OPLinkSettings::RADIOPRISTREAM_DISABLED);
609 if (isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_VCP) ||
610 isComboboxOptionSelected(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_FLEXI)) {
611 setComboboxSelectedOption(m_oplink->RadioAuxStream, OPLinkSettings::RADIOAUXSTREAM_DISABLED);
613 break;
615 updateSettings();
618 void ConfigOPLinkWidget::unbind()
620 // Clear the coordinator ID
621 m_oplink->CoordID->clear();
623 // Clear the OpenLRS settings when needed
624 if (isComboboxOptionSelected(m_oplink->Protocol, OPLinkSettings::PROTOCOL_OPENLRS)) {
625 QStringList openLRS_settings;
626 openLRS_settings << "Version" << "SerialBaudrate" << "ModemParams" << "Flags" \
627 << "RFFrequency" << "RFPower" << "RFChannelSpacing" << "HopChannel";
629 for (int i = 0; i < openLRS_settings.size(); ++i) {
630 oplinkSettingsObj->getField(openLRS_settings[i])->clear();
635 void ConfigOPLinkWidget::clearDeviceID()
637 // Clear the OPLM device ID
638 m_oplink->CustomDeviceID->clear();