diff --git a/artwork/Dials/dials-master-linear.svg b/artwork/Dials/dials-master-linear.svg
index 49e9dec57..24a841da7 100644
--- a/artwork/Dials/dials-master-linear.svg
+++ b/artwork/Dials/dials-master-linear.svg
@@ -217,6 +217,13 @@
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
+
+
+
Vbat
http://www.openpilot.org
+
diff --git a/ground/src/plugins/lineardial/lineardial.pro b/ground/src/plugins/lineardial/lineardial.pro
index 9d9668219..a2fa4464a 100644
--- a/ground/src/plugins/lineardial/lineardial.pro
+++ b/ground/src/plugins/lineardial/lineardial.pro
@@ -3,7 +3,7 @@ TARGET = LineardialGadget
QT += svg
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
-include(../../libs/qwt/qwt.pri)
+include(lineardial_dependencies.pri)
HEADERS += lineardialplugin.h
HEADERS += lineardialgadget.h
HEADERS += lineardialgadgetwidget.h
diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp
index 87f2c0299..51aa9893e 100644
--- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp
+++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp
@@ -28,6 +28,9 @@
#include "lineardialgadgetoptionspage.h"
#include "lineardialgadgetconfiguration.h"
#include "ui_lineardialgadgetoptionspage.h"
+#include "extensionsystem/pluginmanager.h"
+#include "uavobjects/uavobjectmanager.h"
+#include "uavobjects/uavdataobject.h"
#include
#include
@@ -60,10 +63,36 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
options_page->redMin->setValue(m_config->getRedMin());
options_page->redMax->setValue(m_config->getRedMax());
+ // Fills the combo boxes for the UAVObjects
+ ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
+ UAVObjectManager *objManager = pm->getObject();
+ QList< QList > objList = objManager->getDataObjects();
+ foreach (QList list, objList) {
+ foreach (UAVDataObject* obj, list) {
+ options_page->objectName->addItem(obj->getName());
+ }
+ }
+ //select saved UAV Object field values
+ if(options_page->objectName->findText(m_config->getSourceDataObject())!=-1){
+ options_page->objectName->setCurrentIndex(options_page->objectName->findText(m_config->getSourceDataObject()));
+ // Now load the object field values:
+ UAVDataObject* obj = dynamic_cast( objManager->getObject(m_config->getSourceDataObject()) );
+ if (obj != NULL ) {
+ QList fieldList = obj->getFields();
+ foreach (UAVObjectField* field, fieldList) {
+ options_page->objectField->addItem(field->getName());
+ }
+ // And set the highlighed value from the settings:
+ options_page->objectField->setCurrentIndex(options_page->objectField->findText(m_config->getSourceObjectField()));
+ }
+ }
+
+ connect(options_page->objectName, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_objectName_currentIndexChanged(QString)));
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
return optionsPageWidget;
}
+
/**
* Called when the user presses apply or OK.
*
@@ -77,6 +106,8 @@ void LineardialGadgetOptionsPage::apply()
m_config->setGreenRange(options_page->greenMin->value(),options_page->greenMax->value());
m_config->setYellowRange(options_page->yellowMin->value(),options_page->yellowMax->value());
m_config->setRedRange(options_page->redMin->value(),options_page->redMax->value());
+ m_config->setSourceDataObject(options_page->objectName->currentText());
+ m_config->setSourceObjField(options_page->objectField->currentText());
}
/**
@@ -98,6 +129,20 @@ void LineardialGadgetOptionsPage::on_loadFile_clicked()
}
+/*
+ Fills in the field1 combo box when value is changed in the
+ object1 field
+*/
+void LineardialGadgetOptionsPage::on_objectName_currentIndexChanged(QString val) {
+ options_page->objectField->clear();
+ ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
+ UAVObjectManager *objManager = pm->getObject();
+ UAVDataObject* obj = dynamic_cast( objManager->getObject(val) );
+ QList fieldList = obj->getFields();
+ foreach (UAVObjectField* field, fieldList) {
+ options_page->objectField->addItem(field->getName());
+ }
+}
void LineardialGadgetOptionsPage::finish()
{
diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h
index 585ebbf01..f1582a905 100644
--- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h
+++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h
@@ -61,6 +61,8 @@ private:
private slots:
void on_loadFile_clicked();
+ void on_objectName_currentIndexChanged(QString val);
+
};
#endif // LINEARDIALGADGETOPTIONSPAGE_H
diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui
index 9ccd49c96..8e05f6e5d 100644
--- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui
+++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui
@@ -394,7 +394,14 @@
-
-
+
+
+
+ 0
+ 0
+
+
+
-
@@ -404,7 +411,14 @@
-
-
+
+
+
+ 0
+ 0
+
+
+
diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp
index 3908bea3a..ddf0ceaac 100644
--- a/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp
+++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp
@@ -44,8 +44,13 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
yellow = new QGraphicsSvgItem();
red = new QGraphicsSvgItem();
index = new QGraphicsSvgItem();
+ fieldName = new QGraphicsTextItem("Field");
+ fieldName->setDefaultTextColor(QColor("White"));
+ fieldValue = new QGraphicsTextItem("3.0 V");
+
paint();
+ obj1 = NULL;
indexTarget = 0;
indexValue = 0;
@@ -53,10 +58,12 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
dialTimer.start(30);
+#if 0
// Test code for timer to move the index
testSpeed=0;
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
m_testTimer.start(1000);
+#endif
}
LineardialGadgetWidget::~LineardialGadgetWidget()
@@ -64,11 +71,47 @@ LineardialGadgetWidget::~LineardialGadgetWidget()
// Do nothing
}
-void LineardialGadgetWidget::connectInput(QString object1, QString field1) {
+/*!
+ \brief Connects the widget to the relevant UAVObjects
+ */
+void LineardialGadgetWidget::connectInput(QString object1, QString nfield1) {
+ if (obj1 != NULL)
+ disconnect(obj1,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateIndex(UAVObject*)));
+ ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
+ UAVObjectManager *objManager = pm->getObject();
+
+ std::cout << "Lineadial Connect needles - " << object1.toStdString() << "-"<< nfield1.toStdString() << std::endl;
+
+ // Check validity of arguments first, reject empty args and unknown fields.
+ if (!(object1.isEmpty() || nfield1.isEmpty())) {
+ obj1 = dynamic_cast( objManager->getObject(object1) );
+ if (obj1 != NULL ) {
+ connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateIndex(UAVObject*)));
+ field1 = nfield1;
+ fieldName->setPlainText(nfield1);
+ } else {
+ std::cout << "Error: Object is unknown (" << object1.toStdString() << ") this should not happen." << std::endl;
+ }
+ }
}
-
+/*!
+ \brief Called by the UAVObject which got updated
+ */
+void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
+ // Double check that the field exists:
+ UAVObjectField* field = object1->getField(field1);
+ if (field) {
+ double v = field->getDouble();
+ setIndex(v);
+ QString s;
+ s.sprintf("%.2f",v);
+ fieldValue->setPlainText(s);
+ } else {
+ std::cout << "Wrong field, maybe an issue with object disconnection ?" << std::endl;
+ }
+}
void LineardialGadgetWidget::setDialFile(QString dfn)
{
@@ -83,8 +126,6 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
background->setElementId("background");
index->setSharedRenderer(m_renderer);
index->setElementId("needle");
- // TODO: transform the green, yellow & red zones
- // according to their min/max.
green->setSharedRenderer(m_renderer);
green->setElementId("green");
yellow->setSharedRenderer(m_renderer);
@@ -97,22 +138,38 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
foreground->setElementId("foreground");
fgenabled = true;
}
- std::cout<<"Dial file loaded"<matrixForElement("field");
+ startX = textMatrix.mapRect(m_renderer->boundsOnElement("field")).x();
+ startY = textMatrix.mapRect(m_renderer->boundsOnElement("field")).y();
+ QTransform matrix;
+ matrix.translate(startX,startY);
+ fieldName->setTransform(matrix,false);
+
+ textMatrix = m_renderer->matrixForElement("value");
+ startX = textMatrix.mapRect(m_renderer->boundsOnElement("field")).x();
+ startY = textMatrix.mapRect(m_renderer->boundsOnElement("field")).y();
+ matrix.reset();
+ matrix.translate(startX,startY);
+ fieldValue->setTransform(matrix,false);
+
+
// In order to properly render the Green/Yellow/Red graphs, we need to find out
// the starting location of the bargraph rendering area:
QMatrix barMatrix = m_renderer->matrixForElement("bargraph");
startX = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).x();
startY = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).y();
- std::cout << "StartX: " << startX << std::endl;
- std::cout << "StartY: " << startY << std::endl;
+ //std::cout << "StartX: " << startX << std::endl;
+ //std::cout << "StartY: " << startY << std::endl;
bargraphWidth = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).width();
indexHeight = m_renderer->matrixForElement("needle").mapRect(m_renderer->boundsOnElement("needle")).height();
indexWidth = m_renderer->matrixForElement("needle").mapRect(m_renderer->boundsOnElement("needle")).width();
- std::cout << "Index height: " << indexHeight << std::endl;
+ //std::cout << "Index height: " << indexHeight << std::endl;
- QTransform matrix;
+// QTransform matrix;
+ matrix.reset();
matrix.translate(startX-indexWidth/2,startY-indexHeight/2);
index->setTransform(matrix,false);
// Now adjust the red/yellow/green zones:
@@ -163,6 +220,7 @@ void LineardialGadgetWidget::paint()
l_scene->addItem(yellow);
l_scene->addItem(green);
l_scene->addItem(index);
+ l_scene->addItem(fieldName);
l_scene->addItem(foreground);
update();
diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.h b/ground/src/plugins/lineardial/lineardialgadgetwidget.h
index 94a48e85e..55ec2b2ed 100644
--- a/ground/src/plugins/lineardial/lineardialgadgetwidget.h
+++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.h
@@ -29,6 +29,9 @@
#define LINEARDIALGADGETWIDGET_H_
#include "lineardialgadgetconfiguration.h"
+#include "extensionsystem/pluginmanager.h"
+#include "uavobjects/uavobjectmanager.h"
+#include "uavobjects/uavobject.h"
#include
#include
#include
@@ -50,9 +53,12 @@ public:
void setYellowRange(double min, double max) {yellowMin=min; yellowMax=max;}
void setRedRange(double min, double max) {redMin=min; redMax=max;}
void connectInput(QString obj, QString field);
-
void setIndex(double val);
+public slots:
+ void updateIndex(UAVObject *object1);
+
+
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
@@ -73,6 +79,9 @@ private:
QGraphicsSvgItem *yellow;
QGraphicsSvgItem *red;
+ QGraphicsTextItem *fieldName;
+ QGraphicsTextItem *fieldValue;
+
// Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
@@ -101,6 +110,11 @@ private:
// Rotation timer
QTimer dialTimer;
+ // Name of the fields to read when an update is received:
+ UAVDataObject* obj1;
+ QString field1;
+
+
// Test variables
int testSpeed;
QTimer m_testTimer;
diff --git a/ground/src/plugins/plugins.pro b/ground/src/plugins/plugins.pro
index 762469d8b..bd90b1602 100644
--- a/ground/src/plugins/plugins.pro
+++ b/ground/src/plugins/plugins.pro
@@ -81,6 +81,7 @@ SUBDIRS += plugin_airspeed
#Linear Dial Gadget
plugin_lineardial.subdir = lineardial
plugin_lineardial.depends = plugin_coreplugin
+plugin_lineardial.depends = plugin_uavobjects
SUBDIRS += plugin_lineardial
#System health Gadget