Skip to content

Commit

Permalink
feat: add GPS widget for GPS 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kibidev committed Nov 26, 2024
1 parent cd89f9a commit e6f68a0
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 1 deletion.
1 change: 1 addition & 0 deletions qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<file alias="ArmedIndicator.qml">src/ui/toolbar/ArmedIndicator.qml</file>
<file alias="BatteryIndicator.qml">src/ui/toolbar/BatteryIndicator.qml</file>
<file alias="GPSIndicator.qml">src/ui/toolbar/GPSIndicator.qml</file>
<file alias="GPS2Indicator.qml">src/ui/toolbar/GPS2Indicator.qml</file>
<file alias="GPSRTKIndicator.qml">src/ui/toolbar/GPSRTKIndicator.qml</file>
<file alias="JoystickIndicator.qml">src/ui/toolbar/JoystickIndicator.qml</file>
<file alias="LinkIndicator.qml">src/ui/toolbar/LinkIndicator.qml</file>
Expand Down
1 change: 1 addition & 0 deletions src/FirmwarePlugin/FirmwarePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const QVariantList& FirmwarePlugin::toolIndicators(const Vehicle*)
_toolIndicatorList = QVariantList({
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/MessageIndicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/GPSIndicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/GPS2Indicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/TelemetryRSSIIndicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/RCRSSIIndicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/ADSBVehicleIndicator.qml")),
Expand Down
1 change: 1 addition & 0 deletions src/ui/toolbar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_custom_target(UiToolbarQml
BatteryIndicator.qml
BatteryPopup.qml
GPSIndicator.qml
GPS2Indicator.qml
GPSRTKIndicator.qml
JoystickIndicator.qml
LinkIndicator.qml
Expand Down
140 changes: 140 additions & 0 deletions src/ui/toolbar/GPS2Indicator.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/

import QtQuick 2.11
import QtQuick.Layouts 1.11

import QGroundControl 1.0
import QGroundControl.Controls 1.0
import QGroundControl.MultiVehicleManager 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0

//-------------------------------------------------------------------------
//-- GPS Indicator
Item {
id: _root
width: (gps2ValuesColumn.x + gps2ValuesColumn.width) * 1.1
anchors.top: parent.top
anchors.bottom: parent.bottom

property bool showIndicator: true

property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

Component {
id: gps2Info

Rectangle {
width: gps2Col.width + ScreenTools.defaultFontPixelWidth * 3
height: gps2Col.height + ScreenTools.defaultFontPixelHeight * 2
radius: ScreenTools.defaultFontPixelHeight * 0.5
color: qgcPal.window
border.color: qgcPal.text

Column {
id: gps2Col
spacing: ScreenTools.defaultFontPixelHeight * 0.5
width: Math.max(gps2Grid.width, gps2Label.width)
anchors.margins: ScreenTools.defaultFontPixelHeight
anchors.centerIn: parent

QGCLabel {
id: gps2Label
text: (_activeVehicle && _activeVehicle.gps2.count.value >= 0) ? qsTr("GPS 2 Status") : qsTr("GPS Data 2 Unavailable")
font.family: ScreenTools.demiboldFontFamily
anchors.horizontalCenter: parent.horizontalCenter
}

GridLayout {
id: gps2Grid
visible: (_activeVehicle && _activeVehicle.gps2.count.value >= 0)
anchors.margins: ScreenTools.defaultFontPixelHeight
columnSpacing: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
columns: 2

QGCLabel { text: qsTr("GPS Count:") }
QGCLabel { text: _activeVehicle ? _activeVehicle.gps2.count.valueString : qsTr("N/A", "No data to display") }
QGCLabel { text: qsTr("GPS Lock:") }
QGCLabel { text: _activeVehicle ? _activeVehicle.gps2.lock.enumStringValue : qsTr("N/A", "No data to display") }
QGCLabel { text: qsTr("HDOP:") }
QGCLabel { text: _activeVehicle ? _activeVehicle.gps2.hdop.valueString : qsTr("--.--", "No data to display") }
QGCLabel { text: qsTr("VDOP:") }
QGCLabel { text: _activeVehicle ? _activeVehicle.gps2.vdop.valueString : qsTr("--.--", "No data to display") }
QGCLabel { text: qsTr("Course Over Ground:") }
QGCLabel { text: _activeVehicle ? _activeVehicle.gps2.courseOverGround.valueString : qsTr("--.--", "No data to display") }
}
}
}
}

QGCColoredImage {
id: gps2Icon
width: height
anchors.top: parent.top
anchors.bottom: parent.bottom
source: "/qmlimages/Gps.svg"
fillMode: Image.PreserveAspectFit
sourceSize.height: height
opacity: (_activeVehicle && _activeVehicle.gps2.count.value >= 0) ? 1 : 0.5
color: qgcPal.buttonText
}

Column {
id: gps2ValuesColumn
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: ScreenTools.defaultFontPixelWidth / 2
anchors.left: gps2Icon.right

QGCLabel {
anchors.horizontalCenter: gps2Lock.horizontalCenter
visible: _activeVehicle && _activeVehicle.gps2.count.valueString !== ""
color: qgcPal.buttonText
text: _activeVehicle ? _activeVehicle.gps2.count.valueString : ""
}

QGCLabel {
id: gps2Lock
visible: _activeVehicle && _activeVehicle.gps2.lock && _activeVehicle.gps2.lock.enumStringValue !== ""
color: getLockColor()
text: getLockText()

function getLockColor() {
if (!_activeVehicle) return qgcPal.buttonText
const lockString = _activeVehicle.gps2.lock.enumStringValue
if (lockString.includes("RTK")) return qgcPal.colorGreen
if (lockString.includes("3D")) return qgcPal.colorOrange
if (lockString.includes("2D") || lockString.includes("Static")) return qgcPal.colorBlue
if (lockString.includes("None")) return qgcPal.colorRed
return qgcPal.buttonText
}

function getLockText() {
// If it contains "RTK", we have RTK lock.
// If the lock string contains "3D" and not "RTK", we have 3D lock.
// As a pilot, I don't care if it's RTK fix or RTK Float, so we just show RTK.
if (!_activeVehicle) return ""
const lockString = _activeVehicle.gps2.lock.enumStringValue
if (lockString.includes("RTK")) return "RTK"
if (lockString.includes("3D")) return "Lock"
if (lockString.includes("2D") || lockString.includes("Static")) return "Other"
if (lockString.includes("None")) return "None"
return lockString
}
}
}

MouseArea {
anchors.fill: parent
onClicked: {
mainWindow.showIndicatorPopup(_root, gps2Info)
}
}
}
2 changes: 1 addition & 1 deletion src/ui/toolbar/GPSIndicator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Item {

QGCLabel {
id: gpsLabel
text: (_activeVehicle && _activeVehicle.gps.count.value >= 0) ? qsTr("GPS Status") : qsTr("GPS Data Unavailable")
text: (_activeVehicle && _activeVehicle.gps.count.value >= 0) ? qsTr("GPS 1 Status") : qsTr("GPS 1 Data Unavailable")
font.family: ScreenTools.demiboldFontFamily
anchors.horizontalCenter: parent.horizontalCenter
}
Expand Down

0 comments on commit e6f68a0

Please sign in to comment.