-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinputmonitor.h
91 lines (71 loc) · 2.48 KB
/
inputmonitor.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
#ifndef INPUTMONITOR_H
#define INPUTMONITOR_H
#include <QThread>
#include <SDL2/SDL.h>
class InputUpdate
{
friend class InputMonitor;
public:
struct Axis
{
friend class InputMonitor;
public:
Axis(void) : _x(0.0f), _y(0.0f) {}
inline int X(void) const { return _x; }
inline int Y(void) const { return _y; }
private:
int _x;
int _y;
};
InputUpdate(void) : _btnState(0) {}
enum eState
{
eOFF,
eON
};
inline const Axis& AxisLeft(void) const { return _axisLeft; }
inline const Axis& AxisRight(void) const { return _axisRight; }
eState BtnState(unsigned char buttonID) const;
private:
Axis _axisLeft;
Axis _axisRight;
unsigned char _btnState;
};
class InputMonitor : public QThread
{
Q_OBJECT
const int DEAD_ZONE;
public:
explicit InputMonitor(QObject* parent = 0L);
virtual ~InputMonitor();
enum eStatus
{
eOK,
eERROR
};
signals:
void DeviceConnected(const QString& label);
void DeviceDisconnected(void);
void DeviceStatusUpdate(const InputMonitor::eStatus& status, const QString& message);
void DeviceUpdate(const InputUpdate& state);
public slots:
void UpdateRateChanged(unsigned int ms) ;
protected:
void run(void) Q_DECL_OVERRIDE;
private:
void Initialize(void);
SDL_Joystick* SelectController(void);
void HandleController(void);
void OnControllerButtonEvent( const SDL_ControllerButtonEvent& event );
void OnControllerAxisEvent( const SDL_ControllerAxisEvent& event );
void OnJoystickAxisEvent( const SDL_JoyAxisEvent& event);
void OnJoystickButtonEvent( const SDL_JoyButtonEvent& event);
void AddControllerEvent( const SDL_ControllerDeviceEvent& event );
void RemoveControllerEvent( const SDL_ControllerDeviceEvent& event );
void AddJoystickEvent( const SDL_JoyDeviceEvent& event);
void RemoveJoystickEvent( const SDL_JoyDeviceEvent& event);
private:
int _sleepRate;
InputUpdate _currentState;
};
#endif // INPUTMONITOR_H