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