-
Notifications
You must be signed in to change notification settings - Fork 1
/
controllerremapper.h
86 lines (73 loc) · 2.13 KB
/
controllerremapper.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
#ifndef CONTROLLERREMAPPER_H
#define CONTROLLERREMAPPER_H
#include <windows.h>
#include <QThread>
#include <QSet>
#include <QVector>
#include <QTimer>
#include <QMap>
#define XINPUT_GAMEPAD_GUIDE 0x400
#define kButtonCount 11
// The following is a value that an XInput axis is guaranteed never to have, and
// is therefore safe to use as a flag indicating an unset value:
#define kAxisUnset -100000
enum {
kUp = 0,
kUpRight,
kRight,
kDownRight,
kDown,
kDownLeft,
kLeft,
kUpLeft,
kNoDirection
};
class Controller {
public:
Controller() {};
void initialize();
void doControllerMap(UINT vjoyDeviceId);
void reset(UINT vjoyDeviceId);
UINT deviceIndex;
private:
QVector<bool> buttonsDown;
QVector<bool> directionDown;
long lastLeftTrigger, lastRightTrigger, lastLX, lastLY, lastRX, lastRY;
DWORD lastPacketNumber;
bool lastConnected;
bool handledFirstPacket;
};
class ControllerRemapper : public QThread
{
Q_OBJECT
public:
explicit ControllerRemapper(HWND win, bool inEnabled = true, QObject *parent = 0);
void pressButton(UINT deviceIndex, UINT xboxButton);
void moveJoystick(UINT deviceIndex, bool right, double xVal, double yVal);
void pressTrigger(UINT deviceIndex, bool right, double val);
void moveDPad(UINT deviceIndex, int direction);
bool isEnabled();
signals:
void initializationError(QString msg);
public slots:
void poll();
void setEnabled(bool inEnabled);
protected:
virtual void run() Q_DECL_OVERRIDE;
void initialize();
void deinitialize();
void initializeDevice(UINT deviceId);
void throwInitError(QString arg);
bool checkAxisExists(UINT deviceId, UINT axis, QString axisName);
HINSTANCE getXInputDLLHandle();
bool initializeVJoy();
QSet<UINT> initializedDevices;
Controller controllers[4];
QTimer *pollTimer;
unsigned int controllerCount;
HWND dinputWindow;
QMap<UINT, UINT> xboxToVJoyMap;
bool errorOccurred;
bool enabled;
};
#endif // CONTROLLERREMAPPER_H