//Main header file for the XDK
#include
<xtl.h>
/***************************************************************************/
/*
*/
/* The whole gamepad rumble code has been packed in here! We can see
*/
/* thats its nice and small and simple :) I did it so that gamepad 1
*/
/* will start rumbling....nice and easy..hehe
*/
/*
*/
/***************************************************************************/
// I copied and pasted the structure for XINPUT_FEEDBACK below, so you could
// see what it looks like. As you might want to know whats inside it.
/*
struct XINPUT_RUMBLE
{
WORD wLeftMotorSpeed;
WORD wRightMotorSpeed;
};
struct XINPUT_STATE
{
DWORD dwPacketNumber;
union
{
XINPUT_GAMEPAD Gamepad;
};
};
#define XINPUT_FEEDBACK_HEADER_INTERNAL_SIZE 58
struct XINPUT_FEEDBACK_HEADER
{
DWORD dwStatus;
HANDLE OPTIONAL hEvent;
BYTE Reserved[XINPUT_FEEDBACK_HEADER_INTERNAL_SIZE];
};
struct XINPUT_FEEDBACK
{
XINPUT_FEEDBACK_HEADER Header;
union
{
XINPUT_RUMBLE Rumble;
};
};
*/
XINPUT_FEEDBACK Feedback = {0};
void
GamePadRumble()
{
DWORD dwInsertions, dwRemovals;
XGetDeviceChanges( XDEVICE_TYPE_GAMEPAD, &dwInsertions, &dwRemovals );
static HANDLE pGamePd;
// dwInsertion contains the 'bitwise' information
of inserted gamepads
//
// etc
// GamePad 2
// | GamePad 1
// | | GamePad 0
// | | |
// 0 0 ... 0 0 1
if( dwInsertions & 1 )
{
pGamePd = XInputOpen( XDEVICE_TYPE_GAMEPAD, 0,
XDEVICE_NO_SLOT,
NULL );
}
if( pGamePd )
{
Feedback.Rumble.wLeftMotorSpeed = (WORD)64000;
// 0 to 65535
Feedback.Rumble.wRightMotorSpeed = (WORD)0;
// 0 to 65535
// Send the feedback state
XInputSetState( pGamePd, &Feedback);
while( Feedback.Header.dwStatus
== ERROR_IO_PENDING)
{
// Do nothing
}
}//
End if(pGamePd)
}//
End GamePadRumble()
//Application entry point
void
__cdecl main()
{
//--1-- Init our USB Devices, you only ever need
to do this once at startup
XInitDevices(0,0);
while(true)
{
// This is where we call our gamepad
code
// --2-- Call our Gamepad Rumble
function! where we make it rumble!
GamePadRumble();
}//
End while loop
}//
End main()
|