2010-06-23 03:59:12 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file gpsdisplaywidget.cpp
|
|
|
|
* @author Edouard Lafargue Copyright (C) 2010.
|
2010-07-16 12:33:27 +02:00
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
2010-06-23 03:59:12 +02:00
|
|
|
* @{
|
2010-07-16 12:33:27 +02:00
|
|
|
* @addtogroup GPSGadgetPlugin GPS Gadget Plugin
|
|
|
|
* @{
|
|
|
|
* @brief A gadget that displays GPS status and enables basic configuration
|
2010-06-23 03:59:12 +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"
|
2010-08-18 00:07:07 +02:00
|
|
|
#include "gpsdisplaythread.h"
|
2010-06-23 03:59:12 +02:00
|
|
|
#include "ui_gpsdisplaywidget.h"
|
|
|
|
#include "extensionsystem/pluginmanager.h"
|
|
|
|
#include "uavobjects/uavobjectmanager.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
2010-08-07 11:33:12 +02:00
|
|
|
#include <QtGui>
|
2010-06-23 03:59:12 +02:00
|
|
|
#include <QDebug>
|
2010-08-06 12:18:28 +02:00
|
|
|
#include "nmeaparser.h"
|
2010-08-06 09:02:26 +02:00
|
|
|
|
|
|
|
|
2010-08-05 21:19:41 +02:00
|
|
|
|
2010-06-23 03:59:12 +02:00
|
|
|
/*
|
|
|
|
* Initialize the widget
|
|
|
|
*/
|
|
|
|
GpsDisplayWidget::GpsDisplayWidget(QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
setMinimumSize(128,128);
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
|
|
|
|
widget = new Ui_GpsDisplayWidget();
|
|
|
|
widget->setupUi(this);
|
|
|
|
|
2010-07-05 18:19:55 +02:00
|
|
|
QGraphicsScene *scene = new QGraphicsScene(this);
|
|
|
|
QSvgRenderer *renderer = new QSvgRenderer();
|
|
|
|
QGraphicsSvgItem *world = new QGraphicsSvgItem();
|
|
|
|
renderer->load(QString(":/gpsgadget/images/gpsEarth.svg"));
|
|
|
|
world->setSharedRenderer(renderer);
|
|
|
|
world->setElementId("map");
|
|
|
|
scene->addItem(world);
|
|
|
|
scene->setSceneRect(world->boundingRect());
|
|
|
|
widget->gpsWorld->setScene(scene);
|
|
|
|
// Somehow fitInView does not work there at all? Makes
|
|
|
|
// the 'world' element tiny tiny tiny. anyone knows why??
|
|
|
|
//widget->gpsWorld->fitInView(world,Qt::KeepAspectRatio);
|
|
|
|
qreal factor = widget->gpsWorld->size().height()/world->boundingRect().height();
|
|
|
|
widget->gpsWorld->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
|
|
|
world->setScale(factor);
|
|
|
|
|
2010-08-08 22:47:32 +02:00
|
|
|
//Not elegant, just load the image for now
|
|
|
|
QGraphicsScene *fescene = new QGraphicsScene(this);
|
|
|
|
QPixmap earthpix( ":/gpsgadget/images/flatEarth.png" );
|
|
|
|
fescene->addPixmap( earthpix );
|
|
|
|
widget->flatEarth->setScene(fescene);
|
|
|
|
|
2010-08-05 21:19:41 +02:00
|
|
|
connect(widget->connectButton, SIGNAL(clicked(bool)),
|
|
|
|
this,SLOT(connectButtonClicked()));
|
2010-08-07 11:33:12 +02:00
|
|
|
parser=new NMEAParser();
|
|
|
|
connect(parser,SIGNAL(sv(int)),this,SLOT(setSVs(int)));
|
|
|
|
connect(parser,SIGNAL(position(double,double,double)),this,SLOT(setPosition(double,double,double)));
|
2010-08-09 08:41:10 +02:00
|
|
|
connect(parser,SIGNAL(speedheading(double,double)),this,SLOT(setSpeedHeading(double,double)));
|
|
|
|
connect(parser,SIGNAL(datetime(double,double)),this,SLOT(setDateTime(double,double)));
|
2010-08-12 00:58:40 +02:00
|
|
|
connect(parser,SIGNAL(packet(char*)), this, SLOT(dumpPacket(char*)));
|
2010-08-07 11:33:12 +02:00
|
|
|
|
2010-08-12 00:58:40 +02:00
|
|
|
port = NULL;
|
2010-06-23 03:59:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GpsDisplayWidget::~GpsDisplayWidget()
|
|
|
|
{
|
|
|
|
delete widget;
|
|
|
|
}
|
|
|
|
|
2010-08-09 08:41:10 +02:00
|
|
|
void GpsDisplayWidget::setSpeedHeading(double speed, double heading)
|
|
|
|
{
|
|
|
|
QString temp = "Speed: ";
|
|
|
|
temp.append(QString::number(speed,'g',10));
|
|
|
|
temp.append(" Heaging: ");
|
|
|
|
temp.append(QString::number(heading,'g',10));
|
2010-08-29 01:14:31 +02:00
|
|
|
widget->speed_value->setText(QString::number(speed,'g',10));
|
|
|
|
widget->speed_value->adjustSize();
|
|
|
|
widget->bear_value->setText(QString::number(heading,'g',10));
|
|
|
|
widget->bear_value->adjustSize();
|
2010-08-09 08:41:10 +02:00
|
|
|
|
2010-08-12 00:58:40 +02:00
|
|
|
// widget->textBrowser->append(temp);
|
2010-08-09 08:41:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::setDateTime(double date, double time)
|
|
|
|
{
|
|
|
|
QString temp = "Date: ";
|
|
|
|
temp.append(QString::number(date,'g',10));
|
|
|
|
temp.append(" Time: ");
|
|
|
|
temp.append(QString::number(time,'g',10));
|
2010-08-29 01:14:31 +02:00
|
|
|
widget->gdate_value->setText(QString::number(date,'g',10));
|
|
|
|
widget->gdate_value->adjustSize();
|
|
|
|
widget->gtime_value->setText(QString::number(time,'g',10));
|
|
|
|
widget->gdate_value->adjustSize();
|
2010-08-09 08:41:10 +02:00
|
|
|
|
2010-08-12 00:58:40 +02:00
|
|
|
//widget->textBrowser->append(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::dumpPacket(char *packet)
|
|
|
|
{
|
|
|
|
widget->textBrowser->append(QString(packet));
|
2010-08-09 08:41:10 +02:00
|
|
|
}
|
|
|
|
|
2010-08-07 11:33:12 +02:00
|
|
|
void GpsDisplayWidget::setSVs(int sv)
|
|
|
|
{
|
2010-08-08 08:30:25 +02:00
|
|
|
QString temp = "Fix: Sats: ";
|
2010-08-07 11:33:12 +02:00
|
|
|
temp.append(QString::number(sv));
|
2010-08-29 01:14:31 +02:00
|
|
|
widget->status_value->setText(temp);
|
|
|
|
widget->status_value->adjustSize();
|
2010-08-07 11:33:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GpsDisplayWidget::setPosition(double lat, double lon, double alt)
|
|
|
|
{
|
|
|
|
QString temp = "Position: ";
|
2010-08-08 08:30:25 +02:00
|
|
|
temp.append(QString::number(lat,'g',10));
|
2010-08-07 11:33:12 +02:00
|
|
|
temp.append(" ");
|
2010-08-08 08:30:25 +02:00
|
|
|
temp.append(QString::number(lon,'g',10));
|
2010-08-07 11:33:12 +02:00
|
|
|
temp.append(" ");
|
2010-08-08 08:30:25 +02:00
|
|
|
temp.append(QString::number(alt,'g',10));
|
2010-08-29 01:14:31 +02:00
|
|
|
widget->lat_value->setText(QString::number(lat,'g',10));
|
|
|
|
widget->lat_value->adjustSize();
|
|
|
|
widget->long_value->setText(QString::number(lon,'g',10));
|
|
|
|
widget->long_value->adjustSize();
|
|
|
|
//widget->alt_value->setText(QString::number(alt,'g',10));
|
|
|
|
//widget->alt_value->adjustSize();
|
2010-08-09 08:41:10 +02:00
|
|
|
|
2010-08-12 00:58:40 +02:00
|
|
|
//widget->textBrowser->append(temp);
|
2010-08-07 11:33:12 +02:00
|
|
|
}
|
2010-06-23 03:59:12 +02:00
|
|
|
|
2010-08-05 21:19:41 +02:00
|
|
|
void GpsDisplayWidget::setPort(QextSerialPort* port)
|
|
|
|
{
|
|
|
|
|
|
|
|
this->port=port;
|
|
|
|
}
|
|
|
|
|
2010-08-18 02:02:32 +02:00
|
|
|
void GpsDisplayWidget::setParser(NMEAParser* parser)
|
|
|
|
{
|
|
|
|
|
|
|
|
this->parser=parser;
|
|
|
|
}
|
|
|
|
|
2010-06-23 03:59:12 +02:00
|
|
|
void GpsDisplayWidget::connectButtonClicked() {
|
2010-08-06 21:54:08 +02:00
|
|
|
GpsDisplayThread* gpsThread = new GpsDisplayThread();
|
2010-08-07 11:33:12 +02:00
|
|
|
widget->textBrowser->append(QString("Connecting to GPS ...\n"));
|
2010-08-06 21:54:08 +02:00
|
|
|
gpsThread->setPort(port);
|
2010-08-07 11:33:12 +02:00
|
|
|
gpsThread->setParser(parser);
|
2010-08-06 21:54:08 +02:00
|
|
|
gpsThread->start();
|
2010-06-23 03:59:12 +02:00
|
|
|
}
|