QGCMapRCToParamDialog.cpp 2.64 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10 11 12 13 14 15


/// @file
///     @author Thomas Gubler <thomasgubler@gmail.com>

#include "QGCMapRCToParamDialog.h"
#include "ui_QGCMapRCToParamDialog.h"
16
#include "ParameterManager.h"
17 18 19 20 21 22 23

#include <QDebug>
#include <QTimer>
#include <QEventLoop>
#include <QShowEvent>
#include <QPushButton>

24 25 26 27 28 29
QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav, MultiVehicleManager* multiVehicleManager, QWidget *parent)
    : QDialog(parent)
    , param_id(param_id)
    , mav(mav)
    , _multiVehicleManager(multiVehicleManager)
    , ui(new Ui::QGCMapRCToParamDialog)
30 31
{
    ui->setupUi(this);
Lorenz Meier's avatar
Lorenz Meier committed
32 33

    // refresh the parameter from onboard to make sure the current value is used
34
    Vehicle* vehicle = _multiVehicleManager->getVehicleById(mav->getUASID());
35
    Fact* paramFact = vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, param_id);
36
    
Lorenz Meier's avatar
Lorenz Meier committed
37 38 39
    ui->minValueDoubleSpinBox->setValue(paramFact->rawMin().toDouble());
    ui->maxValueDoubleSpinBox->setValue(paramFact->rawMax().toDouble());

40 41 42 43 44 45
    // only enable ok button when param was refreshed
    QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
    okButton->setEnabled(false);

    ui->paramIdLabel->setText(param_id);

DonLakeFlyer's avatar
DonLakeFlyer committed
46
    connect(paramFact, &Fact::vehicleUpdated, this, &QGCMapRCToParamDialog::_parameterUpdated);
47
    vehicle->parameterManager()->refreshParameter(FactSystem::defaultComponentId, param_id);
48 49 50 51 52 53 54 55 56 57 58
}

QGCMapRCToParamDialog::~QGCMapRCToParamDialog()
{
    delete ui;
}

void QGCMapRCToParamDialog::accept() {
    emit mapRCToParamDialogResult(param_id,
            (float)ui->scaleDoubleSpinBox->value(),
            (float)ui->value0DoubleSpinBox->value(),
59 60 61
            (quint8)ui->rcParamChannelComboBox->currentIndex(),
            (float)ui->minValueDoubleSpinBox->value(),
            (float)ui->maxValueDoubleSpinBox->value());
62 63 64 65

    QDialog::accept();
}

Don Gagne's avatar
Don Gagne committed
66
void QGCMapRCToParamDialog::_parameterUpdated(QVariant value)
67
{
68
    Q_UNUSED(value);
69
    
Don Gagne's avatar
Don Gagne committed
70 71 72 73 74 75 76
    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);
77
}