AirspeedConfig.cc 2.57 KB
Newer Older
1
#include "AirspeedConfig.h"
2
#include <QMessageBox>
3

4
AirspeedConfig::AirspeedConfig(QWidget *parent) : AP2ConfigWidget(parent)
5 6
{
    ui.setupUi(this);
7 8
    connect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(enableCheckBoxClicked(bool)));
    connect(ui.useAirspeedCheckBox,SIGNAL(toggled(bool)),this,SLOT(useCheckBoxClicked(bool)));
9
    initConnections();
10 11 12 13 14
}

AirspeedConfig::~AirspeedConfig()
{
}
15 16
void AirspeedConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
17 18 19
    Q_UNUSED(uas);
    Q_UNUSED(component);
    
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    if (parameterName == "ARSPD_ENABLE")
    {
        if (value.toInt() == 0)
        {
            disconnect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(enableCheckBoxClicked(bool)));
            ui.enableCheckBox->setChecked(false);
            connect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(enableCheckBoxClicked(bool)));
            ui.useAirspeedCheckBox->setEnabled(false);
        }
        else
        {
            disconnect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(enableCheckBoxClicked(bool)));
            ui.enableCheckBox->setChecked(true);
            connect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(enableCheckBoxClicked(bool)));
            ui.useAirspeedCheckBox->setEnabled(true);
        }
    }
    else if (parameterName == "ARSPD_USE")
    {
        if (value.toInt() == 0)
        {
            disconnect(ui.useAirspeedCheckBox,SIGNAL(toggled(bool)),this,SLOT(useCheckBoxClicked(bool)));
            ui.useAirspeedCheckBox->setChecked(false);
            connect(ui.useAirspeedCheckBox,SIGNAL(toggled(bool)),this,SLOT(useCheckBoxClicked(bool)));
        }
        else
        {
            disconnect(ui.useAirspeedCheckBox,SIGNAL(toggled(bool)),this,SLOT(useCheckBoxClicked(bool)));
            ui.useAirspeedCheckBox->setChecked(true);
            connect(ui.useAirspeedCheckBox,SIGNAL(toggled(bool)),this,SLOT(useCheckBoxClicked(bool)));
        }
    }
}

void AirspeedConfig::useCheckBoxClicked(bool checked)
{
    if (!m_uas)
    {
58
        showNullMAVErrorMessageBox();
59 60 61 62
        return;
    }
    if (checked)
    {
63
        m_uas->getParamManager()->setParameter(1,"ARSPD_USE",1);
64 65 66
    }
    else
    {
67
        m_uas->getParamManager()->setParameter(1,"ARSPD_USE",0);
68 69 70 71 72 73 74
    }
}

void AirspeedConfig::enableCheckBoxClicked(bool checked)
{
    if (!m_uas)
    {
75
        showNullMAVErrorMessageBox();
76 77 78 79
        return;
    }
    if (checked)
    {
80
        m_uas->getParamManager()->setParameter(1,"ARSPD_ENABLE",1);
81 82 83
    }
    else
    {
84
        m_uas->getParamManager()->setParameter(1,"ARSPD_ENABLE",0);
85 86
    }
}