From 7bb043247c590658fa70f836d9d8d5e9ca92a792 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 13 Apr 2016 10:22:38 -0700 Subject: [PATCH] New RCChannelMonitorControl --- qgroundcontrol.pro | 2 + qgroundcontrol.qrc | 1 + .../Common/RadioComponent.qml | 48 +----- .../PX4/PX4SimpleFlightModes.qml | 14 +- src/QGCApplication.cc | 2 + .../QGroundControl.Controls.qmldir | 1 + src/QmlControls/RCChannelMonitor.qml | 151 ++++++++++++++++++ src/QmlControls/RCChannelMonitorController.cc | 53 ++++++ src/QmlControls/RCChannelMonitorController.h | 61 +++++++ 9 files changed, 283 insertions(+), 50 deletions(-) create mode 100644 src/QmlControls/RCChannelMonitor.qml create mode 100644 src/QmlControls/RCChannelMonitorController.cc create mode 100644 src/QmlControls/RCChannelMonitorController.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 5c5116309..b70078105 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -295,6 +295,7 @@ HEADERS += \ src/QmlControls/CoordinateVector.h \ src/QmlControls/MavlinkQmlSingleton.h \ src/QmlControls/ParameterEditorController.h \ + src/QmlControls/RCChannelMonitorController.h \ src/QmlControls/ScreenToolsController.h \ src/QmlControls/QGCQGeoCoordinate.h \ src/QmlControls/QGroundControlQmlGlobal.h \ @@ -438,6 +439,7 @@ SOURCES += \ src/QmlControls/AppMessages.cc \ src/QmlControls/CoordinateVector.cc \ src/QmlControls/ParameterEditorController.cc \ + src/QmlControls/RCChannelMonitorController.cc \ src/QmlControls/ScreenToolsController.cc \ src/QmlControls/QGCQGeoCoordinate.cc \ src/QmlControls/QGroundControlQmlGlobal.cc \ diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index dcabab456..5e7fde828 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -61,6 +61,7 @@ src/QmlControls/ModeSwitchDisplay.qml src/QmlControls/ParameterEditor.qml src/QmlControls/ParameterEditorDialog.qml + src/QmlControls/RCChannelMonitor.qml src/QmlControls/QGCButton.qml src/QmlControls/QGCCheckBox.qml src/QmlControls/QGCColoredImage.qml diff --git a/src/AutoPilotPlugins/Common/RadioComponent.qml b/src/AutoPilotPlugins/Common/RadioComponent.qml index 18f31d258..70dc08f0c 100644 --- a/src/AutoPilotPlugins/Common/RadioComponent.qml +++ b/src/AutoPilotPlugins/Common/RadioComponent.qml @@ -532,53 +532,9 @@ QGCView { source: controller.imageHelp } - // Channel monitor - Column { + RCChannelMonitor { width: parent.width - spacing: 5 - - QGCLabel { text: qsTr("Channel Monitor") } - - Connections { - target: controller - - onChannelRCValueChanged: { - if (channelMonitorRepeater.itemAt(channel)) { - channelMonitorRepeater.itemAt(channel).loader.item.rcValue = rcValue - } - } - } - - Repeater { - id: channelMonitorRepeater - model: controller.channelCount - width: parent.width - - Row { - spacing: 5 - - // Need this to get to loader from Connections above - property Item loader: theLoader - - QGCLabel { - id: channelLabel - text: modelData + 1 - } - - Loader { - id: theLoader - anchors.verticalCenter: channelLabel.verticalCenter - height: qgcView.defaultTextHeight - width: 200 - sourceComponent: channelMonitorDisplayComponent - - property real defaultTextWidth: qgcView.defaultTextWidth - property bool mapped: true - readonly property bool reversed: false - } - } - } - } // Column - Channel Monitor + } } // Column - Right Column } // QGCFlickable } // QGCViewPanel diff --git a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml index 4f5868aef..4099de573 100644 --- a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml +++ b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml @@ -53,11 +53,11 @@ Item { QGCFlickable { anchors.fill: parent clip: true - contentWidth: contentColumn.width - contentHeight: contentColumn.height + contentWidth: column2.x + column2.width + contentHeight: Math.max(column1.height, column2.height) Column { - id: contentColumn + id: column1 spacing: _margins Row { @@ -131,7 +131,8 @@ Item { } // Column - Flight mode settings Column { - spacing: _margins + id: column2 + spacing: _margins QGCLabel { text: qsTr("Switch Settings") @@ -139,6 +140,7 @@ Item { } Rectangle { + id: switchSettingsRect width: switchSettingsColumn.width + (_margins * 2) height: switchSettingsColumn.height + ScreenTools.defaultFontPixelHeight color: qgcPal.windowShade @@ -174,6 +176,10 @@ Item { } // Repeater } // Column } // Rectangle + + RCChannelMonitor { + width: switchSettingsRect.width + } } // Column - Switch settings } // Row - Settings diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 9b924e3cb..3a12a5c90 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -73,6 +73,7 @@ #include "ESP8266ComponentController.h" #include "ScreenToolsController.h" #include "QGCMobileFileDialogController.h" +#include "RCChannelMonitorController.h" #include "AutoPilotPlugin.h" #include "VehicleComponent.h" #include "FirmwarePluginManager.h" @@ -457,6 +458,7 @@ void QGCApplication::_initCommon(void) qmlRegisterType ("QGroundControl.Controllers", 1, 0, "FlightDisplayViewController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ValuesWidgetController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "QGCMobileFileDialogController"); + qmlRegisterType ("QGroundControl.Controllers", 1, 0, "RCChannelMonitorController"); #ifndef __mobile__ qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ViewWidgetController"); diff --git a/src/QmlControls/QGroundControl.Controls.qmldir b/src/QmlControls/QGroundControl.Controls.qmldir index 64990fbe0..5595c7f19 100644 --- a/src/QmlControls/QGroundControl.Controls.qmldir +++ b/src/QmlControls/QGroundControl.Controls.qmldir @@ -15,6 +15,7 @@ MissionItemStatus 1.0 MissionItemStatus.qml ModeSwitchDisplay 1.0 ModeSwitchDisplay.qml ParameterEditor 1.0 ParameterEditor.qml ParameterEditorDialog 1.0 ParameterEditorDialog.qml +RCChannelMonitor 1.0 RCChannelMonitor.qml QGCButton 1.0 QGCButton.qml QGCCheckBox 1.0 QGCCheckBox.qml QGCColoredImage 1.0 QGCColoredImage.qml diff --git a/src/QmlControls/RCChannelMonitor.qml b/src/QmlControls/RCChannelMonitor.qml new file mode 100644 index 000000000..ff56fd764 --- /dev/null +++ b/src/QmlControls/RCChannelMonitor.qml @@ -0,0 +1,151 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +import QtQuick 2.5 +import QtQuick.Controls 1.2 +import QtQuick.Dialogs 1.2 + +import QGroundControl 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.FactControls 1.0 +import QGroundControl.ScreenTools 1.0 +import QGroundControl.Controllers 1.0 + +FactPanel { + id: _root + height: monitorColumn.height + + QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled } + + RCChannelMonitorController { + id: controller + factPanel: _root + } + + // Live channel monitor control component + Component { + id: channelMonitorDisplayComponent + + Item { + property int rcValue: 1500 + + + property int __lastRcValue: 1500 + readonly property int __rcValueMaxJitter: 2 + property color __barColor: qgcPal.windowShade + + // Bar + Rectangle { + id: bar + anchors.verticalCenter: parent.verticalCenter + width: parent.width + height: parent.height / 2 + color: __barColor + } + + // Center point + Rectangle { + anchors.horizontalCenter: parent.horizontalCenter + width: ScreenTools.defaultTextWidth / 2 + height: parent.height + color: qgcPal.window + } + + // Indicator + Rectangle { + anchors.verticalCenter: parent.verticalCenter + width: parent.height * 0.75 + height: width + x: ((Math.abs((rcValue - 1000) - (reversed ? 1000 : 0)) / 1000) * parent.width) - (width / 2) + radius: width / 2 + color: qgcPal.text + visible: mapped + } + + QGCLabel { + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: "Not Mapped" + visible: !mapped + } + + ColorAnimation { + id: barAnimation + target: bar + property: "color" + from: "yellow" + to: __barColor + duration: 1500 + } + } + } // Component - channelMonitorDisplayComponent + + Column { + id: monitorColumn + width: parent.width + spacing: 5 + + QGCLabel { text: "Channel Monitor" } + + Connections { + target: controller + + onChannelRCValueChanged: { + if (channelMonitorRepeater.itemAt(channel)) { + channelMonitorRepeater.itemAt(channel).loader.item.rcValue = rcValue + } + } + } + + Repeater { + id: channelMonitorRepeater + model: controller.channelCount + width: parent.width + + Row { + spacing: 5 + + // Need this to get to loader from Connections above + property Item loader: theLoader + + QGCLabel { + id: channelLabel + text: modelData + 1 + } + + Loader { + id: theLoader + anchors.verticalCenter: channelLabel.verticalCenter + height: qgcView.defaultTextHeight + width: 200 + sourceComponent: channelMonitorDisplayComponent + + property bool mapped: true + readonly property bool reversed: false + } + } + } + } +} diff --git a/src/QmlControls/RCChannelMonitorController.cc b/src/QmlControls/RCChannelMonitorController.cc new file mode 100644 index 000000000..6bf454663 --- /dev/null +++ b/src/QmlControls/RCChannelMonitorController.cc @@ -0,0 +1,53 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include "RCChannelMonitorController.h" + +RCChannelMonitorController::RCChannelMonitorController(void) + : _chanCount(0) +{ + connect(_vehicle, &Vehicle::rcChannelsChanged, this, &RCChannelMonitorController::_rcChannelsChanged); +} + +void RCChannelMonitorController::_rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]) +{ + int maxChannel = std::min(channelCount, _chanMax()); + + for (int channel=0; channelfirmwareType() == MAV_AUTOPILOT_PX4 ? _chanMaxPX4 : _chanMaxAPM; +} diff --git a/src/QmlControls/RCChannelMonitorController.h b/src/QmlControls/RCChannelMonitorController.h new file mode 100644 index 000000000..66182f978 --- /dev/null +++ b/src/QmlControls/RCChannelMonitorController.h @@ -0,0 +1,61 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#ifndef RCChannelMonitorController_H +#define RCChannelMonitorController_H + +#include + +#include "FactPanelController.h" +#include "UASInterface.h" +#include "QGCLoggingCategory.h" +#include "AutoPilotPlugin.h" + +class RCChannelMonitorController : public FactPanelController +{ + Q_OBJECT + +public: + RCChannelMonitorController(void); + + Q_PROPERTY(int channelCount READ channelCount NOTIFY channelCountChanged) + + int channelCount(void) { return _chanCount; } + +signals: + void channelCountChanged(int channelCount); + void channelRCValueChanged(int channel, int rcValue); + +private slots: + void _rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]); + +private: + int _chanMax(void) const; + + int _chanCount; + + static const int _chanMaxPX4 = 18; ///< Maximum number of supported rc channels, PX4 Firmware + static const int _chanMaxAPM = 14; ///< Maximum number of supported rc channels, APM firmware +}; + +#endif // RCChannelMonitorController_H -- 2.22.0