Skip to content

Commit 4f22425

Browse files
committed
LP-525 More work on hw pages. Added PikoBLX.
1 parent 4df72a2 commit 4f22425

10 files changed

Lines changed: 1011 additions & 77 deletions

ground/gcs/src/plugins/config/commonhwsettingswidget.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,32 @@
2525
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2626
*/
2727
#include "commonhwsettingswidget.h"
28-
2928
#include "ui_commonhwsettingswidget.h"
29+
#include "hwsettings.h"
3030

3131
#include <QDebug>
32+
#include <extensionsystem/pluginmanager.h>
33+
#include "uavobjectmanager.h"
34+
3235

3336
CommonHWSettingsWidget::CommonHWSettingsWidget(QWidget *parent) : QWidget(parent)
3437
{
3538
m_ui = new Ui_CommonHWSettingsWidget();
3639
m_ui->setupUi(this);
3740

41+
m_ui->cbDSMxBind->addItem(tr("Disabled"), 0);
42+
43+
m_ui->cbDSMxBind->addItem(tr("DSM2 1024bit/22ms"), 3);
44+
m_ui->cbDSMxBind->addItem(tr("DSM2 2048bit/11ms"), 5);
45+
m_ui->cbDSMxBind->addItem(tr("DSMX 1024bit/22ms"), 7);
46+
m_ui->cbDSMxBind->addItem(tr("DSMX 2048bit/22ms"), 8);
47+
m_ui->cbDSMxBind->addItem(tr("DSMX 2048bit/11ms"), 9);
48+
49+
m_ui->cbDSMxBind->setCurrentIndex(0);
50+
3851
setFeatures(0);
3952

40-
/* Relay signals from private members */
53+
// Relay signals from private members
4154
connect(m_ui->cbUSBHID, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBHIDFunctionChanged(int)));
4255
connect(m_ui->cbUSBVCP, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBVCPFunctionChanged(int)));
4356
}
@@ -49,22 +62,32 @@ CommonHWSettingsWidget::~CommonHWSettingsWidget()
4962

5063
void CommonHWSettingsWidget::registerWidgets(ConfigTaskWidget &ct)
5164
{
52-
// addAutoBindings();
53-
54-
// ct.addUAVObject("HwSettings");
55-
5665
ct.addWidgetBinding("HwSettings", "USB_HIDPort", m_ui->cbUSBHID);
5766
ct.addWidgetBinding("HwSettings", "USB_VCPPort", m_ui->cbUSBVCP);
5867

5968
ct.addWidgetBinding("HwSettings", "TelemetrySpeed", m_ui->cbTelemetrySpeed);
6069
ct.addWidgetBinding("HwSettings", "GPSSpeed", m_ui->cbGPSSpeed);
6170
ct.addWidgetBinding("HwSettings", "DebugConsoleSpeed", m_ui->cbDebugConsoleSpeed);
6271
ct.addWidgetBinding("HwSettings", "SBusMode", m_ui->cbSBUSMode);
72+
6373
ct.addWidgetBinding("HwSettings", "DSMxBind", m_ui->cbDSMxBind, 0, 1, true);
6474

6575
ct.addWidgetBinding("GPSSettings", "DataProtocol", m_ui->cbGPSProtocol);
6676
}
6777

78+
void CommonHWSettingsWidget::refreshWidgetsValues(UAVObject *obj)
79+
{
80+
Q_UNUSED(obj);
81+
82+
UAVObjectManager *objMngr = ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>();
83+
84+
int option = HwSettings::GetInstance(objMngr)->getDSMxBind();
85+
86+
if(m_ui->cbDSMxBind->findData(option) == -1) {
87+
m_ui->cbDSMxBind->addItem(tr("%1 Pulses").arg(option), option);
88+
m_ui->cbDSMxBind->setCurrentIndex(-1);
89+
}
90+
}
6891

6992
void CommonHWSettingsWidget::setFeatures(quint32 features)
7093
{

ground/gcs/src/plugins/config/commonhwsettingswidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class CommonHWSettingsWidget : public QWidget {
4646
virtual ~CommonHWSettingsWidget();
4747

4848
void registerWidgets(ConfigTaskWidget &ct);
49-
49+
void refreshWidgetsValues(UAVObject *obj);
50+
5051
void setFeatures(quint32 features);
5152

5253
QComboBox *USBVCPComboBox();

ground/gcs/src/plugins/config/config.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ HEADERS += \
5151
configrevohwwidget.h \
5252
configspracingf3evohwwidget.h \
5353
configtinyfishhwwidget.h \
54+
configpikoblxhwwidget.h \
5455
commonhwsettingswidget.h \
5556
calibration/calibrationutils.h \
5657
calibration/wizardstate.h \
@@ -101,6 +102,7 @@ SOURCES += \
101102
configrevohwwidget.cpp \
102103
configspracingf3evohwwidget.cpp \
103104
configtinyfishhwwidget.cpp \
105+
configpikoblxhwwidget.cpp \
104106
commonhwsettingswidget.cpp \
105107
calibration/calibrationutils.cpp \
106108
calibration/wizardstate.cpp \
@@ -141,6 +143,7 @@ FORMS += \
141143
autotune.ui \
142144
configspracingf3evohwwidget.ui \
143145
configtinyfishhwwidget.ui \
146+
configpikoblxhwwidget.ui \
144147
commonhwsettingswidget.ui \
145148
oplink.ui \
146149
configrevonanohwwidget.ui \
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
******************************************************************************
3+
*
4+
* @file configpikoblxhwwidget.h
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 PikoBLX 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+
#ifndef CONFIGPIKOBLXHWWIDGET_H
28+
#define CONFIGPIKOBLXHWWIDGET_H
29+
30+
#include "../uavobjectwidgetutils/configtaskwidget.h"
31+
32+
#include "hwpikoblxsettings.h"
33+
34+
class Ui_PikoBLXHWWidget;
35+
36+
class UAVObject;
37+
38+
class QWidget;
39+
40+
class ConfigPikoBLXHWWidget : public ConfigTaskWidget {
41+
Q_OBJECT
42+
43+
public:
44+
ConfigPikoBLXHWWidget(QWidget *parent = 0);
45+
~ConfigPikoBLXHWWidget();
46+
47+
protected:
48+
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
49+
virtual void updateObjectsFromWidgetsImpl();
50+
51+
private:
52+
Ui_PikoBLXHWWidget *m_ui;
53+
54+
QComboBox *m_cbUART[HwPikoBLXSettings::UARTPORT_NUMELEM];
55+
56+
void updateFeatures();
57+
58+
bool optionConflict(int uartOption, int vcpOption);
59+
60+
private slots:
61+
void UARTxChanged(int index);
62+
void USBVCPFunctionChanged(int index);
63+
};
64+
65+
#endif // CONFIGPIKOBLXHWWIDGET_H

0 commit comments

Comments
 (0)