SonarConfig.cc 2.48 KB
Newer Older
1
#include "SonarConfig.h"
2
#include <QMessageBox>
3

4
SonarConfig::SonarConfig(QWidget *parent) : AP2ConfigWidget(parent)
5 6
{
    ui.setupUi(this);
7 8 9 10
    ui.sonarTypeComboBox->addItem("XL-EZ0 / XL-EZ4");
    ui.sonarTypeComboBox->addItem("LV-EZ0");
    ui.sonarTypeComboBox->addItem("XL-EZL0");
    ui.sonarTypeComboBox->addItem("HRLV");
11 12
    connect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(checkBoxToggled(bool)));
    connect(ui.sonarTypeComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(sonarTypeChanged(int)));
13 14

    initConnections();
15 16 17 18 19
}

SonarConfig::~SonarConfig()
{
}
20 21 22 23 24 25 26 27 28 29 30
void SonarConfig::checkBoxToggled(bool enabled)
{
    if (enabled)
    {
        ui.sonarTypeComboBox->setEnabled(false);
    }
    if (!m_uas)
    {
        QMessageBox::information(0,tr("Error"),tr("Please connect to a MAV before attempting to set configuration"));
        return;
    }
31
    m_uas->getParamManager()->setParameter(1,"SONAR_ENABLE",ui.enableCheckBox->isChecked() ? 1 : 0);
32 33 34
}
void SonarConfig::sonarTypeChanged(int index)
{
35 36
    Q_UNUSED(index);
    
37 38 39 40 41
    if (!m_uas)
    {
        QMessageBox::information(0,tr("Error"),tr("Please connect to a MAV before attempting to set configuration"));
        return;
    }
42
    m_uas->getParamManager()->setParameter(1,"SONAR_TYPE",ui.sonarTypeComboBox->currentIndex());
43 44 45 46
}

void SonarConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
47 48 49
    Q_UNUSED(uas);
    Q_UNUSED(component);
    
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    if (parameterName == "SONAR_ENABLE")
    {
        if (value.toInt() == 0)
        {
            //Disabled
            disconnect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(checkBoxToggled(bool)));
            ui.enableCheckBox->setChecked(false);
            connect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(checkBoxToggled(bool)));
            ui.sonarTypeComboBox->setEnabled(false);
        }
        else
        {
            disconnect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(checkBoxToggled(bool)));
            ui.enableCheckBox->setChecked(true);
            connect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(checkBoxToggled(bool)));
            ui.sonarTypeComboBox->setEnabled(true);
        }
    }
    else if (parameterName == "SONAR_TYPE")
    {
        disconnect(ui.sonarTypeComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(sonarTypeChanged(int)));
        ui.sonarTypeComboBox->setCurrentIndex(value.toInt());
        connect(ui.sonarTypeComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(sonarTypeChanged(int)));
    }
}