QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
JoystickManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QLoggingCategory>
4#include <QtCore/QObject>
5#include <QtCore/QTimer>
6#include <QtCore/QVariantList>
7#include <QtQmlIntegration/QtQmlIntegration>
8
9Q_DECLARE_LOGGING_CATEGORY(JoystickManagerLog)
10
11class Joystick;
13class Vehicle;
14
15class JoystickManager : public QObject
16{
17 Q_OBJECT
18 QML_ELEMENT
19 QML_UNCREATABLE("")
20 Q_MOC_INCLUDE("Joystick.h")
21
22
24 Q_PROPERTY(QStringList availableJoystickNames READ availableJoystickNames NOTIFY availableJoystickNamesChanged)
25
26 Q_PROPERTY(Joystick *activeJoystick READ activeJoystick NOTIFY activeJoystickChanged)
27 Q_PROPERTY(bool activeJoystickEnabledForActiveVehicle READ activeJoystickEnabledForActiveVehicle WRITE setActiveJoystickEnabledForActiveVehicle NOTIFY activeJoystickEnabledForActiveVehicleChanged)
28
29
30 Q_PROPERTY(int joystickCount READ joystickCount NOTIFY availableJoystickNamesChanged)
31
32#ifdef QGC_UNITTEST_BUILD
33 friend class JoystickManagerTest;
34#endif
35
36public:
37 explicit JoystickManager(QObject *parent = nullptr);
38 ~JoystickManager() override;
39
40 static JoystickManager *instance();
41
42 QStringList availableJoystickNames() const { return _name2JoystickMap.keys(); }
43 int joystickCount() const { return _name2JoystickMap.count(); }
44
45 Joystick *activeJoystick();
46 bool activeJoystickEnabledForActiveVehicle() const;
47 void setActiveJoystickEnabledForActiveVehicle(bool enabled);
48
51 Q_INVOKABLE QStringList linkedGroupMembers(const QString &groupId) const;
52
54 Q_INVOKABLE Joystick *joystickByName(const QString &name) const;
55
56signals:
60
61public slots:
62 void init();
63
64private slots:
66 void _checkForAddedOrRemovedJoysticks();
67 void _activeVehicleChanged(Vehicle *activeVehicle);
68 void _setActiveJoystickByName(const QString &name);
69
70 // SDL event handlers (called via QMetaObject::invokeMethod from sdlEventWatcher)
71 void _handleUpdateComplete(int instanceId);
72 void _handleBatteryUpdated(int instanceId);
73 void _handleGamepadRemapped(int instanceId);
74 void _handleTouchpadEvent(int instanceId, int touchpad, int finger, bool down, float x, float y, float pressure);
75 void _handleSensorUpdate(int instanceId, int sensor, float x, float y, float z);
76
77private:
78 void _setActiveJoystickFromSettings();
79 void _setActiveJoystick(Joystick *joystick);
80 bool _joystickEnabledForVehicle(Vehicle *vehicle) const;
81 void _setJoystickEnabledForVehicle(Vehicle *vehicle, bool enabled);
82 Joystick *_findJoystickByInstanceId(int instanceId);
83 void _updatePollingTimer();
84
85 JoystickManagerSettings *_joystickManagerSettings = nullptr;
86 Joystick *_activeJoystick = nullptr;
87 QMap<QString, Joystick*> _name2JoystickMap;
88 QTimer _pollTimer;
89};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
void availableJoystickNamesChanged()
void activeJoystickChanged(Joystick *joystick)
void activeJoystickEnabledForActiveVehicleChanged()