Commit 29365f96 authored by Lorenz Meier's avatar Lorenz Meier

Merge pull request #1726 from DonLakeFlyer/MapRCToParam

Map rc to param fix
parents 5b2949ce 63e0f574
......@@ -44,7 +44,7 @@ FactPanel {
VehicleSummaryRow {
labelText: "Airspeed:"
valueText: dPressOffFact.value == 0 ? "Setup required" : "Ready"
valueText: dpressOffFact.value == 0 ? "Setup required" : "Ready"
}
}
}
......@@ -34,8 +34,7 @@
#include <QShowEvent>
#include <QPushButton>
QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id,
UASInterface *mav, QWidget *parent) :
QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav, QWidget *parent) :
QDialog(parent),
param_id(param_id),
mav(mav),
......@@ -43,22 +42,17 @@ QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id,
{
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(&paramLoadThread);
connect(&paramLoadThread, &QThread::finished, paramLoader, &QObject::deleteLater);
connect(this, &QGCMapRCToParamDialog::refreshParam, paramLoader, &ParamLoader::load);
connect(paramLoader, &ParamLoader::paramLoaded, this, &QGCMapRCToParamDialog::paramLoaded);
paramLoadThread.start();
emit refreshParam();
// refresh the parameter from onboard to make sure the current value is used
AutoPilotPlugin* autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(mav).data();
Q_ASSERT(autopilot);
connect(autopilot->getParameterFact(FactSystem::defaultComponentId, param_id), &Fact::valueChanged, this, &QGCMapRCToParamDialog::_parameterUpdated);
autopilot->refreshParameter(FactSystem::defaultComponentId, param_id);
}
QGCMapRCToParamDialog::~QGCMapRCToParamDialog()
......@@ -77,45 +71,15 @@ void QGCMapRCToParamDialog::accept() {
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 + ")");
}
}
ParamLoader::ParamLoader(QString paramName, UASInterface* uas, QObject* parent) :
QObject(parent),
_uas(uas),
_paramName(paramName),
_paramReceived(false)
{
_autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uas).data();
Q_ASSERT(_autopilot);
}
void ParamLoader::load()
{
connect(_autopilot->getParameterFact(FactSystem::defaultComponentId, _paramName), &Fact::valueChanged, this, &ParamLoader::_parameterUpdated);
// refresh the parameter from onboard to make sure the current value is used
_autopilot->refreshParameter(FactSystem::defaultComponentId, _paramName);
}
void ParamLoader::_parameterUpdated(QVariant value)
void QGCMapRCToParamDialog::_parameterUpdated(QVariant value)
{
Q_UNUSED(value);
emit paramLoaded(true, _autopilot->getParameterFact(FactSystem::defaultComponentId, _paramName)->value().toFloat(), "");
ui->infoLabel->setText("Parameter value is up to date");
ui->value0DoubleSpinBox->setValue(value.toDouble());
ui->value0DoubleSpinBox->setEnabled(true);
connect(this, &QGCMapRCToParamDialog::mapRCToParamDialogResult, mav, &UASInterface::sendMapRCToParam);
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
okButton->setEnabled(true);
}
......@@ -39,29 +39,6 @@ class QGCMapRCToParamDialog;
}
class ParamLoader : public QObject
{
Q_OBJECT
public:
ParamLoader(QString paramName, UASInterface* uas, QObject* parent = NULL);
public slots:
void load();
signals:
void paramLoaded(bool success, float value, QString message = "");
void correctParameterChanged();
private slots:
void _parameterUpdated(QVariant value);
private:
UASInterface* _uas;
AutoPilotPlugin* _autopilot;
QString _paramName;
bool _paramReceived;
};
class QGCMapRCToParamDialog : public QDialog
{
......@@ -69,24 +46,24 @@ class QGCMapRCToParamDialog : public QDialog
QThread paramLoadThread;
public:
explicit QGCMapRCToParamDialog(QString param_id,
UASInterface *mav, QWidget *parent = 0);
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 slots:
void _parameterUpdated(QVariant value);
private:
Ui::QGCMapRCToParamDialog *ui;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment