forked from duchuule/vba10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCXBOXController.cpp
52 lines (41 loc) · 1.22 KB
/
CXBOXController.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
50
51
52
#include "CXBOXController.h"
#ifndef NO_XBOX
namespace VBA10
{
CXBOXController::CXBOXController(int playerNumber)
: controllerNumber(playerNumber - 1)
{
}
XINPUT_STATE CXBOXController::GetState(void)
{
ZeroMemory(&this->state, sizeof(XINPUT_STATE));
XInputGetState(this->controllerNumber, &this->state); //get state of controller #controlerNumber (hardcode 0 at the moment)
//see this->p1Controller = new ControllerInput(1);
return this->state;
}
bool CXBOXController::IsConnected(void)
{
//ZeroMemory(&this->state, sizeof(XINPUT_STATE));
bool connected = false;
for (int i = 0; i <= 3; i++)
{
int cNumber = (this->controllerNumber + i) % 4; //try from the current controller number first
if (XInputGetState(cNumber, &this->state) == ERROR_SUCCESS)
{
controllerNumber = cNumber;
connected = true;
break;
}
}
return connected;
}
void CXBOXController::Vibrate(int leftVal, int rightVal)
{
XINPUT_VIBRATION vibration;
ZeroMemory(&vibration, sizeof(XINPUT_VIBRATION));
vibration.wLeftMotorSpeed = leftVal;
vibration.wRightMotorSpeed = rightVal;
XInputSetState(this->controllerNumber, &vibration);
}
}
#endif