FlightModesComponent.cc 3.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 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.
 
 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.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

/// @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 37
FlightModesComponent::FlightModesComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
    PX4Component(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
    return _autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ||
            _autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_MODE_SW")->rawValue().toInt() != 0;
68 69
}

Don Gagne's avatar
Don Gagne committed
70
QStringList FlightModesComponent::setupCompleteChangedTriggerList(void) const
71
{
Don Gagne's avatar
Don Gagne committed
72
    return QStringList("RC_MAP_MODE_SW");
73 74
}

75
QUrl FlightModesComponent::setupSource(void) const
76
{
77
    return QUrl::fromUserInput("qrc:/qml/FlightModesComponent.qml");
78 79
}

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

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