Commit a24f8776 authored by lm's avatar lm

Finished param slider implementation, quite usable by now. No guarantees yet on read requests

parent a9bcf3e8
......@@ -23,10 +23,4 @@ void QGCUASParamManager::requestParameterListUpdate(int component)
}
/**
* The .. signal is emitted
*/
void QGCUASParamManager::requestParameterUpdate(int component, const QString& parameter)
{
}
......@@ -20,10 +20,7 @@ public:
/** @brief Request an update for the parameter list */
void requestParameterListUpdate(int component = 0);
/** @brief Request an update for this specific parameter */
void requestParameterUpdate(int component, const QString& parameter);
/** @brief Request list of parameters from MAV */
virtual void requestParameterList() = 0;
virtual void requestParameterUpdate(int component, const QString& parameter) = 0;
signals:
void parameterChanged(int component, QString parameter, float value);
......@@ -31,6 +28,10 @@ signals:
void parameterListUpToDate(int component);
public slots:
/** @brief Write one parameter to the MAV */
virtual void setParameter(int component, QString parameterName, float value) = 0;
/** @brief Request list of parameters from MAV */
virtual void requestParameterList() = 0;
protected:
UASInterface* mav; ///< The MAV this widget is controlling
......
......@@ -746,6 +746,15 @@ void QGCParamWidget::retransmissionGuardTick()
}
/**
* The .. signal is emitted
*/
void QGCParamWidget::requestParameterUpdate(int component, const QString& parameter)
{
}
/**
* @param component the subsystem which has the parameter
* @param parameterName name of the parameter, as delivered by the system
......
......@@ -64,6 +64,8 @@ public slots:
void addParameter(int uas, int component, QString parameterName, float value);
/** @brief Request list of parameters from MAV */
void requestParameterList();
/** @brief Request one single parameter */
void requestParameterUpdate(int component, const QString& parameter);
/** @brief Set one parameter, changes value in RAM of MAV */
void setParameter(int component, QString parameterName, float value);
/** @brief Set all parameters, changes the value in RAM of MAV */
......
......@@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout" columnstretch="100,100,50">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
......
#include <QMenu>
#include <QContextMenuEvent>
#include <QSettings>
#include <QTimer>
#include "QGCParamSlider.h"
#include "ui_QGCParamSlider.h"
......@@ -42,11 +43,16 @@ QGCParamSlider::QGCParamSlider(QWidget *parent) :
connect(ui->editSelectComponentComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectComponent(int)));
connect(ui->editSelectParamComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectParameter(int)));
connect(ui->valueSlider, SIGNAL(valueChanged(int)), this, SLOT(setSliderValue(int)));
connect(ui->valueSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setParamValue(double)));
connect(ui->editNameLabel, SIGNAL(textChanged(QString)), ui->nameLabel, SLOT(setText(QString)));
connect(ui->readButton, SIGNAL(clicked()), this, SLOT(requestParameter()));
connect(ui->editRefreshParamsButton, SIGNAL(clicked()), this, SLOT(refreshParamList()));
// Set the current UAS if present
setActiveUAS(UASManager::instance()->getActiveUAS());
// Get param value
QTimer::singleShot(1000, this, SLOT(requestParameter()));
}
QGCParamSlider::~QGCParamSlider()
......@@ -54,6 +60,16 @@ QGCParamSlider::~QGCParamSlider()
delete ui;
}
void QGCParamSlider::refreshParamList()
{
ui->editSelectParamComboBox->setEnabled(true);
ui->editSelectComponentComboBox->setEnabled(true);
if (uas)
{
uas->getParamManager()->requestParameterList();
}
}
void QGCParamSlider::setActiveUAS(UASInterface* activeUas)
{
if (activeUas)
......@@ -61,12 +77,10 @@ void QGCParamSlider::setActiveUAS(UASInterface* activeUas)
if (uas)
{
disconnect(uas, SIGNAL(parameterChanged(int,int,int,int,QString,float)), this, SLOT(setParameterValue(int,int,int,int,QString,float)));
disconnect(ui->editRefreshParamsButton, SIGNAL(clicked()), uas->getParamManager(), SLOT(requestParameterList()));
}
// Connect buttons and signals
connect(activeUas, SIGNAL(parameterChanged(int,int,int,int,QString,float)), this, SLOT(setParameterValue(int,int,int,int,QString,float)), Qt::UniqueConnection);
connect(ui->editRefreshParamsButton, SIGNAL(clicked()), activeUas->getParamManager(), SLOT(requestParameterList()), Qt::UniqueConnection);
uas = activeUas;
}
}
......@@ -79,6 +93,12 @@ void QGCParamSlider::requestParameter()
}
}
void QGCParamSlider::setParamValue(double value)
{
parameterValue = value;
ui->valueSlider->setValue(floatToScaledInt(value));
}
void QGCParamSlider::selectComponent(int componentIndex)
{
this->component = ui->editSelectComponentComboBox->itemData(componentIndex).toInt();
......@@ -139,10 +159,10 @@ void QGCParamSlider::endEditMode()
void QGCParamSlider::sendParameter()
{
if (QGCToolWidgetItem::uas)
if (uas)
{
qDebug() << "SENDING" << component << parameterName << parameterValue;
QGCToolWidgetItem::uas->setParameter(component, parameterName, parameterValue);
// Set value, param manager handles retransmission
uas->getParamManager()->setParameter(component, parameterName, parameterValue);
}
else
{
......@@ -153,8 +173,9 @@ void QGCParamSlider::sendParameter()
void QGCParamSlider::setSliderValue(int sliderValue)
{
parameterValue = scaledIntToFloat(sliderValue);
QString unit("");
ui->valueLabel->setText(QString("%1 %2").arg(parameterValue, 6, 'f', 6, ' ').arg(unit));
ui->valueSpinBox->setValue(parameterValue);
// QString unit("");
// ui->valueLabel->setText(QString("%1 %2").arg(parameterValue, 6, 'f', 6, ' ').arg(unit));
}
/**
......@@ -200,8 +221,7 @@ void QGCParamSlider::setParameterValue(int uas, int component, int paramCount, i
if (component == this->component && parameterName == this->parameterName)
{
parameterValue = value;
QString unit("");
ui->valueLabel->setText(QString("%1 %2").arg(value, 0, 'f', 3).arg(unit));
ui->valueSpinBox->setValue(value);
ui->valueSlider->setValue(floatToScaledInt(value));
}
}
......@@ -221,14 +241,14 @@ void QGCParamSlider::changeEvent(QEvent *e)
float QGCParamSlider::scaledIntToFloat(int sliderValue)
{
float result = (((double)sliderValue)/(double)scaledInt)*(ui->editMaxSpinBox->value() - ui->editMinSpinBox->value());
qDebug() << "INT TO FLOAT: CONVERTED" << sliderValue << "TO" << result;
//qDebug() << "INT TO FLOAT: CONVERTED" << sliderValue << "TO" << result;
return result;
}
int QGCParamSlider::floatToScaledInt(float value)
{
int result = ((value - ui->editMinSpinBox->value())/(ui->editMaxSpinBox->value() - ui->editMinSpinBox->value()))*scaledInt;
qDebug() << "FLOAT TO INT: CONVERTED" << value << "TO" << result << "SCALEDINT" << scaledInt;
//qDebug() << "FLOAT TO INT: CONVERTED" << value << "TO" << result << "SCALEDINT" << scaledInt;
return result;
}
......@@ -255,5 +275,6 @@ void QGCParamSlider::readSettings(const QSettings& settings)
ui->editSelectComponentComboBox->addItem(tr("Component #%1").arg(settings.value("QGC_PARAM_SLIDER_COMPONENTID").toInt()), settings.value("QGC_PARAM_SLIDER_COMPONENTID").toInt());
ui->editMinSpinBox->setValue(settings.value("QGC_PARAM_SLIDER_MIN").toFloat());
ui->editMaxSpinBox->setValue(settings.value("QGC_PARAM_SLIDER_MAX").toFloat());
qDebug() << "DONE READING SETTINGS";
ui->editSelectParamComboBox->setEnabled(true);
ui->editSelectComponentComboBox->setEnabled(true);
}
......@@ -30,9 +30,11 @@ public slots:
void setParameterValue(int uas, int component, int paramCount, int paramIndex, QString parameterName, float value);
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void refreshParamList();
void setActiveUAS(UASInterface *uas);
void selectComponent(int componentIndex);
void selectParameter(int paramIndex);
void setParamValue(double value);
protected slots:
/** @brief Request the parameter of this widget from the MAV */
......
......@@ -6,29 +6,35 @@
<rect>
<x>0</x>
<y>0</y>
<width>606</width>
<width>839</width>
<height>179</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="100,0,0,0,0,0,0,0,0,0">
<item row="1" column="1" colspan="4">
<layout class="QGridLayout" name="gridLayout" columnstretch="100,0,0,0,0,0,0,0,0">
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>12</number>
</property>
<item row="1" column="1" colspan="3">
<widget class="QLineEdit" name="editNameLabel">
<property name="text">
<string>Informal Name..</string>
</property>
</widget>
</item>
<item row="1" column="5">
<item row="1" column="4">
<widget class="QLabel" name="editMinLabel">
<property name="text">
<string>Min</string>
</property>
</widget>
</item>
<item row="1" column="7">
<item row="1" column="6">
<widget class="QLabel" name="editMaxLabel">
<property name="text">
<string>Max</string>
......@@ -45,14 +51,7 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="valueLabel">
<property name="text">
<string>0.00</string>
</property>
</widget>
</item>
<item row="2" column="4" colspan="2">
<item row="2" column="3" colspan="2">
<widget class="QDoubleSpinBox" name="editMinSpinBox">
<property name="minimum">
<double>-999999999.000000000000000</double>
......@@ -62,11 +61,11 @@
</property>
</widget>
</item>
<item row="2" column="6">
<item row="2" column="5">
<widget class="QSlider" name="valueSlider">
<property name="maximumSize">
<size>
<width>300</width>
<width>250</width>
<height>16777215</height>
</size>
</property>
......@@ -78,7 +77,7 @@
</property>
</widget>
</item>
<item row="2" column="7">
<item row="2" column="6">
<widget class="QDoubleSpinBox" name="editMaxSpinBox">
<property name="minimum">
<double>-999999999.000000000000000</double>
......@@ -88,22 +87,25 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="7">
<item row="0" column="1" colspan="6">
<widget class="QLabel" name="editInstructionsLabel">
<property name="text">
<string>Please configure the parameter slider now:</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="7">
<item row="5" column="1" colspan="6">
<widget class="QLabel" name="editStatusLabel">
<property name="text">
<string>Please click first on refresh to update selection menus..</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="editSelectComponentComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Select component</string>
</property>
......@@ -112,8 +114,11 @@
</property>
</widget>
</item>
<item row="3" column="5" colspan="3">
<item row="3" column="4" colspan="3">
<widget class="QComboBox" name="editSelectParamComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Select parameter</string>
</property>
......@@ -123,24 +128,13 @@
</widget>
</item>
<item row="2" column="8">
<widget class="QPushButton" name="writeButton">
<property name="toolTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="statusTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../mavground.qrc">
<normaloff>:/images/devices/network-wireless.svg</normaloff>:/images/devices/network-wireless.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="9">
<widget class="QPushButton" name="readButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Read the current parameter value on the system</string>
</property>
......@@ -152,7 +146,7 @@
</property>
</widget>
</item>
<item row="3" column="8" colspan="2">
<item row="3" column="7" colspan="2">
<widget class="QPushButton" name="editRefreshParamsButton">
<property name="enabled">
<bool>true</bool>
......@@ -162,15 +156,22 @@
</property>
</widget>
</item>
<item row="5" column="8" colspan="2">
<item row="5" column="7" colspan="2">
<widget class="QPushButton" name="editDoneButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QDoubleSpinBox" name="valueSpinBox"/>
<item row="2" column="2">
<widget class="QDoubleSpinBox" name="valueSpinBox">
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
......@@ -185,6 +186,35 @@
</property>
</spacer>
</item>
<item row="2" column="7">
<widget class="QPushButton" name="writeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="statusTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../mavground.qrc">
<normaloff>:/images/devices/network-wireless.svg</normaloff>:/images/devices/network-wireless.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
......
......@@ -23,6 +23,7 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) :
createActions();
toolLayout = ui->toolLayout;
toolLayout->setAlignment(Qt::AlignTop);
toolLayout->setSpacing(8);
QDockWidget* dock = dynamic_cast<QDockWidget*>(this->parentWidget());
if (dock)
......
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