Bsongis/issue 4400 (#4425)
[opentx.git] / companion / src / simulation / joystick.h
blob5e2b4e86319e7bcedb7f77b87e532065b236c36c
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _JOYSTICK_H_
22 #define _JOYSTICK_H_
24 #include <QObject>
25 #include <QMap>
26 #include <QTime>
27 #include <QTimer>
28 #include <QStringList>
29 #include <SDL.h>
31 #define SDL_JOYSTICK_DEFAULT_EVENT_TIMEOUT 25
32 #define SDL_JOYSTICK_DEFAULT_AUTOREPEAT_DELAY 250
34 class Joystick : public QObject
36 Q_OBJECT
38 public:
39 QStringList joystickNames;
40 SDL_Joystick *joystick;
41 int numAxes;
42 int numButtons;
43 int numHats;
44 int numTrackballs;
45 int eventTimeout;
46 int autoRepeatDelay;
47 bool autoRepeat;
48 QTimer joystickTimer;
49 QMap<int, int> deadzones;
50 QMap<int, int> sensitivities;
52 Joystick(QObject *parent = 0,
53 int joystickEventTimeout = SDL_JOYSTICK_DEFAULT_EVENT_TIMEOUT,
54 bool doAutoRepeat = true,
55 int autoRepeatDelay = SDL_JOYSTICK_DEFAULT_AUTOREPEAT_DELAY);
56 ~Joystick();
57 bool open(int);
58 void close();
59 bool isOpen() { return joystick != NULL; }
60 int getAxisValue(int);
62 private:
63 QMap<int, Sint16> axes;
64 QMap<int, Uint8> buttons;
65 QMap<int, Uint8> hats;
66 QMap<int, QTime> axisRepeatTimers;
67 QMap<int, QTime> buttonRepeatTimers;
68 QMap<int, QTime> hatRepeatTimers;
70 signals:
71 void axisValueChanged(int axis, int value);
72 void buttonValueChanged(int button, bool value);
73 void hatValueChanged(int hat, int value);
74 void trackballValueChanged(int trackball, int deltaX, int deltaY);
76 public slots:
77 void processEvents();
80 #endif // _JOYSTICK_H_