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"
|
|
|
|
#include "ui_gpsdisplaywidget.h"
|
|
|
|
#include "extensionsystem/pluginmanager.h"
|
|
|
|
#include "uavobjects/uavobjectmanager.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <QtGui/QFileDialog>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2010-08-05 21:19:41 +02:00
|
|
|
|
|
|
|
class MyThread : public QThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QextSerialPort *port;
|
|
|
|
void setPort(QextSerialPort* port);
|
|
|
|
void run();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
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-05 21:19:41 +02:00
|
|
|
|
|
|
|
connect(widget->connectButton, SIGNAL(clicked(bool)),
|
|
|
|
this,SLOT(connectButtonClicked()));
|
2010-06-23 03:59:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GpsDisplayWidget::~GpsDisplayWidget()
|
|
|
|
{
|
|
|
|
delete widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-05 21:19:41 +02:00
|
|
|
void GpsDisplayWidget::setPort(QextSerialPort* port)
|
|
|
|
{
|
|
|
|
|
|
|
|
this->port=port;
|
|
|
|
}
|
|
|
|
|
2010-06-23 03:59:12 +02:00
|
|
|
void GpsDisplayWidget::connectButtonClicked() {
|
2010-08-05 21:19:41 +02:00
|
|
|
MyThread* myThread = new MyThread();
|
|
|
|
myThread->setPort(port);
|
|
|
|
myThread->start();
|
2010-06-23 03:59:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-05 21:19:41 +02:00
|
|
|
void MyThread::setPort(QextSerialPort* port)
|
|
|
|
{
|
|
|
|
|
|
|
|
this->port=port;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyThread::run()
|
|
|
|
{
|
|
|
|
qDebug() << "Opening.";
|
|
|
|
|
|
|
|
qDebug() << port->portName();
|
|
|
|
|
|
|
|
bool isOpen = port->open(QIODevice::ReadWrite);
|
|
|
|
qDebug() << "Open: " << isOpen;
|
|
|
|
|
|
|
|
char buf[1024];
|
|
|
|
while(true) {
|
|
|
|
qDebug() << "Reading.";
|
|
|
|
qint64 bytesRead = port->readLine(buf, sizeof(buf));
|
|
|
|
qDebug() << "bytesRead: " << bytesRead;
|
|
|
|
if (bytesRead != -1) {
|
|
|
|
qDebug() << "Result: '" << buf << "'";
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 03:59:12 +02:00
|
|
|
|