FlightModesComponent.cc 3.08 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10 11 12 13 14

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

#include "FlightModesComponent.h"
Don Gagne's avatar
Don Gagne committed
15
#include "PX4AutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
16
#include "QGCQmlWidgetHolder.h"
17 18 19 20 21 22

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

23
FlightModesComponent::FlightModesComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
24
    VehicleComponent(vehicle, autopilot, parent),
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    _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.");
}

41
QString FlightModesComponent::iconResource(void) const
42
{
43
    return "/qmlimages/FlightModesComponentIcon.png";
44 45 46 47
}

bool FlightModesComponent::requiresSetup(void) const
{
Don Gagne's avatar
Don Gagne committed
48
    return _autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ? false : true;
49 50 51 52
}

bool FlightModesComponent::setupComplete(void) const
{
Don Gagne's avatar
Don Gagne committed
53 54 55 56 57 58 59 60 61 62
    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;
63 64
}

Don Gagne's avatar
Don Gagne committed
65
QStringList FlightModesComponent::setupCompleteChangedTriggerList(void) const
66
{
Don Gagne's avatar
Don Gagne committed
67 68 69 70 71
    QStringList list;

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

    return list;
72 73
}

74
QUrl FlightModesComponent::setupSource(void) const
75
{
Don Gagne's avatar
Don Gagne committed
76
    return QUrl::fromUserInput("qrc:/qml/PX4FlightModes.qml");
77 78
}

79
QUrl FlightModesComponent::summaryQmlSource(void) const
80
{
81
    return QUrl::fromUserInput("qrc:/qml/FlightModesComponentSummary.qml");
82
}
Don Gagne's avatar
Don Gagne committed
83 84 85

QString FlightModesComponent::prerequisiteSetup(void) const
{
Don Gagne's avatar
Don Gagne committed
86
    if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) {
87 88 89 90 91 92 93 94 95 96
        // 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();
97
        } else if (!plugin->vehicle()->hilMode() && !plugin->sensorsComponent()->setupComplete()) {
98
            return plugin->sensorsComponent()->name();
99
        }
Don Gagne's avatar
Don Gagne committed
100
    }
101

Don Gagne's avatar
Don Gagne committed
102 103
    return QString();
}