|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * |
| 4 | + * @file configpikoblxhwwidget.cpp |
| 5 | + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2017. |
| 6 | + * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. |
| 7 | + * @addtogroup GCSPlugins GCS Plugins |
| 8 | + * @{ |
| 9 | + * @addtogroup ConfigPlugin Config Plugin |
| 10 | + * @{ |
| 11 | + * @brief PikoBLX hardware configuration panel |
| 12 | + *****************************************************************************/ |
| 13 | +/* |
| 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. |
| 18 | + * |
| 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. |
| 23 | + * |
| 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 |
| 27 | + */ |
| 28 | +#include "configpikoblxhwwidget.h" |
| 29 | + |
| 30 | +#include "ui_configpikoblxhwwidget.h" |
| 31 | + |
| 32 | +#include "hwsettings.h" |
| 33 | + |
| 34 | +#include <QDebug> |
| 35 | + |
| 36 | +ConfigPikoBLXHWWidget::ConfigPikoBLXHWWidget(QWidget *parent) : ConfigTaskWidget(parent) |
| 37 | +{ |
| 38 | + m_ui = new Ui_PikoBLXHWWidget(); |
| 39 | + m_ui->setupUi(this); |
| 40 | + |
| 41 | + // must be done before auto binding ! |
| 42 | + setWikiURL("PikoBLX+Configuration"); |
| 43 | + |
| 44 | + addAutoBindings(); |
| 45 | + |
| 46 | + addUAVObject("HwSettings"); |
| 47 | + addUAVObject("HwPikoBLXSettings"); |
| 48 | + |
| 49 | + addWidgetBinding("HwPikoBLXSettings", "UARTPort", m_ui->cbUART1, 0, 1, true); |
| 50 | + addWidgetBinding("HwPikoBLXSettings", "UARTPort", m_ui->cbUART2, 1, 1, true); |
| 51 | + addWidgetBinding("HwPikoBLXSettings", "UARTPort", m_ui->cbUART3, 2, 1, true); |
| 52 | + addWidgetBinding("HwPikoBLXSettings", "LEDPort", m_ui->cbLEDPort); |
| 53 | + |
| 54 | + m_cbUART[0] = m_ui->cbUART1; |
| 55 | + m_cbUART[1] = m_ui->cbUART2; |
| 56 | + m_cbUART[2] = m_ui->cbUART3; |
| 57 | + |
| 58 | + for(quint32 i = 0; i < HwPikoBLXSettings::UARTPORT_NUMELEM; ++i) { |
| 59 | + connect(m_cbUART[i], static_cast<void(QComboBox::*) (int)>(&QComboBox::currentIndexChanged), this, &ConfigPikoBLXHWWidget::UARTxChanged); |
| 60 | + } |
| 61 | + |
| 62 | + m_ui->commonHWSettings->registerWidgets(*this); |
| 63 | + |
| 64 | + connect(m_ui->commonHWSettings, &CommonHWSettingsWidget::USBVCPFunctionChanged, this, &ConfigPikoBLXHWWidget::USBVCPFunctionChanged); |
| 65 | + |
| 66 | + updateFeatures(); |
| 67 | +} |
| 68 | + |
| 69 | +ConfigPikoBLXHWWidget::~ConfigPikoBLXHWWidget() |
| 70 | +{ |
| 71 | + delete m_ui; |
| 72 | +} |
| 73 | + |
| 74 | +void ConfigPikoBLXHWWidget::refreshWidgetsValuesImpl(UAVObject *obj) |
| 75 | +{ |
| 76 | +// is this needed? This is to force sane state |
| 77 | +// UART1Changed(0); |
| 78 | +// UART2Changed(0); |
| 79 | +// UART3Changed(0); |
| 80 | + |
| 81 | + m_ui->commonHWSettings->refreshWidgetsValues(obj); |
| 82 | +} |
| 83 | + |
| 84 | +void ConfigPikoBLXHWWidget::updateObjectsFromWidgetsImpl() |
| 85 | +{ |
| 86 | + updateFeatures(); |
| 87 | +} |
| 88 | + |
| 89 | +void ConfigPikoBLXHWWidget::updateFeatures() |
| 90 | +{ |
| 91 | + quint32 features = CommonHWSettingsWidget::F_USB; |
| 92 | + |
| 93 | + for(quint32 i = 0; i < HwPikoBLXSettings::UARTPORT_NUMELEM; ++i) { |
| 94 | + switch (getComboboxSelectedOption(m_cbUART[i])) { |
| 95 | + case HwPikoBLXSettings::UARTPORT_TELEMETRY: |
| 96 | + features |= CommonHWSettingsWidget::F_TELEMETRY; |
| 97 | + break; |
| 98 | + case HwPikoBLXSettings::UARTPORT_DSM: |
| 99 | + features |= CommonHWSettingsWidget::F_DSM; |
| 100 | + break; |
| 101 | + case HwPikoBLXSettings::UARTPORT_SBUS: |
| 102 | + features |= CommonHWSettingsWidget::F_SBUS; |
| 103 | + break; |
| 104 | + case HwPikoBLXSettings::UARTPORT_GPS: |
| 105 | + features |= CommonHWSettingsWidget::F_GPS; |
| 106 | + break; |
| 107 | + case HwPikoBLXSettings::UARTPORT_DEBUGCONSOLE: |
| 108 | + features |= CommonHWSettingsWidget::F_DEBUGCONSOLE; |
| 109 | + break; |
| 110 | + default: |
| 111 | + break; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + m_ui->commonHWSettings->setFeatures(features); |
| 116 | + |
| 117 | + HwSettings::GetInstance(getObjectManager()) |
| 118 | + ->setOptionalModules(HwSettings::OPTIONALMODULES_GPS, |
| 119 | + (features & CommonHWSettingsWidget::F_GPS) |
| 120 | + ? HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED); |
| 121 | +} |
| 122 | + |
| 123 | +bool ConfigPikoBLXHWWidget::optionConflict(int uartOption, int vcpOption) |
| 124 | +{ |
| 125 | + return (vcpOption == HwSettings::USB_VCPPORT_DEBUGCONSOLE |
| 126 | + && uartOption == HwPikoBLXSettings::UARTPORT_DEBUGCONSOLE) |
| 127 | + || (vcpOption == HwSettings::USB_VCPPORT_MAVLINK |
| 128 | + && uartOption == HwPikoBLXSettings::UARTPORT_MAVLINK); |
| 129 | +} |
| 130 | + |
| 131 | +void ConfigPikoBLXHWWidget::UARTxChanged(int index) |
| 132 | +{ |
| 133 | + Q_UNUSED(index); |
| 134 | + |
| 135 | + QComboBox *cbUARTx = qobject_cast<QComboBox *>(sender()); |
| 136 | + |
| 137 | + if(!cbUARTx) { |
| 138 | + return; |
| 139 | + } |
| 140 | + |
| 141 | + // Everything except HwPikoBLXSettings::UARTPORT_DISABLED and HwPikoBLXSettings::UARTPORT_DSM |
| 142 | + // is allowed on single port only. |
| 143 | + // HoTT SUMD & SUMH belong to the same receiver group, therefore cannot be configure at the same time |
| 144 | + // |
| 145 | + |
| 146 | + int option = getComboboxSelectedOption(cbUARTx); |
| 147 | + |
| 148 | + if (option == HwPikoBLXSettings::UARTPORT_HOTTSUMD) { |
| 149 | + option = HwPikoBLXSettings::UARTPORT_HOTTSUMH; |
| 150 | + } |
| 151 | + |
| 152 | + if (option != HwPikoBLXSettings::UARTPORT_DISABLED && option != HwPikoBLXSettings::UARTPORT_DSM) { |
| 153 | + |
| 154 | + for(quint32 i = 0; i < HwPikoBLXSettings::UARTPORT_NUMELEM; ++i) { |
| 155 | + if (m_cbUART[i] == cbUARTx) { |
| 156 | + continue; |
| 157 | + } |
| 158 | + int other = getComboboxSelectedOption(m_cbUART[i]); |
| 159 | + if (other == HwPikoBLXSettings::UARTPORT_HOTTSUMD) { |
| 160 | + other = HwPikoBLXSettings::UARTPORT_HOTTSUMH; |
| 161 | + } |
| 162 | + if (other == option) { |
| 163 | + setComboboxSelectedOption(m_cbUART[i], HwPikoBLXSettings::UARTPORT_DISABLED); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + QComboBox *cbUSBVCP = m_ui->commonHWSettings->USBVCPComboBox(); |
| 168 | + |
| 169 | + if (optionConflict(option, getComboboxSelectedOption(cbUSBVCP))) { |
| 170 | + setComboboxSelectedOption(cbUSBVCP, HwSettings::USB_VCPPORT_DISABLED); |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + updateFeatures(); |
| 175 | +} |
| 176 | + |
| 177 | +void ConfigPikoBLXHWWidget::USBVCPFunctionChanged(int index) |
| 178 | +{ |
| 179 | + Q_UNUSED(index); |
| 180 | + |
| 181 | + int vcpOption = getComboboxSelectedOption(m_ui->commonHWSettings->USBVCPComboBox()); |
| 182 | + |
| 183 | + for(quint32 i = 0; i < HwPikoBLXSettings::UARTPORT_NUMELEM; ++i) { |
| 184 | + if (optionConflict(getComboboxSelectedOption(m_cbUART[i]), vcpOption)) { |
| 185 | + setComboboxSelectedOption(m_cbUART[i], HwPikoBLXSettings::UARTPORT_DISABLED); |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + updateFeatures(); |
| 190 | +} |
| 191 | + |
0 commit comments