-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoystick.h
101 lines (66 loc) · 1.47 KB
/
joystick.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef JOYSTICK_H
#define JOYSTICK_H
#include <QObject>
#include <QDebug>
#include <QStringList>
#include "sdlwrap.h"
#include "SDL.h"
#undef main
#define INT_16_MAX 32767
#define INT_16_MIN -32768
#define JOYSTICK_A 10
#define JOYSTICK_B 11
#define JOYSTICK_X 12
#define JOYSTICK_Y 13
#define JOYSTICK_DP_UP 0
#define JOYSTICK_DP_DOWN 1
#define JOYSTICK_DP_LEFT 2
#define JOYSTICK_DP_RIGHT 3
#define JOYSTICK_LJ_X 0
#define JOYSTICK_LJ_Y 1
#define JOYSTICK_RJ_X 2
#define JOYSTICK_RJ_Y 3
#define JOYSTICK_L3 6
#define JOYSTICK_R3 7
#define JOYSTICK_LEFTBUTTON 8
#define JOYSTICK_RIGHTBUTTON 9
#define JOYSTICK_LTRIGG 4
#define JOYSTICK_RTRIGG 5
#define JOYSTICK_BACK 5
#define JOYSTICK_START 4
#define JOYSTICK_HOME 14
struct ButtonState {
bool lastState;
bool currentState;
};
class Joystick : public QObject
{
Q_OBJECT
public:
explicit Joystick();
~Joystick();
bool select(int index);
bool connect();
void disconnect();
bool isConnected();
int getNumAxes();
int getNumButtons();
bool getButtonState(int buttonId);
bool getButtonPressed(int buttonId);
bool getButtonReleased(int buttonId);
qint16 getAxis(int axisId);
void update();
private:
bool connected;
int numAxes;
int numButtons;
QList<ButtonState> buttons;
QList<qint16> axes;
QList<qint16> axesZero;
QString joystickName;
int joystickId;
SDL_Joystick* sdlJoystick;
signals:
public slots:
};
#endif // JOYSTICK_H