FlightModesComponent.cc 3.62 KB
Newer Older
1
/*=====================================================================
2

3
 QGroundControl Open Source Ground Control Station
4

5
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
6

7
 This file is part of the QGROUNDCONTROL project
8

9 10 11 12
 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.
13

14 15 16 17
 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.
18

19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
21

22 23 24 25 26 27
 ======================================================================*/

/// @file
///     @author Don Gagne <don@thegagnes.com>

#include "FlightModesComponent.h"
Don Gagne's avatar
Don Gagne committed
28
#include "PX4AutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
29
#include "QGCQmlWidgetHolder.h"
30 31 32 33 34 35

struct SwitchListItem {
    const char* param;
    const char* name;
};

36
FlightModesComponent::FlightModesComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
37
    VehicleComponent(vehicle, autopilot, parent),
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    _name(tr("Flight Modes"))
{
}

QString FlightModesComponent::name(void) const
{
    return _name;
}

QString FlightModesComponent::description(void) const
{
    // FIXME: Better text
    return tr("The Flight Modes Component is used to set the switches associated with Flight Modes. "
              "At a minimum the Main Mode Switch must be assigned prior to flight.");
}

54
QString FlightModesComponent::iconResource(void) const
55
{
56
    return "/qmlimages/FlightModesComponentIcon.png";
57 58 59 60
}

bool FlightModesComponent::requiresSetup(void) const
{
Don Gagne's avatar
Don Gagne committed
61
    return _autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ? false : true;
62 63 64 65
}

bool FlightModesComponent::setupComplete(void) const
{
Don Gagne's avatar
Don Gagne committed
66 67 68 69 70 71 72 73 74 75
    if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) {
        return true;
    }

    if (_autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_MODE_SW")->rawValue().toInt() != 0 ||
            (_autopilot->parameterExists(FactSystem::defaultComponentId, "RC_MAP_FLTMODE") && _autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_FLTMODE")->rawValue().toInt() != 0)) {
        return true;
    }

    return false;
76 77
}

Don Gagne's avatar
Don Gagne committed
78
QStringList FlightModesComponent::setupCompleteChangedTriggerList(void) const
79
{
Don Gagne's avatar
Don Gagne committed
80 81 82 83 84
    QStringList list;

    list << QStringLiteral("RC_MAP_MODE_SW") << QStringLiteral("RC_MAP_FLTMODE");

    return list;
85 86
}

87
QUrl FlightModesComponent::setupSource(void) const
88
{
Don Gagne's avatar
Don Gagne committed
89
    return QUrl::fromUserInput("qrc:/qml/PX4FlightModes.qml");
90 91
}

92
QUrl FlightModesComponent::summaryQmlSource(void) const
93
{
94
    return QUrl::fromUserInput("qrc:/qml/FlightModesComponentSummary.qml");
95
}
Don Gagne's avatar
Don Gagne committed
96 97 98

QString FlightModesComponent::prerequisiteSetup(void) const
{
Don Gagne's avatar
Don Gagne committed
99
    if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) {
100 101 102 103 104 105 106 107 108 109
        // No RC input
        return QString();
    } else {
        PX4AutoPilotPlugin* plugin = dynamic_cast<PX4AutoPilotPlugin*>(_autopilot);
        Q_ASSERT(plugin);

        if (!plugin->airframeComponent()->setupComplete()) {
            return plugin->airframeComponent()->name();
        } else if (!plugin->radioComponent()->setupComplete()) {
            return plugin->radioComponent()->name();
110 111
        } else if (!plugin->sensorsComponent()->setupComplete()) {
            return plugin->sensorsComponent()->name();
112
        }
Don Gagne's avatar
Don Gagne committed
113
    }
114

Don Gagne's avatar
Don Gagne committed
115 116
    return QString();
}