JoystickManager.h 2.35 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

Gus Grubba's avatar
Gus Grubba committed
10 11
/// @file
/// @brief  Joystick Manager
12

Gus Grubba's avatar
Gus Grubba committed
13
#pragma once
14 15 16

#include "QGCLoggingCategory.h"
#include "Joystick.h"
17 18
#include "MultiVehicleManager.h"
#include "QGCToolbox.h"
19 20 21 22 23

#include <QVariantList>

Q_DECLARE_LOGGING_CATEGORY(JoystickManagerLog)

Gus Grubba's avatar
Gus Grubba committed
24
/// Joystick Manager
25
class JoystickManager : public QGCTool
26 27 28 29
{
    Q_OBJECT
    
public:
30
    JoystickManager(QGCApplication* app, QGCToolbox* toolbox);
31
    ~JoystickManager();
32

Jacob Walser's avatar
Jacob Walser committed
33 34
    Q_PROPERTY(QVariantList joysticks READ joysticks NOTIFY availableJoysticksChanged)
    Q_PROPERTY(QStringList  joystickNames READ joystickNames NOTIFY availableJoysticksChanged)
35 36 37 38
    
    Q_PROPERTY(Joystick* activeJoystick READ activeJoystick WRITE setActiveJoystick NOTIFY activeJoystickChanged)
    Q_PROPERTY(QString activeJoystickName READ activeJoystickName WRITE setActiveJoystickName NOTIFY activeJoystickNameChanged)
    
Gus Grubba's avatar
Gus Grubba committed
39
    /// List of available joysticks
40
    QVariantList joysticks();
Gus Grubba's avatar
Gus Grubba committed
41
    /// List of available joystick names
42 43
    QStringList joystickNames(void);
    
Gus Grubba's avatar
Gus Grubba committed
44
    /// Get active joystick
45
    Joystick* activeJoystick(void);
Gus Grubba's avatar
Gus Grubba committed
46
    /// Set active joystick
47 48 49 50 51
    void setActiveJoystick(Joystick* joystick);
    
    QString activeJoystickName(void);
    void setActiveJoystickName(const QString& name);

52 53
    void restartJoystickCheckTimer(void);

54 55 56
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

57
public slots:
Jacob Walser's avatar
Jacob Walser committed
58
    void init();
59

60 61 62
signals:
    void activeJoystickChanged(Joystick* joystick);
    void activeJoystickNameChanged(const QString& name);
Jacob Walser's avatar
Jacob Walser committed
63
    void availableJoysticksChanged(void);
64
    void updateAvailableJoysticksSignal();
65 66

private slots:
Jacob Walser's avatar
Jacob Walser committed
67
    void _updateAvailableJoysticks(void);
68 69 70 71 72
    
private:
    void _setActiveJoystickFromSettings(void);
    
private:
73
    Joystick*                   _activeJoystick;
74
    QMap<QString, Joystick*>    _name2JoystickMap;
75
    MultiVehicleManager*        _multiVehicleManager;
76 77 78
    
    static const char * _settingsGroup;
    static const char * _settingsKeyActiveJoystick;
Jacob Walser's avatar
Jacob Walser committed
79

80
    int _joystickCheckTimerCounter;
Jacob Walser's avatar
Jacob Walser committed
81
    QTimer _joystickCheckTimer;
82
};