APMLightsComponentSummary.qml 4.6 KB
Newer Older
1 2
import QtQuick          2.3
import QtQuick.Controls 1.2
3 4 5 6 7 8 9 10 11 12 13 14 15 16

import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Palette 1.0

FactPanel {
    id:             panel
    anchors.fill:   parent
    color:          qgcPal.windowShadeDark

    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
    FactPanelController { id: controller; factPanel: panel }

17 18 19 20 21 22 23 24 25 26
    property Fact _rc5Function:         controller.getParameterFact(-1, "r.SERVO5_FUNCTION")
    property Fact _rc6Function:         controller.getParameterFact(-1, "r.SERVO6_FUNCTION")
    property Fact _rc7Function:         controller.getParameterFact(-1, "r.SERVO7_FUNCTION")
    property Fact _rc8Function:         controller.getParameterFact(-1, "r.SERVO8_FUNCTION")
    property Fact _rc9Function:         controller.getParameterFact(-1, "r.SERVO9_FUNCTION")
    property Fact _rc10Function:        controller.getParameterFact(-1, "r.SERVO10_FUNCTION")
    property Fact _rc11Function:        controller.getParameterFact(-1, "r.SERVO11_FUNCTION")
    property Fact _rc12Function:        controller.getParameterFact(-1, "r.SERVO12_FUNCTION")
    property Fact _rc13Function:        controller.getParameterFact(-1, "r.SERVO13_FUNCTION")
    property Fact _rc14Function:        controller.getParameterFact(-1, "r.SERVO14_FUNCTION")
27 28 29 30 31 32 33 34 35 36

    readonly property int   _rcFunctionRCIN9:               59
    readonly property int   _rcFunctionRCIN10:              60
    readonly property int   _firstLightsOutChannel:         5
    readonly property int   _lastLightsOutChannel:          14

    Component.onCompleted: {
        calcLightOutValues()
    }

37
    /// Light output channels are stored in SERVO#_FUNCTION parameters. We need to loop through those
38 39 40 41 42
    /// to find them and setup the ui accordindly.
    function calcLightOutValues() {
        lightsLoader.lights1OutIndex = 0
        lightsLoader.lights2OutIndex = 0
        for (var channel=_firstLightsOutChannel; channel<=_lastLightsOutChannel; channel++) {
43
            var functionFact = controller.getParameterFact(-1, "r.SERVO" + channel + "_FUNCTION")
44 45 46 47 48 49 50 51
            if (functionFact.value == _rcFunctionRCIN9) {
                lightsLoader.lights1OutIndex = channel - 4
            } else if (functionFact.value == _rcFunctionRCIN10) {
                lightsLoader.lights2OutIndex = channel - 4
            }
        }
    }

52
    // Whenever any SERVO#_FUNCTION parameters chagnes we need to go looking for light output channels again
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    Connections { target: _rc5Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc6Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc7Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc8Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc9Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc10Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc11Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc12Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc13Function; onValueChanged: calcLightOutValues() }
    Connections { target: _rc14Function; onValueChanged: calcLightOutValues() }

    ListModel {
        id: lightsOutModel
        ListElement { text: qsTr("Disabled"); value: 0 }
        ListElement { text: qsTr("Channel 5"); value: 5 }
        ListElement { text: qsTr("Channel 6"); value: 6 }
        ListElement { text: qsTr("Channel 7"); value: 7 }
        ListElement { text: qsTr("Channel 8"); value: 8 }
        ListElement { text: qsTr("Channel 9"); value: 9 }
        ListElement { text: qsTr("Channel 10"); value: 10 }
        ListElement { text: qsTr("Channel 11"); value: 11 }
        ListElement { text: qsTr("Channel 12"); value: 12 }
        ListElement { text: qsTr("Channel 13"); value: 13 }
        ListElement { text: qsTr("Channel 14"); value: 14 }
    }

    Loader {
        id:                 lightsLoader

        property int    lights1OutIndex:         0
        property int    lights2OutIndex:         0
        property int    lights1Function:         _rcFunctionRCIN9
        property int    lights2Function:         _rcFunctionRCIN10
    }

    Column {
        anchors.fill:       parent

        VehicleSummaryRow {
            labelText:  qsTr("Lights Output 1:")
            valueText:  lightsOutModel.get(lightsLoader.lights1OutIndex).text
        }

        VehicleSummaryRow {
            labelText:  qsTr("Lights Output 2:")
            valueText:  lightsOutModel.get(lightsLoader.lights2OutIndex).text
        }
    }
}