diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index f44bfb65ee7cfb59eb0a0543d11a93bc957d2924..a14e67f1e8267ba283c98eaee55536e01d692b7d 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -2026,15 +2026,13 @@ QImage UAS::getImage() // RAW greyscale if (imageType == MAVLINK_DATA_STREAM_IMG_RAW8U) { - // TODO FIXME - int imgColors = 255;//imageSize/(imageWidth*imageHeight); - //const int headerSize = 15; + int imgColors = 255; // Construct PGM header QString header("P5\n%1 %2\n%3\n"); header = header.arg(imageWidth).arg(imageHeight).arg(imgColors); - QByteArray tmpImage(header.toStdString().c_str(), header.toStdString().size()); + QByteArray tmpImage(header.toStdString().c_str(), header.toStdString().size() - 1); tmpImage.append(imageRecBuffer); //qDebug() << "IMAGE SIZE:" << tmpImage.size() << "HEADER SIZE: (15):" << header.size() << "HEADER: " << header; @@ -2047,7 +2045,7 @@ QImage UAS::getImage() if (!image.loadFromData(tmpImage, "PGM")) { - qDebug()<< "could not create extracted image"; + qDebug()<< __FILE__ << __LINE__ << "could not create extracted image"; return QImage(); } @@ -2060,7 +2058,7 @@ QImage UAS::getImage() { if (!image.loadFromData(imageRecBuffer)) { - qDebug() << "Loading data from image buffer failed!"; + qDebug() << __FILE__ << __LINE__ << "Loading data from image buffer failed!"; } } // Restart statemachine diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 815224445ec963eab489681448aa848e02fffde0..60709c1a33b634f4678116d8d2c970e00caa0b32 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project #include #include #include +#include #include #include @@ -43,14 +44,8 @@ This file is part of the QGROUNDCONTROL project #include "UASManager.h" #include "UAS.h" #include "HUD.h" -#include "MG.h" #include "QGC.h" -// Fix for some platforms, e.g. windows -#ifndef GL_MULTISAMPLE -#define GL_MULTISAMPLE 0x809D -#endif - /** * @warning The HUD widget will not start painting its content automatically * to update the view, start the auto-update by calling HUD::start(). @@ -60,7 +55,7 @@ This file is part of the QGROUNDCONTROL project * @param parent */ HUD::HUD(int width, int height, QWidget* parent) - : QWidget(parent), + : QLabel(parent), uas(NULL), yawInt(0.0f), mode(tr("UNKNOWN MODE")), @@ -119,22 +114,14 @@ HUD::HUD(int width, int height, QWidget* parent) load(0.0f), offlineDirectory(""), nextOfflineImage(""), - HUDInstrumentsEnabled(true), + HUDInstrumentsEnabled(false), videoEnabled(true), xImageFactor(1.0), yImageFactor(1.0), imageRequested(false), - imageLoggingEnabled(false) + imageLoggingEnabled(false), + image(NULL) { - // Set auto fill to false - setAutoFillBackground(false); - - // Set minimum size - setMinimumSize(80, 60); - // Set preferred size - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - scalingFactor = this->width()/vwidth; - // Fill with black background QImage fill = QImage(width, height, QImage::Format_Indexed8); fill.setNumColors(3); @@ -142,27 +129,23 @@ HUD::HUD(int width, int height, QWidget* parent) fill.setColor(1, qRgb(0, 0, 0)); fill.setColor(2, qRgb(0, 0, 0)); fill.fill(0); + glImage = fill; - //QString imagePath = "/Users/user/Desktop/frame0000.png"; - //qDebug() << __FILE__ << __LINE__ << "template image:" << imagePath; - //fill = QImage(imagePath); + // Set auto fill to false + setAutoFillBackground(false); - glImage = fill; + // Set minimum size + setMinimumSize(80, 60); + // Set preferred size + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + scalingFactor = this->width()/vwidth; // Refresh timer refreshTimer->setInterval(updateInterval); - connect(refreshTimer, SIGNAL(timeout()), this, SLOT(paintHUD())); + connect(refreshTimer, SIGNAL(timeout()), this, SLOT(repaint())); // Resize to correct size and fill with image QWidget::resize(this->width(), this->height()); - //glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); - - // Set size once - //setFixedSize(fill.size()); - //setMinimumSize(fill.size()); - //setMaximumSize(fill.size()); - // Lock down the size - //setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); fontDatabase = QFontDatabase(); const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app @@ -502,10 +485,8 @@ void HUD::paintRollPitchStrips() void HUD::paintEvent(QPaintEvent *event) { - // Event is not needed - // the event is ignored as this widget - // is refreshed automatically - Q_UNUSED(event); + + paintHUD(); } void HUD::paintHUD() @@ -586,6 +567,13 @@ void HUD::paintHUD() } + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + QPixmap pmap = QPixmap::fromImage(glImage).scaledToWidth(width()); + painter.drawPixmap(0, (height() - pmap.height()) / 2, pmap); + // END OF OPENGL PAINTING if (HUDInstrumentsEnabled) { @@ -594,10 +582,7 @@ void HUD::paintHUD() // QT PAINTING //makeCurrent(); - QPainter painter; - painter.begin(this); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor); // COORDINATE FRAME IS NOW (0,0) at CENTER OF WIDGET @@ -759,13 +744,12 @@ void HUD::paintHUD() painter.rotate(-(att.x()/M_PI)* -180.0f); } - painter.end(); - } else { - QPainter painter; - painter.begin(this); - painter.end(); + } + + painter.end(); } + } @@ -1200,7 +1184,8 @@ void HUD::setImageSize(int width, int height, int depth, int channels) rawBuffer1 = (unsigned char*)malloc(rawExpectedBytes); rawBuffer2 = (unsigned char*)malloc(rawExpectedBytes); rawImage = rawBuffer1; - // TODO check if old image should be deleted + if (image) + delete image; // Set image format // 8 BIT GREYSCALE IMAGE @@ -1367,20 +1352,16 @@ void HUD::setPixels(int imgid, const unsigned char* imageData, int length, int s void HUD::copyImage() { - if (isVisible() && HUDInstrumentsEnabled) + UAS* u = dynamic_cast(this->uas); + if (u) { - //qDebug() << "HUD::copyImage()"; - UAS* u = dynamic_cast(this->uas); - if (u) - { - this->glImage = u->getImage(); + this->glImage = u->getImage(); - // Save to directory if logging is enabled - if (imageLoggingEnabled) - { - u->getImage().save(QString("%1/%2.png").arg(imageLogDirectory).arg(imageLogCounter)); - imageLogCounter++; - } + // Save to directory if logging is enabled + if (imageLoggingEnabled) + { + u->getImage().save(QString("%1/%2.png").arg(imageLogDirectory).arg(imageLogCounter)); + imageLogCounter++; } } } diff --git a/src/ui/HUD.h b/src/ui/HUD.h index 8352e6c1ba7945fcf5746d99bb08c9228049df4b..d38b8d135e2b9af389ef462bf729cc8c0d7d1539 100644 --- a/src/ui/HUD.h +++ b/src/ui/HUD.h @@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project #include #include +#include #include #include #include @@ -47,7 +48,7 @@ This file is part of the QGROUNDCONTROL project * It can superimpose the HUD over the current live image stream (any arriving image stream will be auto- * matically used as background), or it draws the classic blue-brown background known from instruments. */ -class HUD : public QWidget +class HUD : public QLabel { Q_OBJECT public: @@ -139,7 +140,7 @@ protected: void contextMenuEvent (QContextMenuEvent* event); void createActions(); - static const int updateInterval = 40; + static const int updateInterval = 100; QImage* image; ///< Double buffer image QImage glImage; ///< The background / camera image diff --git a/src/ui/MAVLinkDecoder.cc b/src/ui/MAVLinkDecoder.cc index b93fa9af5a8848e9195d8793a7c3dc1a51d720d0..549da8fba19b6c8fca8ffacfc130cf6bb8097527 100644 --- a/src/ui/MAVLinkDecoder.cc +++ b/src/ui/MAVLinkDecoder.cc @@ -17,8 +17,9 @@ MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) : } // Fill filter - messageFilter.insert(MAVLINK_MSG_ID_HEARTBEAT, false); - messageFilter.insert(MAVLINK_MSG_ID_SYS_STATUS, false); + // Allow system status +// messageFilter.insert(MAVLINK_MSG_ID_HEARTBEAT, false); +// messageFilter.insert(MAVLINK_MSG_ID_SYS_STATUS, false); messageFilter.insert(MAVLINK_MSG_ID_STATUSTEXT, false); messageFilter.insert(MAVLINK_MSG_ID_COMMAND_LONG, false); messageFilter.insert(MAVLINK_MSG_ID_COMMAND_ACK, false); @@ -200,7 +201,7 @@ void MAVLinkDecoder::emitFieldValue(mavlink_message_t* msg, int fieldid, quint64 // Add field tree widget item uint8_t msgid = msg->msgid; - //if (messageFilter.contains(msgid)) return; + if (messageFilter.contains(msgid)) return; QString fieldName(messageInfo[msgid].fields[fieldid].name); QString fieldType; uint8_t* m = ((uint8_t*)(receivedMessages+msgid))+8; diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 7184ebfc4df7c23b47bf7a1ebbad7c1724934aaf..54e8d226f8403cc95759e49bd3826214efaa6fb5 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -466,11 +466,7 @@ void MainWindow::buildCommonWidgets() { pilotView = new SubMainWindow(this); pilotView->setObjectName("VIEW_FLIGHT"); - //pilotView->setCentralWidget(new HUD(320,240,this)); pilotView->setCentralWidget(new QGCMapTool(this)); - //hudWidget = new HUD(320, 240, this); - //addCentralWidget(hudWidget, tr("Head Up Display")); - //mapWidget = new QGCMapTool(this); addCentralWidget(pilotView, "Pilot"); } if (!configView) @@ -591,18 +587,9 @@ void MainWindow::buildCommonWidgets() connect(tempAction,SIGNAL(triggered(bool)),this, SLOT(showTool(bool))); } - // createDockWidget(simView,new HUD(320,240,this),tr("Head Up Display"),"HEAD_UP_DISPLAY_DOCKWIDGET",VIEW_SIMULATION,Qt::RightDockWidgetArea,this->width()/1.5); + createDockWidget(engineeringView,new HUD(320,240,this),tr("Video Downlink"),"HEAD_UP_DISPLAY_DOCKWIDGET",VIEW_ENGINEER,Qt::RightDockWidgetArea,this->width()/1.5); createDockWidget(simView,new PrimaryFlightDisplay(320,240,this),tr("Primary Flight Display"),"PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET",VIEW_SIMULATION,Qt::RightDockWidgetArea,this->width()/1.5); - //createDockWidget(pilotView,new UASListWidget(this),tr("Unmanned Systems"),"UNMANNED_SYSTEM_LIST_DOCKWIDGET",VIEW_FLIGHT,Qt::RightDockWidgetArea); -// createDockWidget(pilotView,new HUD(320,240,this),tr("Head Up Display"),"HEAD_UP_DISPLAY_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea,this->width()/1.8); - //createDockWidget(pilotView,new UASQuickView(this),tr("Quick View"),"UAS_INFO_QUICKVIEW_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea); - - //UASQuickView *quickview = new UASQuickView(this); - //quickview->addSource(mavlinkDecoder); - - - //createDockWidget(pilotView,quickview,tr("Quick View"),"UAS_INFO_QUICKVIEW_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea); createDockWidget(pilotView,new PrimaryFlightDisplay(320,240,this),tr("Primary Flight Display"),"PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea,this->width()/1.8); QGCTabbedInfoView *infoview = new QGCTabbedInfoView(this);