X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fgamepad.cpp;h=4615c82e0880ac8fa1cbab06c75a6f1fd32fbfe6;hb=5b056aa1b8278aff14df2dacb5df2787d2eb8bdf;hp=62a6d7a9bef851d932aba79f87c305fc3a2aa36b;hpb=5d76d651dfc3aa0a2e810e6b6db2ae8a2e34c53e;p=virtualjaguar diff --git a/src/gui/gamepad.cpp b/src/gui/gamepad.cpp index 62a6d7a..4615c82 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,6 +18,7 @@ // 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]; @@ -50,17 +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 }; @@ -92,14 +114,21 @@ bool Gamepad::GetState(int joystickID, int buttonID) { 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] > 16000 && (direction == 0)) + if ((axis[joystickID][axisNum] > 32000) && (direction == 0)) +//{ +//printf("Axis + hit!\n"); return true; +//} - if (axis[joystickID][axisNum] < -16000 && (direction == 1)) + if ((axis[joystickID][axisNum] < -32000) && (direction == 1)) +//{ +//printf("Axis - hit!\n"); return true; +//} } } @@ -110,6 +139,8 @@ bool Gamepad::GetState(int joystickID, int buttonID) int Gamepad::CheckButtonPressed(void) { + DumpJoystickStatesToLog(); + // This translates the hat direction to a mask index. int hatNum[16] = { -1, 0, 1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1 }; @@ -146,6 +177,7 @@ int Gamepad::CheckButtonPressed(void) } +// UNUSED int Gamepad::GetButtonID(void) { // Return single button ID being pressed (if any) @@ -153,6 +185,7 @@ int Gamepad::GetButtonID(void) } +// UNUSED int Gamepad::GetJoystickID(void) { // Return joystick ID of button being pressed (if any) @@ -179,6 +212,84 @@ void Gamepad::Update(void) } +void Gamepad::DumpJoystickStatesToLog(void) +{ + bool pressed = false; + + for(int i=0; i 32000) + { + pressed = true; + break; + break; + } + + if (axis[i][j] < -32000) + { + pressed = true; + break; + break; + } + } + } + + if (!pressed) + return; + + WriteLog("Gamepad: CheckButtonPressed...\n"); + + for(int i=0; i 32000) + WriteLog("Gamepad: Pad #%i, axis %i pushed down...\n", i, j); + + if (axis[i][j] < -32000) + WriteLog("Gamepad: Pad #%i, axis %i pushed up...\n", i, j); + } + } +} + + +// However, SDL 2 *does* support hot-plugging! :-D #if 0 // Need to test this. It may be that the only time joysticks are detected is // when the program is first run. That would suck.