Skip to content
AutoPilotPlugin.cc 2.36 KiB
Newer Older
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
 * (c) 2009-2020 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.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed

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

#include "AutoPilotPlugin.h"
#include "QGCApplication.h"
#include "FirmwarePlugin.h"
AutoPilotPlugin::AutoPilotPlugin(Vehicle* vehicle, QObject* parent)
    : QObject(parent)
    , _vehicle(vehicle)
    , _firmwarePlugin(vehicle->firmwarePlugin())
DonLakeFlyer's avatar
DonLakeFlyer committed
    , _setupComplete(false)
Don Gagne's avatar
Don Gagne committed
{
AutoPilotPlugin::~AutoPilotPlugin()
{
void AutoPilotPlugin::_recalcSetupComplete(void)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
    bool newSetupComplete = true;

    for(const QVariant& componentVariant: vehicleComponents()) {
DonLakeFlyer's avatar
DonLakeFlyer committed
        VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
        if (component) {
            if (!component->setupComplete()) {
                newSetupComplete = false;
                break;
            }
        } else {
            qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
        }
    }

    if (_setupComplete != newSetupComplete) {
        _setupComplete = newSetupComplete;
        emit setupCompleteChanged(_setupComplete);
    }
}

bool AutoPilotPlugin::setupComplete(void)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
    return _setupComplete;
void AutoPilotPlugin::parametersReadyPreChecks(void)

    // Connect signals in order to keep setupComplete up to date
    for(const QVariant componentVariant: vehicleComponents()) {
        VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
        if (component) {
            connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
        } else {
            qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
        }
    }

DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
        qgcApp()->showAppMessage(tr("One or more vehicle components require setup prior to flight."));
        // Take the user to Vehicle Summary
        qgcApp()->showSetupView();
        qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
Don Gagne's avatar
Don Gagne committed
    }