2013-04-05 22:46:56 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file gpsdisplaywidget.cpp
|
|
|
|
* @author Edouard Lafargue Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup GPSGadgetPlugin GPS Gadget Plugin
|
|
|
|
* @{
|
2013-05-19 16:37:30 +02:00
|
|
|
* @brief A gadget that displays GPS status and enables basic configuration
|
2013-04-05 22:46:56 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gpsdisplaywidget.h"
|
|
|
|
#include "extensionsystem/pluginmanager.h"
|
|
|
|
#include "uavobjectmanager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <QtGui>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the widget
|
|
|
|
*/
|
|
|
|
GpsDisplayWidget::GpsDisplayWidget(QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
// Not elegant, just load the image for now
|
2013-04-05 22:46:56 +02:00
|
|
|
QGraphicsScene *fescene = new QGraphicsScene(this);
|
2013-05-19 16:37:30 +02:00
|
|
|
QPixmap earthpix(":/gpsgadget/images/flatEarth.png");
|
|
|
|
fescene->addPixmap(earthpix);
|
2013-04-05 22:46:56 +02:00
|
|
|
flatEarth->setScene(fescene);
|
|
|
|
marker = new QGraphicsSvgItem();
|
|
|
|
QSvgRenderer *renderer = new QSvgRenderer();
|
|
|
|
renderer->load(QString(":/gpsgadget/images/marker.svg"));
|
|
|
|
marker->setSharedRenderer(renderer);
|
|
|
|
fescene->addItem(marker);
|
2013-05-19 16:37:30 +02:00
|
|
|
double scale = earthpix.width() / (marker->boundingRect().width() * 20);
|
2013-04-05 22:46:56 +02:00
|
|
|
marker->setScale(scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
GpsDisplayWidget::~GpsDisplayWidget()
|
2013-05-19 16:37:30 +02:00
|
|
|
{}
|
2013-04-05 22:46:56 +02:00
|
|
|
|
|
|
|
void GpsDisplayWidget::setSpeedHeading(double speed, double heading)
|
|
|
|
{
|
|
|
|
QString str;
|
2013-05-19 16:37:30 +02:00
|
|
|
|
|
|
|
speed_value->setText(str.sprintf("%.02f m/s", speed));
|
|
|
|
bear_value->setText(str.sprintf("%.02f deg", heading));
|
2013-04-05 22:46:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::setDateTime(double date, double time)
|
|
|
|
{
|
2013-05-19 16:37:30 +02:00
|
|
|
QString dstring1, dstring2;
|
|
|
|
|
|
|
|
dstring1.sprintf("%06.0f", date);
|
|
|
|
dstring1.insert(dstring1.length() - 2, ".");
|
|
|
|
dstring1.insert(dstring1.length() - 5, ".");
|
|
|
|
dstring2.sprintf("%06.0f", time);
|
|
|
|
dstring2.insert(dstring2.length() - 2, ":");
|
|
|
|
dstring2.insert(dstring2.length() - 5, ":");
|
2013-04-05 22:46:56 +02:00
|
|
|
time_value->setText(dstring1 + " " + dstring2 + " GMT");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::setFixType(const QString &fixtype)
|
|
|
|
{
|
2013-05-19 16:37:30 +02:00
|
|
|
if (fixtype == "NoGPS") {
|
2013-04-05 22:46:56 +02:00
|
|
|
fix_value->setText("No GPS");
|
|
|
|
} else if (fixtype == "NoFix") {
|
|
|
|
fix_value->setText("Fix not available");
|
|
|
|
} else if (fixtype == "Fix2D") {
|
|
|
|
fix_value->setText("2D");
|
2013-05-19 16:37:30 +02:00
|
|
|
} else if (fixtype == "Fix3D") {
|
2013-04-05 22:46:56 +02:00
|
|
|
fix_value->setText("3D");
|
|
|
|
} else {
|
|
|
|
fix_value->setText("Unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::dumpPacket(const QString &packet)
|
|
|
|
{
|
|
|
|
textBrowser->append(packet);
|
2013-05-19 16:37:30 +02:00
|
|
|
if (textBrowser->document()->lineCount() > 200) {
|
2013-04-05 22:46:56 +02:00
|
|
|
QTextCursor tc = textBrowser->textCursor();
|
|
|
|
tc.movePosition(QTextCursor::Start);
|
|
|
|
tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
|
|
|
|
tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
|
|
|
|
tc.removeSelectedText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::setSVs(int sv)
|
|
|
|
{
|
|
|
|
QString temp;
|
2013-05-19 16:37:30 +02:00
|
|
|
|
2013-04-05 22:46:56 +02:00
|
|
|
temp.append(QString::number(sv));
|
|
|
|
status_value->setText(temp);
|
|
|
|
status_value->adjustSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::setDOP(double hdop, double vdop, double pdop)
|
|
|
|
{
|
|
|
|
QString str;
|
2013-05-19 16:37:30 +02:00
|
|
|
|
2013-04-05 22:46:56 +02:00
|
|
|
str.sprintf("%.2f / %.2f / %.2f", hdop, vdop, pdop);
|
|
|
|
dop_value->setText(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::setPosition(double lat, double lon, double alt)
|
|
|
|
{
|
2013-05-19 16:37:30 +02:00
|
|
|
// lat *= 1E-7;
|
|
|
|
// lon *= 1E-7;
|
2013-04-05 22:46:56 +02:00
|
|
|
double deg = floor(fabs(lat));
|
2013-05-19 16:37:30 +02:00
|
|
|
double min = (fabs(lat) - deg) * 60;
|
2013-04-05 22:46:56 +02:00
|
|
|
QString str1;
|
2013-05-19 16:37:30 +02:00
|
|
|
|
|
|
|
str1.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
|
|
|
|
if (lat > 0) {
|
2013-04-05 22:46:56 +02:00
|
|
|
str1.append("N");
|
2013-05-19 16:37:30 +02:00
|
|
|
} else {
|
2013-04-05 22:46:56 +02:00
|
|
|
str1.append("S");
|
2013-05-19 16:37:30 +02:00
|
|
|
}
|
2013-04-05 22:46:56 +02:00
|
|
|
coord_value->setText(str1);
|
|
|
|
deg = floor(fabs(lon));
|
2013-05-19 16:37:30 +02:00
|
|
|
min = (fabs(lon) - deg) * 60;
|
2013-04-05 22:46:56 +02:00
|
|
|
QString str2;
|
2013-05-19 16:37:30 +02:00
|
|
|
str2.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
|
|
|
|
if (lon > 0) {
|
2013-04-05 22:46:56 +02:00
|
|
|
str2.append("E");
|
2013-05-19 16:37:30 +02:00
|
|
|
} else {
|
2013-04-05 22:46:56 +02:00
|
|
|
str2.append("W");
|
2013-05-19 16:37:30 +02:00
|
|
|
}
|
2013-04-05 22:46:56 +02:00
|
|
|
coord_value_2->setText(str2);
|
|
|
|
QString str3;
|
|
|
|
str3.sprintf("%.2f m", alt);
|
|
|
|
coord_value_3->setText(str3);
|
|
|
|
|
|
|
|
// Now place the marker:
|
2013-05-19 16:37:30 +02:00
|
|
|
double wscale = flatEarth->sceneRect().width() / 360;
|
|
|
|
double hscale = flatEarth->sceneRect().height() / 180;
|
|
|
|
QPointF opd = QPointF((lon + 180) * wscale - marker->boundingRect().width() * marker->scale() / 2,
|
|
|
|
(90 - lat) * hscale - marker->boundingRect().height() * marker->scale() / 2);
|
|
|
|
marker->setTransform(QTransform::fromTranslate(opd.x(), opd.y()), false);
|
2013-04-05 22:46:56 +02:00
|
|
|
}
|