6import QGroundControl.FactControls
7import QGroundControl.Controls
11 pageComponent: lightsPageComponent
14 id: lightsPageComponent
20 FactPanelController { id: controller; }
22 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
23 property bool _oldFW: _activeVehicle.versionCompare(3, 5, 2) < 0
24 property Fact _rc5Function: controller.getParameterFact(-1, "SERVO5_FUNCTION")
25 property Fact _rc6Function: controller.getParameterFact(-1, "SERVO6_FUNCTION")
26 property Fact _rc7Function: controller.getParameterFact(-1, "SERVO7_FUNCTION")
27 property Fact _rc8Function: controller.getParameterFact(-1, "SERVO8_FUNCTION")
28 property Fact _rc9Function: controller.getParameterFact(-1, "SERVO9_FUNCTION")
29 property Fact _rc10Function: controller.getParameterFact(-1, "SERVO10_FUNCTION")
30 property Fact _rc11Function: controller.getParameterFact(-1, "SERVO11_FUNCTION")
31 property Fact _rc12Function: controller.getParameterFact(-1, "SERVO12_FUNCTION")
32 property Fact _rc13Function: controller.getParameterFact(-1, "SERVO13_FUNCTION")
33 property Fact _rc14Function: controller.getParameterFact(-1, "SERVO14_FUNCTION")
34 property Fact _rc15Function: controller.getParameterFact(-1, "SERVO15_FUNCTION")
35 property Fact _rc16Function: controller.getParameterFact(-1, "SERVO16_FUNCTION")
36 property Fact _stepSize: _oldFW ? controller.getParameterFact(-1, "JS_LIGHTS_STEP") : null // v3.5.1 and prior
37 property Fact _numSteps: _oldFW ? null : controller.getParameterFact(-1, "JS_LIGHTS_STEPS") // v3.5.2 and up
39 readonly property real _margins: ScreenTools.defaultFontPixelHeight
40 readonly property real _comboWidth: ScreenTools.defaultFontPixelWidth * 30
41 readonly property int _rcFunctionDisabled: 0
42 readonly property int _rcFunctionRCIN9: 59
43 readonly property int _rcFunctionRCIN10: 60
44 readonly property int _firstLightsOutChannel: 5
45 readonly property int _lastLightsOutChannel: 16
47 Component.onCompleted: {
52 /// Light output channels are stored in SERVO#_FUNCTION parameters. We need to loop through those
53 /// to find them and setup the ui accordindly.
54 function calcLightOutValues() {
55 lightsLoader.lights1OutIndex = 0
56 lightsLoader.lights2OutIndex = 0
57 for (let channel=_firstLightsOutChannel; channel<=_lastLightsOutChannel; channel++) {
58 let functionFact = controller.getParameterFact(-1, "SERVO" + channel + "_FUNCTION")
59 if (functionFact.value == _rcFunctionRCIN9) {
60 lightsLoader.lights1OutIndex = channel - 4
61 } else if (functionFact.value == _rcFunctionRCIN10) {
62 lightsLoader.lights2OutIndex = channel - 4
67 function setRCFunction(channel, rcFunction) {
68 // First clear any previous settings for this function
69 for (let index=_firstLightsOutChannel; index<=_lastLightsOutChannel; index++) {
70 let functionFact = controller.getParameterFact(-1, "SERVO" + index + "_FUNCTION")
71 if (functionFact.value != _rcFunctionDisabled && functionFact.value == rcFunction) {
72 functionFact.value = _rcFunctionDisabled
76 // Now set the function into the new channel
78 let functionFact = controller.getParameterFact(-1, "SERVO" + channel + "_FUNCTION")
79 functionFact.value = rcFunction
83 function calcCurrentStep() {
86 for(i; i <= 10; i++) {
87 let stepSize = (1900-1100)/i
88 if(_stepSize.value >= stepSize) {
89 _stepSize.value = stepSize;
93 if (_stepSize.value < 80) {
96 lightsLoader.lightsSteps = i
98 lightsLoader.lightsSteps = _numSteps.value
102 function calcStepSize(steps) {
104 _stepSize.value = (1900-1100)/steps
106 _numSteps.value = steps
110 // Whenever any SERVO#_FUNCTION parameters chagnes we need to go looking for light output channels again
111 Connections { target: _rc5Function; onValueChanged: calcLightOutValues() }
112 Connections { target: _rc6Function; onValueChanged: calcLightOutValues() }
113 Connections { target: _rc7Function; onValueChanged: calcLightOutValues() }
114 Connections { target: _rc8Function; onValueChanged: calcLightOutValues() }
115 Connections { target: _rc9Function; onValueChanged: calcLightOutValues() }
116 Connections { target: _rc10Function; onValueChanged: calcLightOutValues() }
117 Connections { target: _rc11Function; onValueChanged: calcLightOutValues() }
118 Connections { target: _rc12Function; onValueChanged: calcLightOutValues() }
119 Connections { target: _rc13Function; onValueChanged: calcLightOutValues() }
120 Connections { target: _rc14Function; onValueChanged: calcLightOutValues() }
124 // It appears that QGCComboBox can't handle models that don't have a initial item
125 // after onModelChanged
126 ListElement { text: qsTr("Disabled"); value: 0 }
128 function update(number) {
129 // Not enough channels
133 for(let i = 5; i <= number; i++) {
134 let text = qsTr("Channel ") + i
135 append({"text": text, "value": i})
139 Component.onCompleted: {
140 // Number of main outputs plus extra auxiliary outputs
141 // http://ardupilot.org/copter/docs/parameters.html#brd-pwm-count-auxiliary-pin-config
142 let totalChannels = _lastLightsOutChannel
143 if (controller.parameterExists(-1, "BRD_PWM_COUNT")) {
144 let brd_pwm_count_value = controller.getParameterFact(-1, "BRD_PWM_COUNT").value
145 totalChannels = 8 + (brd_pwm_count_value == 7 ? 3 : brd_pwm_count_value)
147 update(totalChannels)
155 title: qsTr("Light Output Channels")
159 rowSpacing: _margins / 2
160 columnSpacing: _margins / 2
162 QGCLabel { text: qsTr("Lights 1") }
166 Layout.maximumWidth: _comboWidth
167 model: lightsOutModel
169 currentIndex: lights1OutIndex
171 onActivated: (index) => { setRCFunction(lightsOutModel.get(index).value, lights1Function) }
174 QGCLabel { text: qsTr("Lights 2") }
178 Layout.maximumWidth: _comboWidth
179 model: lightsOutModel
181 currentIndex: lights2OutIndex
183 onActivated: (index) => { setRCFunction(lightsOutModel.get(index).value, lights2Function) }
186 QGCLabel { text: qsTr("Brightness Steps") }
190 Layout.maximumWidth: _comboWidth
191 model: [1,2,3,4,5,6,7,8,9,10]
192 currentIndex: lightsSteps-1
194 onActivated: (index) => { calcStepSize(index+1) }
198 } // Component - lightSettings
202 sourceComponent: lightSettings
204 property int lights1OutIndex: 0
205 property int lights2OutIndex: 0
206 property int lights1Function: _rcFunctionRCIN9
207 property int lights2Function: _rcFunctionRCIN10
208 property int lightsSteps: 1