QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
JoystickComponent.cc
Go to the documentation of this file.
1#include "JoystickComponent.h"
3
4#include "Joystick.h"
5#include "JoystickManager.h"
6
7QGC_LOGGING_CATEGORY(JoystickComponentLog, "AutoPilotPlugins.JoystickComponent")
8
9JoystickComponent::JoystickComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent)
10 : VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownJoystickVehicleComponent, parent)
11 , _name(tr("Joystick"))
12{
13 qCDebug(JoystickComponentLog) << this;
14
15 (void) connect(JoystickManager::instance(), &JoystickManager::activeJoystickChanged, this, &JoystickComponent::_activeJoystickChanged);
16 (void) connect(JoystickManager::instance(), &JoystickManager::activeJoystickChanged, this, &VehicleComponent::setupCompleteChanged);
17
18 _activeJoystickChanged(JoystickManager::instance()->activeJoystick());
19}
20
21JoystickComponent::~JoystickComponent()
22{
23 qCDebug(JoystickComponentLog) << this;
24}
25
26QString JoystickComponent::description() const
27{
28 return tr("Configure joystick input, calibrate axes, and manage button assignments.");
29}
30
31bool JoystickComponent::setupComplete() const
32{
33 return !JoystickManager::instance()->activeJoystick() || JoystickManager::instance()->activeJoystick()->settings()->calibrated()->rawValue().toBool();
34}
35
36QUrl JoystickComponent::setupSource() const
37{
38 return QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/VehicleSetup/JoystickComponent.qml"));
39}
40
41QUrl JoystickComponent::summaryQmlSource() const
42{
43 return QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AutoPilotPlugins/Common/JoystickComponentSummary.qml"));
44}
45
46QString JoystickComponent::joystickStatusText() const
47{
48 if (!_activeJoystick) {
49 return tr("No joystick detected");
50 }
51
52 if (_activeJoystick->axisCount() == 0) {
53 return tr("Buttons only");
54 }
55
56 if (!_activeJoystick->requiresCalibration()) {
57 return tr("Ready");
58 }
59
60 return _activeJoystick->settings()->calibrated()->rawValue().toBool() ? tr("Calibrated") : tr("Needs calibration");
61}
62
63QString JoystickComponent::joystickFeaturesText() const
64{
65 if (!_activeJoystick) {
66 return QString();
67 }
68
69 QStringList features;
70
71 if (_activeJoystick->hasRumble()) {
72 features.append(tr("Rumble"));
73 }
74 if (_activeJoystick->hasRumbleTriggers()) {
75 features.append(tr("Trigger Rumble"));
76 }
77 if (_activeJoystick->hasLED()) {
78 features.append(tr("LED"));
79 }
80 if (_activeJoystick->hasGyroscope()) {
81 features.append(tr("Gyro"));
82 }
83 if (_activeJoystick->hasAccelerometer()) {
84 features.append(tr("Accel"));
85 }
86 if (_activeJoystick->touchpadCount() > 0) {
87 features.append(tr("Touchpad"));
88 }
89
90 return features.join(QStringLiteral(", "));
91}
92
93void JoystickComponent::_activeJoystickChanged(Joystick *joystick)
94{
95 if (_activeJoystick) {
96 (void) disconnect(_activeJoystick->settings()->calibrated(), &Fact::rawValueChanged, this, &VehicleComponent::setupCompleteChanged);
97 (void) disconnect(_activeJoystick->settings()->calibrated(), &Fact::rawValueChanged, this, &JoystickComponent::_joystickCalibrationChanged);
98 (void) disconnect(_activeJoystick, &Joystick::batteryStateChanged, this, &JoystickComponent::_joystickBatteryChanged);
99 _activeJoystick = nullptr;
100 }
101
102 if (joystick) {
103 _activeJoystick = joystick;
104 (void) connect(_activeJoystick->settings()->calibrated(), &Fact::rawValueChanged, this, &VehicleComponent::setupCompleteChanged);
105 (void) connect(_activeJoystick->settings()->calibrated(), &Fact::rawValueChanged, this, &JoystickComponent::_joystickCalibrationChanged);
106 (void) connect(_activeJoystick, &Joystick::batteryStateChanged, this, &JoystickComponent::_joystickBatteryChanged);
107 }
108
111}
112
113void JoystickComponent::_joystickCalibrationChanged()
114{
116}
117
118void JoystickComponent::_joystickBatteryChanged()
119{
121}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void rawValueChanged(const QVariant &value)
void joystickStatusChanged()
void activeJoystickChanged()
void activeJoystickChanged(Joystick *joystick)
Fact *calibrated READ calibrated CONSTANT Fact * calibrated()
virtual bool hasAccelerometer() const
Definition Joystick.h:232
virtual bool hasRumbleTriggers() const
Definition Joystick.h:203
virtual bool requiresCalibration() const
Definition Joystick.h:201
void batteryStateChanged()
virtual int touchpadCount() const
Definition Joystick.h:241
virtual bool hasGyroscope() const
Definition Joystick.h:231
QString name READ name int axisCount
Definition Joystick.h:101
virtual bool hasRumble() const
Definition Joystick.h:202
JoystickSettings * settings()
Definition Joystick.h:197
virtual bool hasLED() const
Definition Joystick.h:204
void setupCompleteChanged()