forked from ptitSeb/stuntcarremake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XBOXController.cpp
69 lines (57 loc) · 1.34 KB
/
XBOXController.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "dxstdafx.h"
#include "XBOXController.h"
// ctor - playerNumber 1<>4
CXBOXController::CXBOXController(const int playerNumber)
{
// Set the Controller Number
_controllerNum = playerNumber - 1;
}
XINPUT_STATE CXBOXController::GetState()
{
// Zeroise the state
ZeroMemory(&_controllerState, sizeof(XINPUT_STATE));
// Get the state
#ifdef linux
#warning TODO...
_controllerState = 0;
#else
XInputGetState(_controllerNum, &_controllerState);
#endif
return _controllerState;
}
bool CXBOXController::IsConnected()
{
// Zeroise the state
ZeroMemory(&_controllerState, sizeof(XINPUT_STATE));
// Get the state
#ifdef linux
#warning TODO
DWORD Result = 0xFFFF;
#else
DWORD Result = XInputGetState(_controllerNum, &_controllerState);
#endif
if(Result == ERROR_SUCCESS)
{
return true;
}
else
{
return false;
}
}
void CXBOXController::Vibrate(const unsigned short leftVal, const unsigned short rightVal)
{
#ifdef linux
#warning TODO
#else
// Create a Vibraton State
XINPUT_VIBRATION Vibration;
// Zeroise the Vibration
ZeroMemory(&Vibration, sizeof(XINPUT_VIBRATION));
// Set the Vibration Values
Vibration.wLeftMotorSpeed = leftVal;
Vibration.wRightMotorSpeed = rightVal;
// Vibrate the controller
XInputSetState(_controllerNum, &Vibration);
#endif
}