Commit 62550909 authored by Don Gagne's avatar Don Gagne

Commit

parent 0dd0e656
...@@ -702,6 +702,7 @@ HEADERS+= \ ...@@ -702,6 +702,7 @@ HEADERS+= \
src/VehicleSetup/VehicleSetupButton.h \ src/VehicleSetup/VehicleSetupButton.h \
src/VehicleSetup/VehicleComponentButton.h \ src/VehicleSetup/VehicleComponentButton.h \
src/VehicleSetup/VehicleComponent.h \ src/VehicleSetup/VehicleComponent.h \
src/AutoPilotPlugins/AutoPilotPluginManager.h \
src/AutoPilotPlugins/AutoPilotPlugin.h \ src/AutoPilotPlugins/AutoPilotPlugin.h \
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.h \ src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.h \
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h \ src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h \
...@@ -716,7 +717,7 @@ SOURCES += \ ...@@ -716,7 +717,7 @@ SOURCES += \
src/VehicleSetup/SummaryPage.cc \ src/VehicleSetup/SummaryPage.cc \
src/VehicleSetup/ParameterEditor.cc \ src/VehicleSetup/ParameterEditor.cc \
src/VehicleSetup/VehicleComponent.cc \ src/VehicleSetup/VehicleComponent.cc \
src/AutoPilotPlugins/AutoPilotPlugin.cc \ src/AutoPilotPlugins/AutoPilotPluginManager.cc \
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.cc \ src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.cc \
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc \ src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc \
src/AutoPilotPlugins/PX4/PX4Component.cc \ src/AutoPilotPlugins/PX4/PX4Component.cc \
......
...@@ -43,10 +43,6 @@ class AutoPilotPlugin : public QObject ...@@ -43,10 +43,6 @@ class AutoPilotPlugin : public QObject
Q_OBJECT Q_OBJECT
public: public:
/// @brief Returns the singleton AutoPilot instance for the specified auto pilot type.
/// @param autopilotType Specified using the MAV_AUTOPILOT_* values.
static AutoPilotPlugin* getInstanceForAutoPilotPlugin(int autopilotType);
/// @brief Returns the list of VehicleComponent objects associated with the AutoPilot. /// @brief Returns the list of VehicleComponent objects associated with the AutoPilot.
virtual QList<VehicleComponent*> getVehicleComponents(UASInterface* uas) const = 0; virtual QList<VehicleComponent*> getVehicleComponents(UASInterface* uas) const = 0;
...@@ -63,7 +59,7 @@ public: ...@@ -63,7 +59,7 @@ public:
protected: protected:
// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin // All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin
AutoPilotPlugin(void); AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { }
}; };
#endif #endif
...@@ -24,33 +24,30 @@ ...@@ -24,33 +24,30 @@
/// @file /// @file
/// @author Don Gagne <don@thegagnes.com> /// @author Don Gagne <don@thegagnes.com>
#include "AutoPilotPlugin.h" #include "AutoPilotPluginManager.h"
#include "PX4/PX4AutoPilotPlugin.h" #include "PX4/PX4AutoPilotPlugin.h"
#include "Generic/GenericAutoPilotPlugin.h" #include "Generic/GenericAutoPilotPlugin.h"
static AutoPilotPlugin* PX4_AutoPilot = NULL; ///< Singleton plugin for MAV_AUTOPILOT_PX4 AutoPilotPluginManager::AutoPilotPluginManager(QObject* parent) :
static AutoPilotPlugin* Generic_AutoPilot = NULL; ///< Singleton plugin for AutoPilots which do not have a specifically implemented plugin QObject(parent)
AutoPilotPlugin::AutoPilotPlugin(void)
{ {
// All plugins are constructed here so that they end up on the correct thread
_pluginMap[MAV_AUTOPILOT_PX4] = new PX4AutoPilotPlugin(this);
Q_ASSERT(_pluginMap.contains(MAV_AUTOPILOT_PX4));
_pluginMap[MAV_AUTOPILOT_GENERIC] = new GenericAutoPilotPlugin(this);
Q_ASSERT(_pluginMap.contains(MAV_AUTOPILOT_GENERIC));
} }
AutoPilotPlugin* AutoPilotPlugin::getInstanceForAutoPilotPlugin(int autopilotType) AutoPilotPlugin* AutoPilotPluginManager::getInstanceForAutoPilotPlugin(int autopilotType)
{ {
switch (autopilotType) { switch (autopilotType) {
case MAV_AUTOPILOT_PX4: case MAV_AUTOPILOT_PX4:
if (PX4_AutoPilot == NULL) { Q_ASSERT(_pluginMap.contains(MAV_AUTOPILOT_PX4));
PX4_AutoPilot = new PX4AutoPilotPlugin; return _pluginMap[MAV_AUTOPILOT_PX4];
}
Q_ASSERT(PX4_AutoPilot);
return PX4_AutoPilot;
default: default:
if (Generic_AutoPilot == NULL) { Q_ASSERT(_pluginMap.contains(MAV_AUTOPILOT_GENERIC));
Generic_AutoPilot = new GenericAutoPilotPlugin; return _pluginMap[MAV_AUTOPILOT_GENERIC];
}
Q_ASSERT(Generic_AutoPilot);
return Generic_AutoPilot;
} }
} }
/*=====================================================================
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/>.
======================================================================*/
#ifndef AUTOPILOTPLUGINMANAGER_H
#define AUTOPILOTPLUGINMANAGER_H
#include <QObject>
#include <QList>
#include <QString>
#include "UASInterface.h"
#include "VehicleComponent.h"
#include "QGCApplication.h"
#include "AutoPilotPlugin.h"
/// @file
/// @brief The AutoPilotPlugin manager is a singleton which maintains the list of AutoPilotPlugin objects.
///
/// @author Don Gagne <don@thegagnes.com>
class AutoPilotPluginManager : public QObject
{
Q_OBJECT
public:
/// @brief Returns the singleton AutoPilot instance for the specified auto pilot type.
/// @param autopilotType Specified using the MAV_AUTOPILOT_* values.
AutoPilotPlugin* getInstanceForAutoPilotPlugin(int autopilotType);
private:
/// @brief Only QGCQpplication is allowed to call constructor. All access to singleton is through
/// QGCApplication::singletonAutoPilotPluginManager.
AutoPilotPluginManager(QObject* parent = NULL);
/// @brief Only QGCQpplication is allowed to call constructor. All access to singleton is through
/// QGCApplication::singletonAutoPilotPluginManager.
friend class QGCApplication;
QMap<int, AutoPilotPlugin*> _pluginMap;
};
#endif
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
#include "GenericAutoPilotPlugin.h" #include "GenericAutoPilotPlugin.h"
GenericAutoPilotPlugin::GenericAutoPilotPlugin(void) GenericAutoPilotPlugin::GenericAutoPilotPlugin(QObject* parent) :
AutoPilotPlugin(parent)
{ {
} }
......
...@@ -36,7 +36,7 @@ class GenericAutoPilotPlugin : public AutoPilotPlugin ...@@ -36,7 +36,7 @@ class GenericAutoPilotPlugin : public AutoPilotPlugin
Q_OBJECT Q_OBJECT
public: public:
GenericAutoPilotPlugin(void); GenericAutoPilotPlugin(QObject* parent = NULL);
virtual QList<VehicleComponent*> getVehicleComponents(UASInterface* uas) const ; virtual QList<VehicleComponent*> getVehicleComponents(UASInterface* uas) const ;
virtual QList<FullMode_t> getModes(void) const; virtual QList<FullMode_t> getModes(void) const;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "RadioComponent.h" #include "RadioComponent.h"
#include "SensorsComponent.h" #include "SensorsComponent.h"
#include "FlightModesComponent.h" #include "FlightModesComponent.h"
#include "AutoPilotPluginManager.h"
/// @file /// @file
/// @brief This is the AutoPilotPlugin implementatin for the MAV_AUTOPILOT_PX4 type. /// @brief This is the AutoPilotPlugin implementatin for the MAV_AUTOPILOT_PX4 type.
...@@ -61,7 +62,8 @@ union px4_custom_mode { ...@@ -61,7 +62,8 @@ union px4_custom_mode {
float data_float; float data_float;
}; };
PX4AutoPilotPlugin::PX4AutoPilotPlugin(void) PX4AutoPilotPlugin::PX4AutoPilotPlugin(QObject* parent) :
AutoPilotPlugin(parent)
{ {
} }
...@@ -165,7 +167,7 @@ QString PX4AutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t customMo ...@@ -165,7 +167,7 @@ QString PX4AutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t customMo
mode = "|OFFBOARD"; mode = "|OFFBOARD";
} }
} else { } else {
mode = AutoPilotPlugin::getInstanceForAutoPilotPlugin(MAV_AUTOPILOT_GENERIC)->getShortModeText(baseMode, customMode); mode = qgcApp()->singletonAutoPilotPluginManager()->getInstanceForAutoPilotPlugin(MAV_AUTOPILOT_GENERIC)->getShortModeText(baseMode, customMode);
} }
return mode; return mode;
......
...@@ -35,7 +35,7 @@ class PX4AutoPilotPlugin : public AutoPilotPlugin ...@@ -35,7 +35,7 @@ class PX4AutoPilotPlugin : public AutoPilotPlugin
Q_OBJECT Q_OBJECT
public: public:
PX4AutoPilotPlugin(void); PX4AutoPilotPlugin(QObject* parent);
virtual QList<VehicleComponent*> getVehicleComponents(UASInterface* uas) const ; virtual QList<VehicleComponent*> getVehicleComponents(UASInterface* uas) const ;
virtual QList<FullMode_t> getModes(void) const; virtual QList<FullMode_t> getModes(void) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment