-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.cpp
49 lines (44 loc) · 1.39 KB
/
controller.cpp
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
#include "controller.h"
#include <windows.h>
#include <xinput.h>
#include <QTimer>
#include <QSettings>
#include <QDebug>
Controller::Controller()
{
}
void Controller::readInput()
{
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(pollControllers()));
timer->start(25);
}
void Controller::pollControllers()
{
for (DWORD i = 0; i < XUSER_MAX_COUNT; ++i) {
XINPUT_STATE controllerState;
if(XInputGetState(i, &controllerState) == ERROR_SUCCESS) {
if(currentPacket != controllerState.dwPacketNumber) {
XINPUT_GAMEPAD *gamepad = &controllerState.Gamepad;
bool A = (gamepad->wButtons & XINPUT_GAMEPAD_A);
bool B = (gamepad->wButtons & XINPUT_GAMEPAD_B);
bool DPAD_LEFT = (gamepad->wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
if(settings.value("controllerFlipped").toBool()) {
qDebug() << "Should be flipped";
if(A) {
emit ButtonPressed();
}
} else {
qDebug() << "Shouldn't";
if(B) {
emit ButtonPressed();
}
}
if(DPAD_LEFT) {
emit Paused();
}
}
currentPacket = controllerState.dwPacketNumber;
}
}
}