15 changed files with 803 additions and 71 deletions
@ -1 +1 @@
@@ -1 +1 @@
|
||||
Subproject commit 7d0aa0205ef8bd13bf855b21d3ebe054dc9109ef |
||||
Subproject commit 42f1a37397335b3c4c96b0a41c73d85e80d54a60 |
@ -0,0 +1,135 @@
@@ -0,0 +1,135 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
This file is part of the QGROUNDCONTROL project |
||||
|
||||
QGROUNDCONTROL is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
QGROUNDCONTROL is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @author Thomas Gubler <thomasgubler@gmail.com>
|
||||
|
||||
#include "QGCMapRCToParamDialog.h" |
||||
#include "ui_QGCMapRCToParamDialog.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QTimer> |
||||
#include <QEventLoop> |
||||
#include <QShowEvent> |
||||
#include <QPushButton> |
||||
|
||||
QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, |
||||
UASInterface *mav, QWidget *parent) : |
||||
QDialog(parent), |
||||
param_id(param_id), |
||||
mav(mav), |
||||
ui(new Ui::QGCMapRCToParamDialog) |
||||
{ |
||||
ui->setupUi(this); |
||||
|
||||
// only enable ok button when param was refreshed
|
||||
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok); |
||||
okButton->setEnabled(false); |
||||
|
||||
ui->paramIdLabel->setText(param_id); |
||||
|
||||
// Refresh the param
|
||||
ParamLoader *paramLoader = new ParamLoader(param_id, mav); |
||||
paramLoader->moveToThread(¶mLoadThread); |
||||
connect(¶mLoadThread, &QThread::finished, paramLoader, &QObject::deleteLater); |
||||
connect(this, &QGCMapRCToParamDialog::refreshParam, paramLoader, &ParamLoader::load); |
||||
connect(paramLoader, &ParamLoader::paramLoaded, this, &QGCMapRCToParamDialog::paramLoaded); |
||||
paramLoadThread.start(); |
||||
emit refreshParam(); |
||||
} |
||||
|
||||
QGCMapRCToParamDialog::~QGCMapRCToParamDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void QGCMapRCToParamDialog::accept() { |
||||
emit mapRCToParamDialogResult(param_id, |
||||
(float)ui->scaleDoubleSpinBox->value(), |
||||
(float)ui->value0DoubleSpinBox->value(), |
||||
(quint8)ui->rcParamChannelComboBox->currentIndex(), |
||||
(float)ui->minValueDoubleSpinBox->value(), |
||||
(float)ui->maxValueDoubleSpinBox->value()); |
||||
|
||||
QDialog::accept(); |
||||
} |
||||
|
||||
void QGCMapRCToParamDialog::paramLoaded(bool success, float value, QString message) |
||||
{ |
||||
paramLoadThread.quit(); |
||||
if (success) { |
||||
ui->infoLabel->setText("Parameter value is up to date"); |
||||
ui->value0DoubleSpinBox->setValue(value); |
||||
ui->value0DoubleSpinBox->setEnabled(true); |
||||
|
||||
connect(this, &QGCMapRCToParamDialog::mapRCToParamDialogResult, |
||||
mav, &UASInterface::sendMapRCToParam); |
||||
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok); |
||||
okButton->setEnabled(true); |
||||
} else { |
||||
qDebug() << "Error while reading param" << param_id; |
||||
ui->infoLabel->setText("Error while refreshing param (" + message + ")"); |
||||
} |
||||
} |
||||
|
||||
void ParamLoader::load() |
||||
{ |
||||
// refresh the parameter from onboard to make sure the current value is used
|
||||
paramMgr->requestParameterUpdate(paramMgr->getDefaultComponentId(), param_id); |
||||
|
||||
// wait until parameter update is received
|
||||
QEventLoop loop; |
||||
QTimer timer; |
||||
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); |
||||
timer.start(10 * 1e3); |
||||
// overloaded signal:
|
||||
connect(mav, static_cast<void (UASInterface::*)( |
||||
int, int, QString, QVariant)>(&UASInterface::parameterChanged), |
||||
this, &ParamLoader::handleParameterChanged); |
||||
connect(this, &ParamLoader::correctParameterChanged, |
||||
&loop, &QEventLoop::quit); |
||||
loop.exec(); |
||||
|
||||
if (!param_received == true) { |
||||
// timeout
|
||||
emit paramLoaded(false, 0.0f, "Timeout"); |
||||
return; |
||||
} |
||||
|
||||
QVariant current_param_value; |
||||
bool got_param = paramMgr->getParameterValue(paramMgr->getDefaultComponentId(), |
||||
param_id, current_param_value); |
||||
|
||||
QString message = got_param ? "" : "param manager Error"; |
||||
emit paramLoaded(got_param, current_param_value.toFloat(), message); |
||||
} |
||||
|
||||
void ParamLoader::handleParameterChanged(int uas, int component, QString parameterName, QVariant value) |
||||
{ |
||||
Q_UNUSED(component); |
||||
Q_UNUSED(value); |
||||
if (uas == mav->getUASID() && parameterName == param_id) { |
||||
param_received = true; |
||||
emit correctParameterChanged(); |
||||
} |
||||
} |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
This file is part of the QGROUNDCONTROL project |
||||
|
||||
QGROUNDCONTROL is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
QGROUNDCONTROL is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @brief Dialog to configure RC to paramter mapping
|
||||
/// @author Thomas Gubler <thomasgubler@gmail.com>
|
||||
|
||||
#ifndef QGCMAPRCTOPARAMDIALOG_H |
||||
#define QGCMAPRCTOPARAMDIALOG_H |
||||
|
||||
#include <QDialog> |
||||
#include <QThread> |
||||
#include "UASInterface.h" |
||||
|
||||
namespace Ui { |
||||
class QGCMapRCToParamDialog; |
||||
} |
||||
|
||||
|
||||
class ParamLoader : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
ParamLoader(QString param_id, UASInterface *mav, QObject * parent = 0): |
||||
QObject(parent), |
||||
mav(mav), |
||||
paramMgr(mav->getParamManager()), |
||||
param_id(param_id), |
||||
param_received(false) |
||||
{} |
||||
|
||||
public slots: |
||||
void load(); |
||||
void handleParameterChanged(int uas, int component, QString parameterName, QVariant value); |
||||
|
||||
signals: |
||||
void paramLoaded(bool success, float value, QString message = ""); |
||||
void correctParameterChanged(); |
||||
|
||||
protected: |
||||
UASInterface *mav; |
||||
QGCUASParamManagerInterface* paramMgr; |
||||
QString param_id; |
||||
bool param_received; |
||||
}; |
||||
|
||||
class QGCMapRCToParamDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
QThread paramLoadThread; |
||||
|
||||
public: |
||||
explicit QGCMapRCToParamDialog(QString param_id, |
||||
UASInterface *mav, QWidget *parent = 0); |
||||
~QGCMapRCToParamDialog(); |
||||
|
||||
signals: |
||||
void mapRCToParamDialogResult(QString param_id, float scale, float value0, |
||||
quint8 param_rc_channel_index, float valueMin, float valueMax); |
||||
void refreshParam(); |
||||
|
||||
public slots: |
||||
void accept(); |
||||
void paramLoaded(bool success, float value, QString message); |
||||
|
||||
protected: |
||||
// void showEvent(QShowEvent * event );
|
||||
QString param_id; |
||||
UASInterface *mav; |
||||
|
||||
private: |
||||
Ui::QGCMapRCToParamDialog *ui; |
||||
}; |
||||
|
||||
#endif // QGCMAPRCTOPARAMDIALOG_H
|
@ -0,0 +1,253 @@
@@ -0,0 +1,253 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>QGCMapRCToParamDialog</class> |
||||
<widget class="QDialog" name="QGCMapRCToParamDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>400</width> |
||||
<height>315</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Dialog</string> |
||||
</property> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>30</x> |
||||
<y>280</y> |
||||
<width>341</width> |
||||
<height>32</height> |
||||
</rect> |
||||
</property> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
||||
</property> |
||||
</widget> |
||||
<widget class="QWidget" name="formLayoutWidget"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>9</x> |
||||
<y>9</y> |
||||
<width>381</width> |
||||
<height>271</height> |
||||
</rect> |
||||
</property> |
||||
<layout class="QFormLayout" name="formLayout"> |
||||
<property name="fieldGrowthPolicy"> |
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> |
||||
</property> |
||||
<item row="0" column="0"> |
||||
<widget class="QLabel" name="label1"> |
||||
<property name="text"> |
||||
<string>Bind</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="0"> |
||||
<widget class="QLabel" name="rcParamChannelInfoLabel"> |
||||
<property name="text"> |
||||
<string>RC-Parameter Channel (Knob No.)</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="1"> |
||||
<widget class="QComboBox" name="rcParamChannelComboBox"> |
||||
<property name="editable"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="currentText"> |
||||
<string>1</string> |
||||
</property> |
||||
<item> |
||||
<property name="text"> |
||||
<string>1</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>2</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>3</string> |
||||
</property> |
||||
</item> |
||||
</widget> |
||||
</item> |
||||
<item row="2" column="0"> |
||||
<widget class="QLabel" name="label2"> |
||||
<property name="text"> |
||||
<string>to</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="3" column="0"> |
||||
<widget class="QLabel" name="paramIdInfoLabel"> |
||||
<property name="text"> |
||||
<string>Parameter</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="3" column="1"> |
||||
<widget class="QLabel" name="paramIdLabel"> |
||||
<property name="text"> |
||||
<string>TextLabel</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="4" column="0"> |
||||
<widget class="QLabel" name="label3"> |
||||
<property name="text"> |
||||
<string>with</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="5" column="0"> |
||||
<widget class="QLabel" name="scaleInfoLabel"> |
||||
<property name="text"> |
||||
<string>Scale</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="5" column="1"> |
||||
<widget class="QDoubleSpinBox" name="scaleDoubleSpinBox"> |
||||
<property name="value"> |
||||
<double>1.000000000000000</double> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="6" column="0"> |
||||
<widget class="QLabel" name="value0InfoLabel"> |
||||
<property name="text"> |
||||
<string>Initial Value</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="6" column="1"> |
||||
<widget class="QDoubleSpinBox" name="value0DoubleSpinBox"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="decimals"> |
||||
<number>8</number> |
||||
</property> |
||||
<property name="minimum"> |
||||
<double>-100000.000000000000000</double> |
||||
</property> |
||||
<property name="maximum"> |
||||
<double>100000.000000000000000</double> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="7" column="0"> |
||||
<widget class="QLabel" name="minInfoLabel"> |
||||
<property name="text"> |
||||
<string>Minimum Value</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="7" column="1"> |
||||
<widget class="QDoubleSpinBox" name="minValueDoubleSpinBox"> |
||||
<property name="decimals"> |
||||
<number>8</number> |
||||
</property> |
||||
<property name="minimum"> |
||||
<double>-100000.000000000000000</double> |
||||
</property> |
||||
<property name="maximum"> |
||||
<double>100000.000000000000000</double> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="8" column="0"> |
||||
<widget class="QLabel" name="maxInfoLabel"> |
||||
<property name="text"> |
||||
<string>Maximum Value</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="8" column="1"> |
||||
<widget class="QDoubleSpinBox" name="maxValueDoubleSpinBox"> |
||||
<property name="decimals"> |
||||
<number>8</number> |
||||
</property> |
||||
<property name="minimum"> |
||||
<double>-10000.000000000000000</double> |
||||
</property> |
||||
<property name="maximum"> |
||||
<double>100000.000000000000000</double> |
||||
</property> |
||||
<property name="singleStep"> |
||||
<double>1.000000000000000</double> |
||||
</property> |
||||
<property name="value"> |
||||
<double>10.000000000000000</double> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="10" column="0"> |
||||
<widget class="QLabel" name="infoLabel"> |
||||
<property name="text"> |
||||
<string>Waiting for parameter refresh,,,</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="9" column="0"> |
||||
<spacer name="verticalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Vertical</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>20</width> |
||||
<height>40</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>QGCMapRCToParamDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>QGCMapRCToParamDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
This file is part of the QGROUNDCONTROL project |
||||
|
||||
QGROUNDCONTROL is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
QGROUNDCONTROL is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @author Thomas Gubler <thomasgubler@gmail.com>
|
||||
|
||||
#include "QGCParamTreeWidget.h" |
||||
#include <QMenu> |
||||
#include <QTreeWidgetItem> |
||||
#include <QDebug> |
||||
|
||||
QGCParamTreeWidget::QGCParamTreeWidget(QWidget *parent) : |
||||
QTreeWidget(parent) |
||||
{ |
||||
setContextMenuPolicy(Qt::CustomContextMenu); |
||||
|
||||
QObject::connect(this, &QGCParamTreeWidget::customContextMenuRequested, |
||||
this, &QGCParamTreeWidget::showContextMenu); |
||||
qDebug() << "create QGCParamTreeWidget"; |
||||
|
||||
} |
||||
|
||||
QGCParamTreeWidget::~QGCParamTreeWidget() |
||||
{ |
||||
|
||||
} |
||||
|
||||
void QGCParamTreeWidget::showContextMenu(const QPoint &pos) |
||||
{ |
||||
QMenu menu; |
||||
QTreeWidgetItem* item = itemAt(pos); |
||||
|
||||
// Only show context menu for parameter items and not for group items
|
||||
// (show for TEST_P but not for TEST)
|
||||
// If a context menu is needed later for the groups then move this 'if'
|
||||
// to below where the actions are created and filter out certain actions
|
||||
// for the outer nodes
|
||||
if (indexOfTopLevelItem(item) > -1 || |
||||
indexOfTopLevelItem(item->parent()) > -1) { |
||||
return; |
||||
} |
||||
|
||||
QString param_id = item->data(0, Qt::DisplayRole).toString(); |
||||
|
||||
// Refresh single parameter
|
||||
QAction* act = new QAction(tr("Refresh this param"), this); |
||||
act->setProperty("action", "refresh"); |
||||
act->setProperty("param_id", param_id); |
||||
connect(act, &QAction::triggered, this, |
||||
&QGCParamTreeWidget::contextMenuAction); |
||||
menu.addAction(act); |
||||
|
||||
// RC to parameter mapping
|
||||
act = new QAction(tr("Map Parameter to RC"), this); |
||||
act->setProperty("action", "maprc"); |
||||
act->setProperty("param_id", param_id); |
||||
connect(act, &QAction::triggered, this, |
||||
&QGCParamTreeWidget::contextMenuAction); |
||||
menu.addAction(act); |
||||
menu.exec(mapToGlobal(pos)); |
||||
} |
||||
|
||||
void QGCParamTreeWidget::contextMenuAction() { |
||||
QString action = qobject_cast<QAction*>( |
||||
sender())->property("action").toString(); |
||||
QString param_id = qobject_cast<QAction*>( |
||||
sender())->property("param_id").toString(); |
||||
|
||||
if (action == "refresh") { |
||||
emit refreshParamRequest(param_id); |
||||
} else if (action == "maprc") { |
||||
emit mapRCToParamRequest(param_id); |
||||
} else { |
||||
qDebug() << "Undefined context menu action"; |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
This file is part of the QGROUNDCONTROL project |
||||
|
||||
QGROUNDCONTROL is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
QGROUNDCONTROL is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @brief A treeview with context menus for parameters
|
||||
/// @author Thomas Gubler <thomasgubler@gmail.com>
|
||||
|
||||
#ifndef QGCPARAMTREEWIDGET_H |
||||
#define QGCPARAMTREEWIDGET_H |
||||
|
||||
#include <QTreeWidget> |
||||
|
||||
/// Implements individual context menus for the QTreeWidgetItems
|
||||
class QGCParamTreeWidget : public QTreeWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
QGCParamTreeWidget(QWidget *parent = 0); |
||||
~QGCParamTreeWidget(); |
||||
|
||||
signals: |
||||
void mapRCToParamRequest(QString param_id); |
||||
void refreshParamRequest(QString param_id); |
||||
|
||||
public slots: |
||||
void showContextMenu(const QPoint &pos); |
||||
void contextMenuAction(); |
||||
|
||||
}; |
||||
|
||||
#endif // QGCPARAMTREEWIDGET_H
|
Loading…
Reference in new issue