diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bf5201b90d..6d14223e75e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,8 @@ if(ANDROID) endif() endif() +set(QT_SILENCE_MISSING_DEPENDENCY_TARGET_WARNING ON) + find_package(Qt6 REQUIRED COMPONENTS diff --git a/src/API/QGCCorePlugin.cc b/src/API/QGCCorePlugin.cc index a338135f1fe..29bfc2db1d8 100644 --- a/src/API/QGCCorePlugin.cc +++ b/src/API/QGCCorePlugin.cc @@ -301,7 +301,7 @@ QQmlApplicationEngine* QGCCorePlugin::createQmlApplicationEngine(QObject* parent { "eventMonitor", QVariant::fromValue(&eventMonitor) } }); */ qmlEngine->addImportPath("qrc:/qml"); - qmlEngine->rootContext()->setContextProperty("joystickManager", qgcApp()->toolbox()->joystickManager()); + qmlEngine->rootContext()->setContextProperty("joystickManager", JoystickManager::instance()); qmlEngine->rootContext()->setContextProperty("debugMessageModel", AppMessages::getModel()); return qmlEngine; } diff --git a/src/Camera/QGCCameraManager.cc b/src/Camera/QGCCameraManager.cc index 3934997ff0f..c1cf3be3af2 100644 --- a/src/Camera/QGCCameraManager.cc +++ b/src/Camera/QGCCameraManager.cc @@ -69,9 +69,8 @@ void QGCCameraManager::_vehicleReady(bool ready) if(ready) { if(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle() == _vehicle) { _vehicleReadyState = true; - JoystickManager *pJoyMgr = qgcApp()->toolbox()->joystickManager(); - _activeJoystickChanged(pJoyMgr->activeJoystick()); - connect(pJoyMgr, &JoystickManager::activeJoystickChanged, this, &QGCCameraManager::_activeJoystickChanged); + _activeJoystickChanged(JoystickManager::instance()->activeJoystick()); + connect(JoystickManager::instance(), &JoystickManager::activeJoystickChanged, this, &QGCCameraManager::_activeJoystickChanged); } } } diff --git a/src/Joystick/CMakeLists.txt b/src/Joystick/CMakeLists.txt index 1cebdecdbd0..e809509d17f 100644 --- a/src/Joystick/CMakeLists.txt +++ b/src/Joystick/CMakeLists.txt @@ -60,6 +60,15 @@ qt_add_resources(Joystick "gamecontrollerdb.txt" FILES ${sdl_gamecontrollerdb_SOURCE_DIR}/gamecontrollerdb.txt ) +qt_add_qml_module(Joystick + URI QGroundControl.JoystickManager + VERSION 1.0 + OUTPUT_TARGETS Joystick_targets + IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY} +) + +cmake_print_variables(Joystick_targets) + set(MINIMUM_SDL2_VERSION 2.30.0) if(NOT QGC_BUILD_DEPENDENCIES) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index c8f411967d7..1e7e7257490 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -19,6 +19,7 @@ #include "FirmwarePlugin.h" #include "QGCLoggingCategory.h" #include "GimbalController.h" +#include "QmlObjectListModel.h" #include diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index 4d0b8bfffac..63b39e3817b 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -18,6 +18,7 @@ #include #include #include +#include // JoystickLog Category declaration moved to QGCLoggingCategory.cc to allow access in Vehicle Q_DECLARE_LOGGING_CATEGORY(JoystickValuesLog) @@ -25,6 +26,7 @@ Q_DECLARE_METATYPE(GRIPPER_ACTIONS) class MultiVehicleManager; class Vehicle; +class QmlObjectListModel; /// Action assigned to button class AssignedButtonAction : public QObject { @@ -54,6 +56,10 @@ class AssignableButtonAction : public QObject { class Joystick : public QThread { Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") + Q_MOC_INCLUDE("QmlObjectListModel.h") + Q_MOC_INCLUDE("Vehicle.h") public: Joystick(const QString& name, int axisCount, int buttonCount, int hatCount, MultiVehicleManager* multiVehicleManager); diff --git a/src/Joystick/JoystickAndroid.cc b/src/Joystick/JoystickAndroid.cc index e0cc24f7f2a..f574be03bf8 100644 --- a/src/Joystick/JoystickAndroid.cc +++ b/src/Joystick/JoystickAndroid.cc @@ -242,12 +242,8 @@ bool JoystickAndroid::_getHat(int hat,int i) { } } -static JoystickManager *_manager = nullptr; - //helper method -bool JoystickAndroid::init(JoystickManager *manager) { - _manager = manager; - +bool JoystickAndroid::init() { //this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports //instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change @@ -296,10 +292,8 @@ static void jniUpdateAvailableJoysticks(JNIEnv *envA, jobject thizA) Q_UNUSED(envA); Q_UNUSED(thizA); - if (_manager != nullptr) { - qCDebug(JoystickLog) << "jniUpdateAvailableJoysticks triggered"; - emit _manager->updateAvailableJoysticksSignal(); - } + qCDebug(JoystickLog) << "jniUpdateAvailableJoysticks triggered"; + emit JoystickManager::instance()->updateAvailableJoysticksSignal(); } void JoystickAndroid::setNativeMethods() diff --git a/src/Joystick/JoystickAndroid.h b/src/Joystick/JoystickAndroid.h index 8209d7751e8..bf96ebebc1d 100644 --- a/src/Joystick/JoystickAndroid.h +++ b/src/Joystick/JoystickAndroid.h @@ -13,16 +13,14 @@ #include class MultiVehicleManager; -class JoystickManager; class JoystickAndroid : public Joystick, public QtAndroidPrivate::GenericMotionEventListener, public QtAndroidPrivate::KeyEventListener { public: JoystickAndroid(const QString& name, int axisCount, int buttonCount, int id, MultiVehicleManager* multiVehicleManager); - ~JoystickAndroid(); - static bool init(JoystickManager *manager); + static bool init(); static void setNativeMethods(); diff --git a/src/Joystick/JoystickManager.cc b/src/Joystick/JoystickManager.cc index c2ae0893c42..f2562540369 100644 --- a/src/Joystick/JoystickManager.cc +++ b/src/Joystick/JoystickManager.cc @@ -7,80 +7,82 @@ * ****************************************************************************/ - #include "JoystickManager.h" -#include "MultiVehicleManager.h" #include "Joystick.h" #if defined(QGC_SDL_JOYSTICK) #include "JoystickSDL.h" #elif defined(Q_OS_ANDROID) #include "JoystickAndroid.h" #endif +#include "QGCApplication.h" +#include "MultiVehicleManager.h" #include "QGCLoggingCategory.h" +#include #include +#include #include #include -QGC_LOGGING_CATEGORY(JoystickManagerLog, "JoystickManagerLog") +QGC_LOGGING_CATEGORY(JoystickManagerLog, "qgc.joystick.joystickmanager") -JoystickManager::JoystickManager(QGCApplication* app, QGCToolbox* toolbox) - : QGCTool(app, toolbox) - , _activeJoystick(nullptr) - , _multiVehicleManager(nullptr) +Q_APPLICATION_STATIC(JoystickManager, _joystickManager); + +JoystickManager::JoystickManager(QObject *parent) + : QObject(parent) + , _joystickCheckTimer(new QTimer(this)) { // qCDebug(JoystickManagerLog) << Q_FUNC_INFO << this; + + _joystickCheckTimer->setInterval(1000); + _joystickCheckTimer->setSingleShot(false); } JoystickManager::~JoystickManager() { - QMap::iterator i; - for (i = _name2JoystickMap.begin(); i != _name2JoystickMap.end(); ++i) { - qCDebug(JoystickManagerLog) << "Releasing joystick:" << i.key(); - i.value()->stop(); - delete i.value(); + for (QMap::key_value_iterator it = _name2JoystickMap.keyValueBegin(); it != _name2JoystickMap.keyValueEnd(); ++it) { + qCDebug(JoystickManagerLog) << "Releasing joystick:" << it->first; + it->second->stop(); + delete it->second; } // qCDebug(JoystickManagerLog) << Q_FUNC_INFO << this; } -void JoystickManager::setToolbox(QGCToolbox *toolbox) +JoystickManager *JoystickManager::instance() { - QGCTool::setToolbox(toolbox); - - _multiVehicleManager = _toolbox->multiVehicleManager(); - - QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); - qmlRegisterUncreatableType("QGroundControl.JoystickManager", 1, 0, "JoystickManager", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "Joystick", "Reference only"); + return _joystickManager(); } -void JoystickManager::init() { +void JoystickManager::init() +{ #ifdef QGC_SDL_JOYSTICK if (!JoystickSDL::init()) { return; } _setActiveJoystickFromSettings(); #elif defined(Q_OS_ANDROID) - if (!JoystickAndroid::init(this)) { + if (!JoystickAndroid::init()) { return; } - connect(this, &JoystickManager::updateAvailableJoysticksSignal, this, &JoystickManager::restartJoystickCheckTimer); + (void) connect(this, &JoystickManager::updateAvailableJoysticksSignal, this, [this]() { + _joystickCheckTimerCounter = 5; + _joystickCheckTimer->start(); + }); #endif - connect(&_joystickCheckTimer, &QTimer::timeout, this, &JoystickManager::_updateAvailableJoysticks); + (void) connect(_joystickCheckTimer, &QTimer::timeout, this, &JoystickManager::_updateAvailableJoysticks); _joystickCheckTimerCounter = 5; - _joystickCheckTimer.start(1000); + _joystickCheckTimer->start(); } -void JoystickManager::_setActiveJoystickFromSettings(void) +void JoystickManager::_setActiveJoystickFromSettings() { QMap newMap; #ifdef QGC_SDL_JOYSTICK - // Get the latest joystick mapping - newMap = JoystickSDL::discover(_multiVehicleManager); + newMap = JoystickSDL::discover(qgcApp()->toolbox()->multiVehicleManager()); #elif defined(Q_OS_ANDROID) - newMap = JoystickAndroid::discover(_multiVehicleManager); + newMap = JoystickAndroid::discover(qgcApp()->toolbox()->multiVehicleManager()); #endif if (_activeJoystick && !newMap.contains(_activeJoystick->name())) { @@ -90,47 +92,45 @@ void JoystickManager::_setActiveJoystickFromSettings(void) // Check to see if our current mapping contains any joysticks that are not in the new mapping // If so, those joysticks have been unplugged, and need to be cleaned up - QMap::iterator i; - for (i = _name2JoystickMap.begin(); i != _name2JoystickMap.end(); ++i) { - if (!newMap.contains(i.key())) { - qCDebug(JoystickManagerLog) << "Releasing joystick:" << i.key(); - i.value()->stopPolling(); - i.value()->wait(1000); - i.value()->deleteLater(); + for (QMap::key_value_iterator it = _name2JoystickMap.keyValueBegin(); it != _name2JoystickMap.keyValueEnd(); ++it) { + if (!newMap.contains(it->first)) { + qCDebug(JoystickManagerLog) << "Releasing joystick:" << it->first; + it->second->stopPolling(); + it->second->wait(1000); + it->second->deleteLater(); } } _name2JoystickMap = newMap; emit availableJoysticksChanged(); - if (!_name2JoystickMap.count()) { + if (_name2JoystickMap.isEmpty()) { setActiveJoystick(nullptr); return; } QSettings settings; - settings.beginGroup(_settingsGroup); - QString name = settings.value(_settingsKeyActiveJoystick).toString(); + QString name = settings.value(_settingsKeyActiveJoystick).toString(); if (name.isEmpty()) { name = _name2JoystickMap.first()->name(); } setActiveJoystick(_name2JoystickMap.value(name, _name2JoystickMap.first())); settings.setValue(_settingsKeyActiveJoystick, _activeJoystick->name()); + + settings.endGroup(); } -Joystick* JoystickManager::activeJoystick(void) +Joystick *JoystickManager::activeJoystick() { return _activeJoystick; } -void JoystickManager::setActiveJoystick(Joystick* joystick) +void JoystickManager::setActiveJoystick(Joystick *joystick) { - QSettings settings; - - if (joystick != nullptr && !_name2JoystickMap.contains(joystick->name())) { + if (joystick && !_name2JoystickMap.contains(joystick->name())) { qCWarning(JoystickManagerLog) << "Set active not in map" << joystick->name(); return; } @@ -148,49 +148,42 @@ void JoystickManager::setActiveJoystick(Joystick* joystick) if (_activeJoystick != nullptr) { qCDebug(JoystickManagerLog) << "Set active:" << _activeJoystick->name(); + QSettings settings; settings.beginGroup(_settingsGroup); settings.setValue(_settingsKeyActiveJoystick, _activeJoystick->name()); + settings.endGroup(); } emit activeJoystickChanged(_activeJoystick); - emit activeJoystickNameChanged(_activeJoystick?_activeJoystick->name():""); + emit activeJoystickNameChanged(_activeJoystick ? _activeJoystick->name() : ""); } -QVariantList JoystickManager::joysticks(void) +QVariantList JoystickManager::joysticks() { QVariantList list; - - for (const QString &name: _name2JoystickMap.keys()) { - list += QVariant::fromValue(_name2JoystickMap[name]); + for (auto it = _name2JoystickMap.constBegin(); it != _name2JoystickMap.constEnd(); ++it) { + list += QVariant::fromValue(it.value()); } return list; } -QStringList JoystickManager::joystickNames(void) -{ - return _name2JoystickMap.keys(); -} - -QString JoystickManager::activeJoystickName(void) +QString JoystickManager::activeJoystickName() const { - return _activeJoystick ? _activeJoystick->name() : QString(); + return (_activeJoystick ? _activeJoystick->name() : QString()); } -bool JoystickManager::setActiveJoystickName(const QString& name) +bool JoystickManager::setActiveJoystickName(const QString &name) { if (_name2JoystickMap.contains(name)) { setActiveJoystick(_name2JoystickMap[name]); return true; - } else { - qCWarning(JoystickManagerLog) << "Set active not in map" << name; - return false; } + + qCWarning(JoystickManagerLog) << "Set active not in map" << name; + return false; } -/* - * TODO: move this to the right place: JoystickSDL.cc and JoystickAndroid.cc respectively and call through Joystick.cc - */ void JoystickManager::_updateAvailableJoysticks() { #ifdef QGC_SDL_JOYSTICK @@ -216,13 +209,7 @@ void JoystickManager::_updateAvailableJoysticks() _joystickCheckTimerCounter--; _setActiveJoystickFromSettings(); if (_joystickCheckTimerCounter <= 0) { - _joystickCheckTimer.stop(); + _joystickCheckTimer->stop(); } #endif } - -void JoystickManager::restartJoystickCheckTimer() -{ - _joystickCheckTimerCounter = 5; - _joystickCheckTimer.start(1000); -} diff --git a/src/Joystick/JoystickManager.h b/src/Joystick/JoystickManager.h index b36a0510bd0..b549c5d0df4 100644 --- a/src/Joystick/JoystickManager.h +++ b/src/Joystick/JoystickManager.h @@ -7,79 +7,67 @@ * ****************************************************************************/ -/// @file -/// @brief Joystick Manager - #pragma once -#include "QGCToolbox.h" - +#include #include -#include #include +#include Q_DECLARE_LOGGING_CATEGORY(JoystickManagerLog) -class MultiVehicleManager; class Joystick; +class MultiVehicleManager; +class QTimer; -/// Joystick Manager -class JoystickManager : public QGCTool +class JoystickManager : public QObject { Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") Q_MOC_INCLUDE("Joystick.h") + Q_PROPERTY(QVariantList joysticks READ joysticks NOTIFY availableJoysticksChanged) + Q_PROPERTY(QStringList joystickNames READ joystickNames NOTIFY availableJoysticksChanged) + Q_PROPERTY(Joystick *activeJoystick READ activeJoystick WRITE setActiveJoystick NOTIFY activeJoystickChanged) + Q_PROPERTY(QString activeJoystickName READ activeJoystickName WRITE setActiveJoystickName NOTIFY activeJoystickNameChanged) public: - JoystickManager(QGCApplication* app, QGCToolbox* toolbox); + explicit JoystickManager(QObject *parent = nullptr); ~JoystickManager(); - Q_PROPERTY(QVariantList joysticks READ joysticks NOTIFY availableJoysticksChanged) - Q_PROPERTY(QStringList joystickNames READ joystickNames NOTIFY availableJoysticksChanged) - - Q_PROPERTY(Joystick* activeJoystick READ activeJoystick WRITE setActiveJoystick NOTIFY activeJoystickChanged) - Q_PROPERTY(QString activeJoystickName READ activeJoystickName WRITE setActiveJoystickName NOTIFY activeJoystickNameChanged) + static JoystickManager *instance(); - /// List of available joysticks QVariantList joysticks(); - /// List of available joystick names - QStringList joystickNames(void); - - /// Get active joystick - Joystick* activeJoystick(void); - /// Set active joystick - void setActiveJoystick(Joystick* joystick); + QStringList joystickNames() const { return _name2JoystickMap.keys(); } - QString activeJoystickName(void); - bool setActiveJoystickName(const QString& name); + Joystick *activeJoystick(); + void setActiveJoystick(Joystick *joystick); - void restartJoystickCheckTimer(void); + QString activeJoystickName() const; + bool setActiveJoystickName(const QString &name); - // Override from QGCTool - virtual void setToolbox(QGCToolbox *toolbox); +signals: + void activeJoystickChanged(Joystick *joystick); + void activeJoystickNameChanged(const QString &name); + void availableJoysticksChanged(); + void updateAvailableJoysticksSignal(); public slots: void init(); -signals: - void activeJoystickChanged(Joystick* joystick); - void activeJoystickNameChanged(const QString& name); - void availableJoysticksChanged(void); - void updateAvailableJoysticksSignal(); - private slots: - void _updateAvailableJoysticks(void); + // TODO: move this to the right place: JoystickSDL.cc and JoystickAndroid.cc respectively and call through Joystick.cc + void _updateAvailableJoysticks(); private: - void _setActiveJoystickFromSettings(void); + void _setActiveJoystickFromSettings(); -private: - Joystick* _activeJoystick; - QMap _name2JoystickMap; - MultiVehicleManager* _multiVehicleManager; + Joystick *_activeJoystick = nullptr; + QMap _name2JoystickMap; - int _joystickCheckTimerCounter; - QTimer _joystickCheckTimer; + int _joystickCheckTimerCounter = 0;; + QTimer *_joystickCheckTimer = nullptr; - static constexpr const char * _settingsGroup = "JoystickManager"; - static constexpr const char * _settingsKeyActiveJoystick = "ActiveJoystick"; + static constexpr const char *_settingsGroup = "JoystickManager"; + static constexpr const char *_settingsKeyActiveJoystick = "ActiveJoystick"; }; diff --git a/src/Joystick/JoystickSDL.h b/src/Joystick/JoystickSDL.h index bb56b2851f4..6cf81c28454 100644 --- a/src/Joystick/JoystickSDL.h +++ b/src/Joystick/JoystickSDL.h @@ -27,7 +27,7 @@ class JoystickSDL : public Joystick JoystickSDL(const QString& name, int axisCount, int buttonCount, int hatCount, int index, bool isGameController, MultiVehicleManager* multiVehicleManager); ~JoystickSDL(); - static QMap discover(MultiVehicleManager* _multiVehicleManager); + static QMap discover(MultiVehicleManager* _multiVehicleManager); static bool init(void); int index(void) const { return _index; } diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index fbdb956f99d..79a40a7a218 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -467,7 +467,7 @@ void QGCApplication::_initForNormalAppBoot() _toolbox->linkManager()->loadLinkConfigurationList(); // Probe for joysticks - _toolbox->joystickManager()->init(); + JoystickManager::instance()->init(); if (_settingsUpgraded) { showAppMessage(QString(tr("The format for %1 saved settings has been modified. " diff --git a/src/QGCToolbox.cc b/src/QGCToolbox.cc index 09e933c7212..05989093171 100644 --- a/src/QGCToolbox.cc +++ b/src/QGCToolbox.cc @@ -12,7 +12,6 @@ #ifndef NO_SERIAL_LINK #include "GPSManager.h" #endif -#include "JoystickManager.h" #include "LinkManager.h" #include "MAVLinkProtocol.h" #include "MissionCommandTree.h" @@ -47,7 +46,6 @@ QGCToolbox::QGCToolbox(QGCApplication* app) #ifndef NO_SERIAL_LINK _gpsManager = new GPSManager (app, this); #endif - _joystickManager = new JoystickManager (app, this); _linkManager = new LinkManager (app, this); _mavlinkProtocol = new MAVLinkProtocol (app, this); _missionCommandTree = new MissionCommandTree (app, this); @@ -74,7 +72,6 @@ void QGCToolbox::setChildToolboxes(void) #ifndef NO_SERIAL_LINK _gpsManager->setToolbox(this); #endif - _joystickManager->setToolbox(this); _linkManager->setToolbox(this); _mavlinkProtocol->setToolbox(this); _missionCommandTree->setToolbox(this); diff --git a/src/QGCToolbox.h b/src/QGCToolbox.h index 634ee38d213..ba93df9c5d8 100644 --- a/src/QGCToolbox.h +++ b/src/QGCToolbox.h @@ -15,7 +15,6 @@ class FirmwarePluginManager; class GPSManager; -class JoystickManager; class LinkManager; class MAVLinkProtocol; class MissionCommandTree; @@ -41,7 +40,6 @@ class QGCToolbox : public QObject { QGCToolbox(QGCApplication* app); FirmwarePluginManager* firmwarePluginManager () { return _firmwarePluginManager; } - JoystickManager* joystickManager () { return _joystickManager; } LinkManager* linkManager () { return _linkManager; } MAVLinkProtocol* mavlinkProtocol () { return _mavlinkProtocol; } MissionCommandTree* missionCommandTree () { return _missionCommandTree; } @@ -69,7 +67,6 @@ class QGCToolbox : public QObject { #ifndef NO_SERIAL_LINK GPSManager* _gpsManager = nullptr; #endif - JoystickManager* _joystickManager = nullptr; LinkManager* _linkManager = nullptr; MAVLinkProtocol* _mavlinkProtocol = nullptr; MissionCommandTree* _missionCommandTree = nullptr; diff --git a/src/Vehicle/MultiVehicleManager.cc b/src/Vehicle/MultiVehicleManager.cc index d5bbb22046d..48231e1ba75 100644 --- a/src/Vehicle/MultiVehicleManager.cc +++ b/src/Vehicle/MultiVehicleManager.cc @@ -32,7 +32,6 @@ MultiVehicleManager::MultiVehicleManager(QGCApplication* app, QGCToolbox* toolbo , _activeVehicle(nullptr) , _offlineEditingVehicle(nullptr) , _firmwarePluginManager(nullptr) - , _joystickManager(nullptr) , _mavlinkProtocol(nullptr) , _gcsHeartbeatEnabled(true) { @@ -47,7 +46,6 @@ void MultiVehicleManager::setToolbox(QGCToolbox *toolbox) QGCTool::setToolbox(toolbox); _firmwarePluginManager = _toolbox->firmwarePluginManager(); - _joystickManager = _toolbox->joystickManager(); _mavlinkProtocol = _toolbox->mavlinkProtocol(); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); @@ -119,7 +117,7 @@ void MultiVehicleManager::_vehicleHeartbeatInfo(LinkInterface* link, int vehicle _app->showAppMessage(tr("Warning: A vehicle is using the same system id as %1: %2").arg(QCoreApplication::applicationName()).arg(vehicleId)); } - Vehicle* vehicle = new Vehicle(link, vehicleId, componentId, (MAV_AUTOPILOT)vehicleFirmwareType, (MAV_TYPE)vehicleType, _firmwarePluginManager, _joystickManager, this); + Vehicle* vehicle = new Vehicle(link, vehicleId, componentId, (MAV_AUTOPILOT)vehicleFirmwareType, (MAV_TYPE)vehicleType, _firmwarePluginManager, this); connect(vehicle, &Vehicle::requestProtocolVersion, this, &MultiVehicleManager::_requestProtocolVersion); connect(vehicle->vehicleLinkManager(), &VehicleLinkManager::allLinksRemoved, this, &MultiVehicleManager::_deleteVehiclePhase1); connect(vehicle->parameterManager(), &ParameterManager::parametersReadyChanged, this, &MultiVehicleManager::_vehicleParametersReadyChanged); diff --git a/src/Vehicle/MultiVehicleManager.h b/src/Vehicle/MultiVehicleManager.h index 70d66c6061b..be09b4b6298 100644 --- a/src/Vehicle/MultiVehicleManager.h +++ b/src/Vehicle/MultiVehicleManager.h @@ -21,7 +21,6 @@ #include "QmlObjectListModel.h" class FirmwarePluginManager; -class JoystickManager; class QGCApplication; class MAVLinkProtocol; class LinkInterface; @@ -111,7 +110,6 @@ private slots: QmlObjectListModel _vehicles; FirmwarePluginManager* _firmwarePluginManager; - JoystickManager* _joystickManager; MAVLinkProtocol* _mavlinkProtocol; QGeoCoordinate _lastKnownLocation; diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 27145ba2df8..4c3eb96d05a 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -80,7 +80,6 @@ Vehicle::Vehicle(LinkInterface* link, MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, FirmwarePluginManager* firmwarePluginManager, - JoystickManager* joystickManager, QObject* parent) : VehicleFactGroup (parent) , _id (vehicleId) @@ -92,7 +91,6 @@ Vehicle::Vehicle(LinkInterface* link, , _defaultCruiseSpeed (_settingsManager->appSettings()->offlineEditingCruiseSpeed()->rawValue().toDouble()) , _defaultHoverSpeed (_settingsManager->appSettings()->offlineEditingHoverSpeed()->rawValue().toDouble()) , _firmwarePluginManager (firmwarePluginManager) - , _joystickManager (joystickManager) , _trajectoryPoints (new TrajectoryPoints(this, this)) , _mavlinkStreamConfig (std::bind(&Vehicle::_setMessageInterval, this, std::placeholders::_1, std::placeholders::_2)) , _vehicleFactGroup (this) @@ -116,7 +114,7 @@ Vehicle::Vehicle(LinkInterface* link, { _linkManager = _toolbox->linkManager(); - connect(_joystickManager, &JoystickManager::activeJoystickChanged, this, &Vehicle::_loadJoystickSettings); + connect(JoystickManager::instance(), &JoystickManager::activeJoystickChanged, this, &Vehicle::_loadJoystickSettings); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &Vehicle::_activeVehicleChanged); _mavlink = _toolbox->mavlinkProtocol(); @@ -1515,7 +1513,7 @@ void Vehicle::_loadJoystickSettings() QSettings settings; settings.beginGroup(QString(_settingsGroup).arg(_id)); - if (_toolbox->joystickManager()->activeJoystick()) { + if (JoystickManager::instance()->activeJoystick()) { qCDebug(JoystickLog) << "Vehicle " << this->id() << " Notified of an active joystick. Loading setting joystickenabled: " << settings.value(_joystickEnabledSettingsKey, false).toBool(); setJoystickEnabled(settings.value(_joystickEnabledSettingsKey, false).toBool()); } else { @@ -1533,7 +1531,7 @@ void Vehicle::saveJoystickSettings() // The joystick enabled setting should only be changed if a joystick is present // since the checkbox can only be clicked if one is present - if (_toolbox->joystickManager()->joysticks().count()) { + if (JoystickManager::instance()->joysticks().count()) { qCDebug(JoystickLog) << "Vehicle " << this->id() << " Saving setting joystickenabled: " << _joystickEnabled; settings.setValue(_joystickEnabledSettingsKey, _joystickEnabled); } @@ -1582,7 +1580,7 @@ void Vehicle::_activeVehicleChanged(Vehicle *newActiveVehicle) // tells the active joystick where to send data void Vehicle::_captureJoystick() { - Joystick* joystick = _joystickManager->activeJoystick(); + Joystick* joystick = JoystickManager::instance()->activeJoystick(); if(joystick){ qCDebug(JoystickLog) << "Vehicle " << this->id() << " Capture Joystick" << joystick->name(); diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 9f96661f9da..03495d9fb94 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -58,7 +58,6 @@ class ImageProtocolManager; class StatusTextHandler; class InitialConnectStateMachine; class Joystick; -class JoystickManager; class LinkInterface; class LinkManager; class MAVLinkProtocol; @@ -118,7 +117,6 @@ class Vehicle : public VehicleFactGroup MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, FirmwarePluginManager* firmwarePluginManager, - JoystickManager* joystickManager, QObject* parent = nullptr); // Pass these into the offline constructor to create an offline vehicle which tracks the offline vehicle settings @@ -1060,7 +1058,6 @@ private slots: LinkManager* _linkManager = nullptr; ParameterManager* _parameterManager = nullptr; FirmwarePluginManager* _firmwarePluginManager = nullptr; - JoystickManager* _joystickManager = nullptr; ComponentInformationManager* _componentInformationManager = nullptr; VehicleObjectAvoidance* _objectAvoidance = nullptr; Autotune* _autotune = nullptr; diff --git a/src/VehicleSetup/JoystickConfigController.cc b/src/VehicleSetup/JoystickConfigController.cc index c7a5c3c846f..90dd6e4e357 100644 --- a/src/VehicleSetup/JoystickConfigController.cc +++ b/src/VehicleSetup/JoystickConfigController.cc @@ -18,11 +18,10 @@ QGC_LOGGING_CATEGORY(JoystickConfigControllerLog, "JoystickConfigControllerLog") JoystickConfigController::JoystickConfigController(void) - : _joystickManager(qgcApp()->toolbox()->joystickManager()) { - connect(_joystickManager, &JoystickManager::activeJoystickChanged, this, &JoystickConfigController::_activeJoystickChanged); - _activeJoystickChanged(_joystickManager->activeJoystick()); + connect(JoystickManager::instance(), &JoystickManager::activeJoystickChanged, this, &JoystickConfigController::_activeJoystickChanged); + _activeJoystickChanged(JoystickManager::instance()->activeJoystick()); _setStickPositions(); _resetInternalCalibrationValues(); _currentStickPositions << _sticksCentered.leftX << _sticksCentered.leftY << _sticksCentered.rightX << _sticksCentered.rightY; @@ -36,7 +35,7 @@ void JoystickConfigController::start(void) void JoystickConfigController::setDeadbandValue(int axis, int value) { _axisDeadbandChanged(axis,value); - Joystick* joystick = _joystickManager->activeJoystick(); + Joystick* joystick = JoystickManager::instance()->activeJoystick(); Joystick::Calibration_t calibration = joystick->getCalibration(axis); calibration.deadband = value; joystick->setCalibration(axis,calibration); @@ -394,7 +393,7 @@ void JoystickConfigController::_resetInternalCalibrationValues() /// @brief Sets internal calibration values from the stored settings void JoystickConfigController::_setInternalCalibrationValuesFromSettings() { - Joystick* joystick = _joystickManager->activeJoystick(); + Joystick* joystick = JoystickManager::instance()->activeJoystick(); // Initialize all function mappings to not set for (int i = 0; i < _axisCount; i++) { struct AxisInfo* info = &_rgAxisInfo[i]; @@ -468,7 +467,7 @@ void JoystickConfigController::_validateCalibration() /// @brief Saves the rc calibration values to the board parameters. void JoystickConfigController::_writeCalibration() { - Joystick* joystick = _joystickManager->activeJoystick(); + Joystick* joystick = JoystickManager::instance()->activeJoystick(); _validateCalibration(); for (int axis = 0; axis < _axisCount; axis++) { diff --git a/src/VehicleSetup/JoystickConfigController.h b/src/VehicleSetup/JoystickConfigController.h index 3e9c6060cee..29f9943a744 100644 --- a/src/VehicleSetup/JoystickConfigController.h +++ b/src/VehicleSetup/JoystickConfigController.h @@ -21,8 +21,6 @@ Q_DECLARE_LOGGING_CATEGORY(JoystickConfigControllerLog) -class JoystickManager; - class JoystickConfigController : public FactPanelController { Q_OBJECT @@ -233,7 +231,6 @@ private slots: QElapsedTimer _stickDetectSettleElapsed; QString _statusText; - JoystickManager* _joystickManager; static constexpr int _calCenterPoint = 0; static constexpr int _calValidMinValue = -32768; ///< Largest valid minimum axis value