JoystickSDL.h 1.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/****************************************************************************
 *
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

/// @file
/// @brief SDL Joystick Interface

#pragma once
Gregory Dymarek's avatar
Gregory Dymarek committed
14 15 16 17 18

#include "Joystick.h"
#include "Vehicle.h"
#include "MultiVehicleManager.h"

19
#include <SDL.h>
Gregory Dymarek's avatar
Gregory Dymarek committed
20

21
/// @brief SDL Joystick Interface
Gregory Dymarek's avatar
Gregory Dymarek committed
22 23 24
class JoystickSDL : public Joystick
{
public:
25
    JoystickSDL(const QString& name, int axisCount, int buttonCount, int hatCount, int index, bool isGameController, MultiVehicleManager* multiVehicleManager);
Gregory Dymarek's avatar
Gregory Dymarek committed
26 27

    static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager); 
Jacob Walser's avatar
Jacob Walser committed
28 29 30 31
    static bool init(void);

    int index(void) { return _index; }
    void setIndex(int index) { _index = index; }
Gregory Dymarek's avatar
Gregory Dymarek committed
32

33 34
    // This can be uncommented to hide the calibration buttons for gamecontrollers in the future
    // bool requiresCalibration(void) final { return !_isGameController; }
Gregory Dymarek's avatar
Gregory Dymarek committed
35 36

private:
37 38
    static void _loadGameControllerMappings();

39 40 41
    bool _open      () final;
    void _close     () final;
    bool _update    () final;
Gregory Dymarek's avatar
Gregory Dymarek committed
42

43 44 45 46 47 48
    bool _getButton (int i) final;
    int  _getAxis   (int i) final;
    bool _getHat    (int hat,int i) final;

    SDL_Joystick*       sdlJoystick;
    SDL_GameController* sdlController;
Gregory Dymarek's avatar
Gregory Dymarek committed
49

50
    bool    _isGameController;
Gregory Dymarek's avatar
Gregory Dymarek committed
51
    int     _index;      ///< Index for SDL_JoystickOpen
52

Gregory Dymarek's avatar
Gregory Dymarek committed
53
};