From ecbbfd089110e7654b8fd68bf36814882e0a9f14 Mon Sep 17 00:00:00 2001 From: Dmytro Poplavskiy Date: Sun, 20 Oct 2013 23:05:14 +1000 Subject: [PATCH] PFD view: added Warning and incomplete Info views Only GPS info is implemented --- .../share/openpilotgcs/pfd/default/Info.qml | 38 ++++++ .../share/openpilotgcs/pfd/default/Pfd.qml | 33 +++-- .../pfd/default/SvgElementImage.qml | 10 +- .../pfd/default/SvgElementPositionItem.qml | 14 +++ .../openpilotgcs/pfd/default/Warnings.qml | 115 ++++++++++++++++++ .../src/plugins/pfdqml/pfdqmlgadgetwidget.cpp | 4 +- 6 files changed, 201 insertions(+), 13 deletions(-) create mode 100644 ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml create mode 100644 ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementPositionItem.qml create mode 100644 ground/openpilotgcs/share/openpilotgcs/pfd/default/Warnings.qml diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml new file mode 100644 index 000000000..741a2ea78 --- /dev/null +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml @@ -0,0 +1,38 @@ +import Qt 4.7 + +Item { + id: info + property variant sceneSize + + SvgElementImage { + id: info_bg + elementName: "info-bg" + sceneSize: info.sceneSize + } + + Repeater { + id: satNumberBar + + // hack, qml/js treats qint8 as a char, necessary to convert it back to integer value + property int satNumber : String(GPSPositionSensor.Satellites).charCodeAt(0) + + model: 10 + SvgElementImage { + property int minSatNumber : index+1 + elementName: "gps" + minSatNumber + sceneSize: info.sceneSize + visible: satNumberBar.satNumber >= minSatNumber + } + } + + Text { + text: ["No GPS", "No Fix", "Fix2D", "Fix3D"][GPSPositionSensor.Status] + + // TODO: get coords from svg file, as soon as "gps-mode-text" text is converted to path + x: info.sceneSize.width * 0.05 + y: info.sceneSize.height * 0.006 + + font.pixelSize: info.sceneSize.height * 0.02 + color: "white" + } +} diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml index da5a360f7..18fd41c40 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml @@ -1,5 +1,4 @@ -import Qt 4.7 -import "." +import QtQuick 1.1 Rectangle { color: "#666666" @@ -14,6 +13,8 @@ Rectangle { Item { id: sceneItem + property variant viewportSize : Qt.size(width, height) + width: parent.paintedWidth height: parent.paintedHeight anchors.centerIn: parent @@ -27,13 +28,13 @@ Rectangle { HorizontCenter { id: horizontCenterItem - sceneSize: background.sceneSize + sceneSize: sceneItem.viewportSize anchors.fill: parent } RollScale { id: rollscale - sceneSize: background.sceneSize + sceneSize: sceneItem.viewportSize horizontCenter: horizontCenterItem.horizontCenter anchors.fill: parent } @@ -41,7 +42,7 @@ Rectangle { SvgElementImage { id: foreground elementName: "foreground" - sceneSize: background.sceneSize + sceneSize: sceneItem.viewportSize anchors.centerIn: parent } @@ -49,7 +50,7 @@ Rectangle { SvgElementImage { id: side_slip elementName: "sideslip" - sceneSize: background.sceneSize + sceneSize: sceneItem.viewportSize smooth: true property real sideSlip: AccelState.y @@ -70,27 +71,37 @@ Rectangle { Compass { anchors.fill: parent - sceneSize: background.sceneSize + sceneSize: sceneItem.viewportSize } SpeedScale { anchors.fill: parent - sceneSize: background.sceneSize + sceneSize: sceneItem.viewportSize } AltitudeScale { anchors.fill: parent - sceneSize: background.sourceSize + sceneSize: sceneItem.viewportSize } VsiScale { anchors.fill: parent - sceneSize: background.sourceSize + sceneSize: sceneItem.viewportSize } PfdIndicators { anchors.fill: parent - sceneSize: background.sourceSize + sceneSize: sceneItem.viewportSize + } + + Info { + anchors.fill: parent + sceneSize: sceneItem.viewportSize + } + + Warnings { + anchors.fill: parent + sceneSize: sceneItem.viewportSize } } } diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementImage.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementImage.qml index ea9d54626..2830ac941 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementImage.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementImage.qml @@ -17,7 +17,14 @@ Image { sourceSize.width: Math.round(sceneSize.width*scaledBounds.width) sourceSize.height: Math.round(sceneSize.height*scaledBounds.height) - Component.onCompleted: { + x: Math.floor(scaledBounds.x * sceneSize.width) + y: Math.floor(scaledBounds.y * sceneSize.height) + + Component.onCompleted: reloadImage() + onElementNameChanged: reloadImage() + onSceneSizeChanged: reloadImage() + + function reloadImage() { var params = "" if (hSliceCount > 1) params += "hslice="+hSlice+":"+hSliceCount+";" @@ -30,5 +37,6 @@ Image { params = "?" + params source = "image://svg/"+svgFileName+"!"+elementName+params + scaledBounds = svgRenderer.scaledElementBounds(svgFileName, elementName) } } diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementPositionItem.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementPositionItem.qml new file mode 100644 index 000000000..fc1d81cb6 --- /dev/null +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementPositionItem.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +Item { + id: sceneItem + property variant sceneSize + property string elementName + property string svgFileName: "pfd.svg" + property variant scaledBounds: svgRenderer.scaledElementBounds(svgFileName, elementName) + + x: Math.floor(scaledBounds.x * sceneSize.width) + y: Math.floor(scaledBounds.y * sceneSize.height) + width: Math.floor(scaledBounds.width * sceneSize.width) + height: Math.floor(scaledBounds.height * sceneSize.height) +} diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Warnings.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Warnings.qml new file mode 100644 index 000000000..12af0d24b --- /dev/null +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Warnings.qml @@ -0,0 +1,115 @@ +import Qt 4.7 + +Item { + id: warnings + property variant sceneSize + // Uninitialised, OK, Warning, Error, Critical + property variant statusColors : ["gray", "green", "red", "red", "red"] + + SvgElementImage { + id: warning_bg + elementName: "warnings-bg" + sceneSize: warnings.sceneSize + } + + SvgElementPositionItem { + id: warning_rc_input + sceneSize: parent.sceneSize + elementName: "warning-rc-input" + + Rectangle { + anchors.fill: parent + color: warnings.statusColors[SystemAlarms.Alarm_ManualControl] + + Text { + anchors.centerIn: parent + text: "RC INPUT" + font { + family: "Arial" + pixelSize: parent.height * 0.8 + weight: Font.DemiBold + } + } + } + } + + SvgElementPositionItem { + id: warning_master_caution + sceneSize: parent.sceneSize + elementName: "warning-master-caution" + + property bool warningActive: (SystemAlarms.Alarm_BootFault > 1 || + SystemAlarms.Alarm_OutOfMemory > 1 || + SystemAlarms.Alarm_StackOverflow > 1 || + SystemAlarms.Alarm_CPUOverload > 1 || + SystemAlarms.Alarm_EventSystem > 1) + Rectangle { + anchors.fill: parent + color: parent.warningActive ? "red" : "red" + opacity: parent.warningActive ? 1.0 : 0.15 + + Text { + anchors.centerIn: parent + text: "MASTER CAUTION" + font { + family: "Arial" + pixelSize: parent.height * 0.8 + weight: Font.DemiBold + } + } + } + } + + SvgElementPositionItem { + id: warning_autopilot + sceneSize: parent.sceneSize + elementName: "warning-autopilot" + + Rectangle { + anchors.fill: parent + color: warnings.statusColors[SystemAlarms.Alarm_Guidance] + + Text { + anchors.centerIn: parent + text: "AUTOPILOT" + font { + family: "Arial" + pixelSize: parent.height * 0.8 + weight: Font.DemiBold + } + } + } + } + + SvgElementImage { + id: warning_gps + elementName: "warning-gps" + sceneSize: warnings.sceneSize + + visible: SystemAlarms.Alarm_GPS > 1 + } + + SvgElementImage { + id: warning_telemetry + elementName: "warning-telemetry" + sceneSize: warnings.sceneSize + + visible: SystemAlarms.Alarm_Telemetry > 1 + } + + SvgElementImage { + id: warning_battery + elementName: "warning-battery" + sceneSize: warnings.sceneSize + + visible: SystemAlarms.Alarm_Battery > 1 + } + + SvgElementImage { + id: warning_attitude + elementName: "warning-attitude" + sceneSize: warnings.sceneSize + + visible: SystemAlarms.Alarm_Attitude > 1 + } +} diff --git a/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp index b6f74962c..bf6a74c08 100644 --- a/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp @@ -53,7 +53,8 @@ PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWidget *parent) : // setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); QStringList objectsToExport; - objectsToExport << "VelocityState" << + objectsToExport << + "VelocityState" << "PositionState" << "AttitudeState" << "AccelState" << @@ -62,6 +63,7 @@ PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWidget *parent) : "AltitudeHoldDesired" << "GPSPositionSensor" << "GCSTelemetryStats" << + "SystemAlarms" << "FlightBatteryState"; ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();