Skip to content
ParameterInterface.cc 3.12 KiB
Newer Older
pixhawk's avatar
pixhawk committed
#include "ParameterInterface.h"
pixhawk's avatar
pixhawk committed
#include "UASManager.h"
#include "ui_ParameterInterface.h"

pixhawk's avatar
pixhawk committed
ParameterInterface::ParameterInterface(QWidget *parent) :
pixhawk's avatar
pixhawk committed
        paramWidgets(new QMap<int, QGCParamWidget*>()),
        curr(-1),
pixhawk's avatar
pixhawk committed
{
    m_ui->setupUi(this);
pixhawk's avatar
pixhawk committed
    // Setup UI connections
    connect(m_ui->vehicleComboBox, SIGNAL(activated(int)), this, SLOT(selectUAS(int)));
    connect(m_ui->readParamsButton, SIGNAL(clicked()), this, SLOT(requestParameterList()));
pixhawk's avatar
pixhawk committed
    // Setup MAV connections
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*)));
pixhawk's avatar
pixhawk committed
}

ParameterInterface::~ParameterInterface()
{
    delete m_ui;
}

pixhawk's avatar
pixhawk committed
void ParameterInterface::selectUAS(int index)
{
    m_ui->stackedWidget->setCurrentIndex(index);
    curr = index;
}

pixhawk's avatar
pixhawk committed
/**
 *
 * @param uas System to add to list
 */
void ParameterInterface::addUAS(UASInterface* uas)
{
    m_ui->vehicleComboBox->addItem(uas->getUASName());
pixhawk's avatar
pixhawk committed
    QGCParamWidget* param = new QGCParamWidget(uas, this);
    paramWidgets->insert(uas->getUASID(), param);
    m_ui->stackedWidget->addWidget(param);
    if (curr == -1)
    {
        m_ui->stackedWidget->setCurrentWidget(param);
        curr = uas->getUASID();
        qDebug() << "first widget";
    }
pixhawk's avatar
pixhawk committed
    connect(uas, SIGNAL(parameterChanged(int,int,QString,float)), this, SLOT(addParameter(int,int,QString,float)));
pixhawk's avatar
pixhawk committed
}

void ParameterInterface::requestParameterList()
{
pixhawk's avatar
pixhawk committed
    UASInterface* mav;
    QGCParamWidget* widget = paramWidgets->value(curr);
    if (widget != NULL)
    {
        mav = widget->getUAS();
        mav->requestParameters();
        // Clear view
        widget->clear();
    }
pixhawk's avatar
pixhawk committed
/**
 *
 * @param uas System which has the component
 * @param component id of the component
 * @param componentName human friendly name of the component
 */
void ParameterInterface::addComponent(int uas, int component, QString componentName)
pixhawk's avatar
pixhawk committed
{
pixhawk's avatar
pixhawk committed
    QGCParamWidget* widget = paramWidgets->value(uas);
    if (widget != NULL)
    {
        widget->addComponent(component, componentName);
    }
pixhawk's avatar
pixhawk committed
}

pixhawk's avatar
pixhawk committed
void ParameterInterface::addParameter(int uas, int component, QString parameterName, float value)
pixhawk's avatar
pixhawk committed
{
pixhawk's avatar
pixhawk committed
    QGCParamWidget* widget = paramWidgets->value(uas);
    if (widget != NULL)
pixhawk's avatar
pixhawk committed
        widget->addParameter(component, parameterName, value);
pixhawk's avatar
pixhawk committed
}

/**
 * @param uas system
 * @param component the subsystem which has the parameter
 * @param parameterName name of the parameter, as delivered by the system
 * @param value value of the parameter
 */
void ParameterInterface::setParameter(UASInterface* uas, int component, QString parameterName, float value)
{
pixhawk's avatar
pixhawk committed
}

/**
 * @param
 */
void ParameterInterface::commitParameter(UASInterface* uas, int component, QString parameterName, float value)
{

}

pixhawk's avatar
pixhawk committed
/*
void ParameterInterface::commitParameters(UASInterface* uas)
{

}*/

pixhawk's avatar
pixhawk committed
/**
 *
 */


void ParameterInterface::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}