Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / gpsdisplay / gpsdisplaywidget.cpp
blob1f09a963b52efe3743aa05d47c25111df56ee303
1 /**
2 ******************************************************************************
4 * @file gpsdisplaywidget.cpp
5 * @author The LibrePilot Team, http://www.librepilot.org Copyright (C) 2017.
6 * Edouard Lafargue Copyright (C) 2010.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup GPSGadgetPlugin GPS Gadget Plugin
10 * @{
11 * @brief A gadget that displays GPS status and enables basic configuration
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "gpsdisplaywidget.h"
30 #include "extensionsystem/pluginmanager.h"
31 #include "uavobjectmanager.h"
34 #include <iostream>
36 // The following is needed to workaround the problem here:
37 // https://bugreports.qt-project.org/browse/QTBUG-26000
38 #undef B0
40 #include <QtGui>
41 #include <QDebug>
44 * Initialize the widget
46 GpsDisplayWidget::GpsDisplayWidget(QWidget *parent) : QWidget(parent)
48 setupUi(this);
51 GpsDisplayWidget::~GpsDisplayWidget()
54 void GpsDisplayWidget::setSpeedHeading(double speed, double heading)
56 QString str;
58 speed_value->setText(str.sprintf("%.02f m/s", speed));
59 bear_value->setText(str.sprintf("%.02f deg", heading));
62 void GpsDisplayWidget::setDateTime(double date, double time)
64 QString dstring1, dstring2;
66 dstring1.sprintf("%06.0f", date);
67 dstring1.insert(dstring1.length() - 2, ".");
68 dstring1.insert(dstring1.length() - 5, ".");
69 dstring2.sprintf("%06.0f", time);
70 dstring2.insert(dstring2.length() - 2, ":");
71 dstring2.insert(dstring2.length() - 5, ":");
72 time_value->setText(dstring1 + " " + dstring2 + " UTC");
75 void GpsDisplayWidget::setFixType(const QString &fixtype)
77 if (fixtype == "NoGPS") {
78 fix_value->setText("No GPS");
79 } else if (fixtype == "NoFix") {
80 fix_value->setText("Fix not available");
81 } else if (fixtype == "Fix2D") {
82 fix_value->setText("2D");
83 } else if (fixtype == "Fix3D") {
84 fix_value->setText("3D");
85 } else if (fixtype == "Fix3DDGNSS") {
86 fix_value->setText("3D/DGNSS");
87 } else {
88 fix_value->setText("Unknown");
92 void GpsDisplayWidget::dumpPacket(const QString &packet)
94 textBrowser->append(packet);
95 if (textBrowser->document()->lineCount() > 200) {
96 QTextCursor tc = textBrowser->textCursor();
97 tc.movePosition(QTextCursor::Start);
98 tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
99 tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
100 tc.removeSelectedText();
104 void GpsDisplayWidget::setSVs(int sv)
106 QString temp;
108 temp.append(QString::number(sv));
109 status_value->setText(temp);
112 void GpsDisplayWidget::setDOP(double hdop, double vdop, double pdop)
114 QString str;
116 str.sprintf("%.2f / %.2f / %.2f", hdop, vdop, pdop);
117 dop_value->setText(str);
120 void GpsDisplayWidget::setPosition(double lat, double lon, double alt)
122 // lat *= 1E-7;
123 // lon *= 1E-7;
124 double deg = floor(fabs(lat));
125 double min = (fabs(lat) - deg) * 60;
126 QString str1;
128 str1.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
129 if (lat > 0) {
130 str1.append("N");
131 } else {
132 str1.append("S");
134 coord_value->setText(str1);
135 deg = floor(fabs(lon));
136 min = (fabs(lon) - deg) * 60;
137 QString str2;
138 str2.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
139 if (lon > 0) {
140 str2.append("E");
141 } else {
142 str2.append("W");
144 coord_value_2->setText(str2);
145 QString str3;
146 str3.sprintf("%.2f m", alt);
147 coord_value_3->setText(str3);
149 flatEarth->setPosition(lat, lon);