]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/gamepad.cpp
Fix for PS3 controllers.
[virtualjaguar] / src / gui / gamepad.cpp
index b8ebdde5c21a8bf9827d906b2ac92508c2e0c3b2..873e3b5ad9a81d2efc0f3f7c186a256336fa2d22 100644 (file)
@@ -64,6 +64,15 @@ void Gamepad::AllocateJoysticks(void)
                        numHats[i] = SDL_JoystickNumHats(pad[i]);
                        numAxes[i] = SDL_JoystickNumAxes(pad[i]);
                        WriteLog("Gamepad: Joystick #%i: %s\n", i, padName[i]);
+
+                       // Ick, kludges already!!!
+                       if (strcmp(padName[i], "Sony PLAYSTATION(R)3 Controller") == 0)
+                       {
+                               // We do this because these axes stay stuck on -32000 (buttons)
+                               // or come on and stay on (D-pad). :-P
+                               numAxes[i] = 8;
+                               WriteLog("Gamepad: Blacklisting PS3 controller axes 8 on up...\n");
+                       }
                }
        }
 
@@ -137,9 +146,10 @@ bool Gamepad::GetState(int joystickID, int buttonID)
 }
 
 
-//UNUSED
 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 };
@@ -211,6 +221,83 @@ void Gamepad::Update(void)
 }
 
 
+void Gamepad::DumpJoystickStatesToLog(void)
+{
+       bool pressed = false;
+
+       for(int i=0; i<numJoysticks; i++)
+       {
+               for(int j=0; j<numButtons[i]; j++)
+               {
+                       if (button[i][j])
+                       {
+                               pressed = true;
+                               break;
+                               break;
+                       }
+               }
+
+               for(int j=0; j<numHats[i]; j++)
+               {
+                       if (hat[i][j])
+                       {
+                               pressed = true;
+                               break;
+                               break;
+                       }
+               }
+
+               for(int j=0; j<numAxes[i]; j++)
+               {
+                       // We encode these as axis # (in bits 1-15), up or down in bit 0.
+                       if (axis[i][j] > 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<numJoysticks; i++)
+       {
+               for(int j=0; j<numButtons[i]; j++)
+               {
+                       if (button[i][j])
+                               WriteLog("Gamepad: Pad #%i, button %i down...\n", i, j);
+               }
+
+               for(int j=0; j<numHats[i]; j++)
+               {
+                       if (hat[i][j])
+                               WriteLog("Gamepad: Pad #%i, hat %i pushed...\n", i, j);
+               }
+
+               for(int j=0; j<numAxes[i]; j++)
+               {
+                       // We encode these as axis # (in bits 1-15), up or down in bit 0.
+                       if (axis[i][j] > 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