X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fgui%2Fgamepad.cpp;h=b8ebdde5c21a8bf9827d906b2ac92508c2e0c3b2;hb=62587015fb12ec54b1702bfa17077e4b8af44b19;hp=1ef1a4e78fdd37877c4b26d4c9ac54b0f2810c5a;hpb=9af4fb023287b26dce01a36c65c9e30f56481051;p=virtualjaguar diff --git a/src/gui/gamepad.cpp b/src/gui/gamepad.cpp index 1ef1a4e..b8ebdde 100644 --- a/src/gui/gamepad.cpp +++ b/src/gui/gamepad.cpp @@ -7,7 +7,7 @@ // JLH = James Hammons // // Who When What -// --- ---------- ------------------------------------------------------------- +// --- ---------- ------------------------------------------------------------ // JLH 01/05/2013 Created this file // @@ -18,10 +18,13 @@ // Class member initialization /*static*/ int Gamepad::numJoysticks = 0; /*static*/ SDL_Joystick * Gamepad::pad[8]; +/*static*/ char Gamepad::padName[8][128]; /*static*/ int Gamepad::numButtons[8]; /*static*/ int Gamepad::numHats[8]; +/*static*/ int Gamepad::numAxes[8]; /*static*/ bool Gamepad::button[8][256]; /*static*/ uint8_t Gamepad::hat[8][32]; +/*static*/ int32_t Gamepad::axis[8][32]; Gamepad::Gamepad(void)//: numJoysticks(0) @@ -48,16 +51,27 @@ void Gamepad::AllocateJoysticks(void) for(int i=0; i 127 if (pad[i]) { numButtons[i] = SDL_JoystickNumButtons(pad[i]); numHats[i] = SDL_JoystickNumHats(pad[i]); + numAxes[i] = SDL_JoystickNumAxes(pad[i]); + WriteLog("Gamepad: Joystick #%i: %s\n", i, padName[i]); } } WriteLog("Gamepad: Found %u joystick%s.\n", numJoysticks, (numJoysticks == 1 ? "" : "s")); +#if 0 +for(int i=0; i= 8) + return NULL; + +//printf("GAMEPAD: Getting name (%s) for joystick #%i...\n", padName[joystickID], joystickID); + return padName[joystickID]; +} + + bool Gamepad::GetState(int joystickID, int buttonID) { uint8_t hatMask[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; @@ -85,12 +110,34 @@ bool Gamepad::GetState(int joystickID, int buttonID) uint8_t hatDirection = hatMask[buttonID & JOY_HATBUT_MASK]; return (hat[joystickID][hatNumber] & hatDirection ? true : false); } + else if (buttonID & JOY_AXIS) + { + int axisNum = (buttonID & JOY_AXISNUM_MASK) >> 1; + int direction = (buttonID & JOY_AXISDIR_MASK); +//printf("Checking pad #%u axis %u: axis = %i, direction = %u\n", joystickID, axisNum, axis[joystickID][axisNum], direction); + + if (axis[joystickID][axisNum] != 0) + { + if ((axis[joystickID][axisNum] > 32000) && (direction == 0)) +//{ +//printf("Axis + hit!\n"); + return true; +//} + + if ((axis[joystickID][axisNum] < -32000) && (direction == 1)) +//{ +//printf("Axis - hit!\n"); + return true; +//} + } + } // Default == failure return false; } +//UNUSED int Gamepad::CheckButtonPressed(void) { // This translates the hat direction to a mask index. @@ -111,12 +158,25 @@ int Gamepad::CheckButtonPressed(void) if (hat[i][j]) return (JOY_HAT | hatNum[hat[i][j]]); } + + for(int j=0; j 0) + if (axis[i][j] > 32000) + return (JOY_AXIS | (j << 1) | 0); + +// if (axis[i][j] < 0) + if (axis[i][j] < -32000) + return (JOY_AXIS | (j << 1) | 1); + } } return -1; } +// UNUSED int Gamepad::GetButtonID(void) { // Return single button ID being pressed (if any) @@ -124,6 +184,7 @@ int Gamepad::GetButtonID(void) } +// UNUSED int Gamepad::GetJoystickID(void) { // Return joystick ID of button being pressed (if any) @@ -143,10 +204,14 @@ void Gamepad::Update(void) for(int j=0; j