|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * |
| 4 | + * @file commonhwsettingswidget.cpp |
| 5 | + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017. |
| 6 | + * @addtogroup GCSPlugins GCS Plugins |
| 7 | + * @{ |
| 8 | + * @addtogroup ConfigPlugin Config Plugin |
| 9 | + * @{ |
| 10 | + * @brief Common hardware configuration panel |
| 11 | + *****************************************************************************/ |
| 12 | +/* |
| 13 | + * This program is free software; you can redistribute it and/or modify |
| 14 | + * it under the terms of the GNU General Public License as published by |
| 15 | + * the Free Software Foundation; either version 3 of the License, or |
| 16 | + * (at your option) any later version. |
| 17 | + * |
| 18 | + * This program is distributed in the hope that it will be useful, but |
| 19 | + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 20 | + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 21 | + * for more details. |
| 22 | + * |
| 23 | + * You should have received a copy of the GNU General Public License along |
| 24 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | + */ |
| 27 | +#include "commonhwsettingswidget.h" |
| 28 | +#include "ui_commonhwsettingswidget.h" |
| 29 | +#include "hwsettings.h" |
| 30 | + |
| 31 | +#include <QDebug> |
| 32 | +#include <extensionsystem/pluginmanager.h> |
| 33 | +#include "uavobjectmanager.h" |
| 34 | + |
| 35 | + |
| 36 | +CommonHWSettingsWidget::CommonHWSettingsWidget(QWidget *parent) : ConfigTaskWidget(parent, Child) |
| 37 | +{ |
| 38 | + m_ui = new Ui_CommonHWSettingsWidget(); |
| 39 | + m_ui->setupUi(this); |
| 40 | + |
| 41 | + m_ui->cbDSMxBind->addItem(tr("Disabled"), 0); |
| 42 | + |
| 43 | + setFeatures(0); |
| 44 | + |
| 45 | + // Relay signals from private members |
| 46 | + connect(m_ui->cbUSBHID, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBHIDFunctionChanged(int))); |
| 47 | + connect(m_ui->cbUSBVCP, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBVCPFunctionChanged(int))); |
| 48 | + |
| 49 | + // And these are here to handle conflicting VCP & HID options (such as USBTelemetry). |
| 50 | + connect(m_ui->cbUSBHID, SIGNAL(currentIndexChanged(int)), this, SLOT(USBHIDComboChanged(int))); |
| 51 | + connect(m_ui->cbUSBVCP, SIGNAL(currentIndexChanged(int)), this, SLOT(USBVCPComboChanged(int))); |
| 52 | +} |
| 53 | + |
| 54 | +CommonHWSettingsWidget::~CommonHWSettingsWidget() |
| 55 | +{ |
| 56 | + delete m_ui; |
| 57 | +} |
| 58 | + |
| 59 | +void CommonHWSettingsWidget::registerWidgets(ConfigTaskWidget &ct) |
| 60 | +{ |
| 61 | + ct.addWidgetBinding("HwSettings", "USB_HIDPort", m_ui->cbUSBHID); |
| 62 | + ct.addWidgetBinding("HwSettings", "USB_VCPPort", m_ui->cbUSBVCP); |
| 63 | + |
| 64 | + ct.addWidgetBinding("HwSettings", "TelemetrySpeed", m_ui->cbTelemetrySpeed); |
| 65 | + ct.addWidgetBinding("HwSettings", "GPSSpeed", m_ui->cbGPSSpeed); |
| 66 | + ct.addWidgetBinding("HwSettings", "DebugConsoleSpeed", m_ui->cbDebugConsoleSpeed); |
| 67 | + ct.addWidgetBinding("HwSettings", "SBusMode", m_ui->cbSBUSMode); |
| 68 | + |
| 69 | + ct.addWidgetBinding("HwSettings", "DSMxBind", m_ui->cbDSMxBind, 0, 1, true); |
| 70 | + |
| 71 | + ct.addWidgetBinding("GPSSettings", "DataProtocol", m_ui->cbGPSProtocol); |
| 72 | +} |
| 73 | + |
| 74 | +void CommonHWSettingsWidget::refreshWidgetsValues(UAVObject *obj) |
| 75 | +{ |
| 76 | + Q_UNUSED(obj); |
| 77 | + |
| 78 | + int option = HwSettings::GetInstance(getObjectManager())->getDSMxBind(); |
| 79 | + |
| 80 | + if (m_ui->cbDSMxBind->count() == 0) { |
| 81 | + m_ui->cbDSMxBind->addItem(tr("None"), 0); |
| 82 | + m_ui->cbDSMxBind->addItem(tr("DSM2 1024bit/22ms"), 3); |
| 83 | + m_ui->cbDSMxBind->addItem(tr("DSM2 2048bit/11ms"), 5); |
| 84 | + m_ui->cbDSMxBind->addItem(tr("DSMX 1024bit/22ms"), 7); |
| 85 | + m_ui->cbDSMxBind->addItem(tr("DSMX 2048bit/22ms"), 8); |
| 86 | + m_ui->cbDSMxBind->addItem(tr("DSMX 2048bit/11ms"), 9); |
| 87 | + } |
| 88 | + |
| 89 | + int index = m_ui->cbDSMxBind->findData(option); |
| 90 | + |
| 91 | + if (index == -1) { |
| 92 | + m_ui->cbDSMxBind->addItem(tr("%1 Pulses").arg(option), option); |
| 93 | + m_ui->cbDSMxBind->setCurrentIndex(m_ui->cbDSMxBind->count() - 1); |
| 94 | + } else { |
| 95 | + m_ui->cbDSMxBind->setCurrentIndex(index); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +void CommonHWSettingsWidget::setFeatures(quint32 features) |
| 100 | +{ |
| 101 | + bool flag = features != 0; |
| 102 | + |
| 103 | + setVisible(flag); |
| 104 | + |
| 105 | + flag = (features & F_USB) != 0; |
| 106 | + |
| 107 | + m_ui->lbUSBHID->setVisible(flag); |
| 108 | + m_ui->cbUSBHID->setVisible(flag); |
| 109 | + m_ui->lbUSBVCP->setVisible(flag); |
| 110 | + m_ui->cbUSBVCP->setVisible(flag); |
| 111 | + |
| 112 | + flag = (features & F_SBUS) != 0; |
| 113 | + |
| 114 | + m_ui->lbSBUSMode->setVisible(flag); |
| 115 | + m_ui->cbSBUSMode->setVisible(flag); |
| 116 | + |
| 117 | + flag = (features & F_DSM) != 0; |
| 118 | + |
| 119 | + m_ui->lbDSMxBind->setVisible(flag); |
| 120 | + m_ui->cbDSMxBind->setVisible(flag); |
| 121 | + |
| 122 | + flag = (features & F_TELEMETRY) != 0; |
| 123 | + |
| 124 | + m_ui->lbTelemetrySpeed->setVisible(flag); |
| 125 | + m_ui->cbTelemetrySpeed->setVisible(flag); |
| 126 | + |
| 127 | + flag = (features & F_DEBUGCONSOLE) != 0; |
| 128 | + |
| 129 | + m_ui->lbDebugConsoleSpeed->setVisible(flag); |
| 130 | + m_ui->cbDebugConsoleSpeed->setVisible(flag); |
| 131 | + |
| 132 | + flag = (features & F_GPS) != 0; |
| 133 | + |
| 134 | + m_ui->lbGPSSpeed->setVisible(flag); |
| 135 | + m_ui->cbGPSSpeed->setVisible(flag); |
| 136 | + m_ui->lbGPSProtocol->setVisible(flag); |
| 137 | + m_ui->cbGPSProtocol->setVisible(flag); |
| 138 | +} |
| 139 | + |
| 140 | +QComboBox *CommonHWSettingsWidget::USBVCPComboBox() |
| 141 | +{ |
| 142 | + return m_ui->cbUSBVCP; |
| 143 | +} |
| 144 | + |
| 145 | +bool CommonHWSettingsWidget::USBFunctionConflict() |
| 146 | +{ |
| 147 | + return (getComboboxSelectedOption(m_ui->cbUSBHID) == HwSettings::USB_HIDPORT_USBTELEMETRY) |
| 148 | + && (getComboboxSelectedOption(m_ui->cbUSBVCP) == HwSettings::USB_VCPPORT_USBTELEMETRY); |
| 149 | +} |
| 150 | + |
| 151 | +void CommonHWSettingsWidget::USBHIDComboChanged(int index) |
| 152 | +{ |
| 153 | + Q_UNUSED(index); |
| 154 | + |
| 155 | + if (USBFunctionConflict()) { |
| 156 | + setComboboxSelectedOption(m_ui->cbUSBVCP, HwSettings::USB_VCPPORT_DISABLED); |
| 157 | + } else if (getComboboxSelectedOption(m_ui->cbUSBHID) != HwSettings::USB_HIDPORT_USBTELEMETRY) { |
| 158 | + setComboboxSelectedOption(m_ui->cbUSBVCP, HwSettings::USB_VCPPORT_USBTELEMETRY); |
| 159 | + } |
| 160 | +} |
| 161 | + |
| 162 | +void CommonHWSettingsWidget::USBVCPComboChanged(int index) |
| 163 | +{ |
| 164 | + Q_UNUSED(index); |
| 165 | + |
| 166 | + if (USBFunctionConflict()) { |
| 167 | + setComboboxSelectedOption(m_ui->cbUSBHID, HwSettings::USB_HIDPORT_DISABLED); |
| 168 | + } else if (getComboboxSelectedOption(m_ui->cbUSBVCP) != HwSettings::USB_VCPPORT_USBTELEMETRY) { |
| 169 | + setComboboxSelectedOption(m_ui->cbUSBHID, HwSettings::USB_HIDPORT_USBTELEMETRY); |
| 170 | + } |
| 171 | +} |
0 commit comments