/***************************************************************************/
/*
*/
/* FileName: main.cpp
*/
/*
*/
/* Details: gamepad basics
*/
/*
*/
/* Author: Ben_3D@xbdev.net
*/
/*
*/
/*
*/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*
*/
/*
*/
/* Details: Determines if the keypad buttons have been pressed
*/
/*
*/
/* Auth: x-factor (http://www.xbdev.net)
*/
/*
*/
/* Main functions:
*/
/* Allows you to understand how the gamepad works, and give you a chance
*/
/* to build a self contained gamepad class that will meet all of your
*/
/* gameing needs.....
*/
/*
*/
/***************************************************************************/
/*
*****************************************************************
*** ***
*** | 1 Y B ***
* ___|___ xbdev.net *
* | X A *
* | *
* *
* x 3 | *
* x ___|___ *
* xxxxxxxxx ***************************** | *
* x * * | 2 *
* x * start back * *
* * * *
* * * *
********* *********
*/
/***************************************************************************/
#include
<xtl.h> // this is the xdk..xbox libraries
/***************************************************************************/
/*
*/
/* Well the function name should say it all, but its so that we can
*/
/* see if the gamepad has been pressed, so when we do press a button, we
*/
/* need some feedback, so I added this function....its nothing to do with
*/
/* the gamepad..heheh ..just incase you didn't know..
*/
/*
*/
/***************************************************************************/
void
ReBoot()
{
LD_LAUNCH_DASHBOARD LaunchData = { XLD_LAUNCH_DASHBOARD_MAIN_MENU };
XLaunchNewImage( NULL, (LAUNCH_DATA*)&LaunchData );
}
/***************************************************************************/
/*
*/
/* This is it...the code that explains how the gamepad works...its not to
*/
/* long I didnt' think...coudlnt really make it any smaller than this....
*/
/* But hopefully after looking at it for a second or to you can see what
is*/
/* happening..
*/
/*
*/
/***************************************************************************/
bool
GamePad()
{
XINPUT_GAMEPAD myGamePad;
// Definition of what XINPUT_GAMEPAD looks like:
/*
struct
{
WORD wButtons;
BYTE bAnalogButtons[8];
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
} XINPUT_GAMEPAD;
*/
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 )
{
XINPUT_STATE myInputStates;
XInputGetState( pGamePd, &myInputStates );
memcpy( &myGamePad, &myInputStates.Gamepad,
sizeof(XINPUT_GAMEPAD) );
}
// Okay simple but effective in this example, but
you press the gamepad
// up button, and it returns true!
if( myGamePad.wButtons &
XINPUT_GAMEPAD_DPAD_UP )
{
return
true;
}
return false;
}
//Application entry point
void
__cdecl main()
{
XInitDevices(0, 0);
// We keep checking the gampad, when it return
true, the up button on the gamepad
// was pressed and it returns true, and we leave
the loop and reboot our xbox.
while( true
)
{
bool bb = GamePad();
if( bb )
{
break;
}
}
ReBoot();
}
|