QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RemoteControlChannelValueDisplay.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7/// Displays the value of a single channel as an indicator within a value range bar
8Item {
9 enum Mode {
10 RawValue, // Display raw channel value
11 MappedValue // Channel goes through a mapping process and can be reversed
12 }
13
14 required property int channelValueMin
15 required property int channelValueMax
16 required property int mode ///< Mode of display using Mode enum values
17 property bool channelMapped: false
18 property int channelValue: _valueBarRange / 2 + _valueBarMin
19 property int deadbandValue: 0
20 property bool deadbandEnabled: false
21
22 id: control
23 implicitHeight: ScreenTools.defaultFontPixelHeight
24
25 readonly property real _valueRangeBarOvershootPercent: 0.2 // Pct overshoot on each end of display so indicator doesn't go right to edge
26 readonly property int _halfRange: (channelValueMax - channelValueMin) / 2
27 readonly property int _valueBarMin: channelValueMin - (_halfRange * _valueRangeBarOvershootPercent)
28 readonly property int _valueBarMax: channelValueMax + (_halfRange * _valueRangeBarOvershootPercent)
29 readonly property int _valueBarRange: _valueBarMax - _valueBarMin
30
31 Component.onCompleted: {
32 if (mode === RemoteControlChannelValueDisplay.RawValue) {
33 if (channelMapped) {
34 console.warn("RemoteControlChannelValueDisplay: channelMapped should not be true in Raw Value mode")
35 channelMapped = false
36 }
37 }
38 }
39
40 QGCPalette { id: qgcPal; colorGroupEnabled: control.enabled }
41
42 Rectangle {
43 id: fullValueRangeBar
44 anchors.verticalCenter: parent.verticalCenter
45 width: parent.width
46 height: parent.height / 2
47 color: qgcPal.windowShade
48 }
49
50 Rectangle {
51 id: deadbandRange
52 anchors.verticalCenter: parent.verticalCenter
53 height: parent.height
54 width: _deadbandWidth
55 x: _deadbandOffset
56 radius: ScreenTools.defaultFontPixelHeight / 4
57 color: qgcPal.buttonHighlight
58 opacity: 0.35
59 visible: control.deadbandEnabled && control.deadbandValue > 0
60 readonly property real _rangeSpan: Math.max(1, control.channelValueMax - control.channelValueMin)
61 readonly property real _usableWidth: parent.width / (1 + control._valueRangeBarOvershootPercent)
62 readonly property real _deadbandWidth: Math.min(1, (control.deadbandValue * 2) / _rangeSpan) * _usableWidth
63 readonly property real _deadbandOffset: (parent.width - _usableWidth) / 2 + (_usableWidth - _deadbandWidth) / 2
64 }
65
66 Rectangle {
67 id: centerPointDisplay
68 anchors.horizontalCenter: parent.horizontalCenter
69 width: 1
70 height: parent.height
71 color: qgcPal.window
72 }
73
74 QGCLabel {
75 id: notMappedLabel
76 anchors.centerIn: parent
77 text: qsTr("Not Mapped")
78 visible: control.mode === RemoteControlChannelValueDisplay.MappedValue && !control.channelMapped
79 }
80
81 // Indicator
82 Rectangle {
83 anchors.verticalCenter: parent.verticalCenter
84 width: parent.height * 0.75
85 height: width
86 x: {
87 const clampedValue = Math.max(control._valueBarMin, Math.min(control._valueBarMax, control.channelValue))
88 const normalized = (clampedValue - control._valueBarMin) / control._valueBarRange
89 return (normalized * parent.width) - (width / 2)
90 }
91 radius: width / 2
92 color: qgcPal.text
93 visible: control.mode === RemoteControlChannelValueDisplay.RawValue || control.channelMapped
94 }
95}