From 1fbebb4ce15b04872a698c8fd6c7f1335ac978b0 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Mon, 9 Feb 2009 13:10:29 +0000 Subject: Wiimote: Configure gamepad in Wiimote plugin git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2172 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/InputCommon/Src/SDL.cpp | 130 ++++++++++++++++++++++++++++++++++++ Source/Core/InputCommon/Src/SDL.h | 30 +++++++++ 2 files changed, 160 insertions(+) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/SDL.cpp b/Source/Core/InputCommon/Src/SDL.cpp index 286ccf0fc1..67c4b97b31 100644 --- a/Source/Core/InputCommon/Src/SDL.cpp +++ b/Source/Core/InputCommon/Src/SDL.cpp @@ -231,4 +231,134 @@ void GetJoyState(CONTROLLER_STATE &_PadState, CONTROLLER_MAPPING _PadMapping, in + +////////////////////////////////////////////////////////////////////////////////////////// +// Configure button mapping +// ŻŻŻŻŻŻŻŻŻŻ + +// Avoid extreme axis values +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +/* Function: We have to avoid very big values to becuse some triggers are -0x8000 in the + unpressed state (and then go from -0x8000 to 0x8000 as they are fully pressed) */ +bool AvoidValues(int value) +{ + // Avoid detecting very small or very big (for triggers) values + if( (value > -0x2000 && value < 0x2000) // Small values + || (value < -0x6000 || value > 0x6000)) // Big values + return true; // Avoid + else + return false; // Keep +} + + +// Detect a pressed button +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void GetButton(SDL_Joystick *joy, int ControllerID, int buttons, int axes, int hats, + int &KeyboardKey, int &value, int &type, int &pressed, bool &Succeed, bool &Stop, + bool LeftRight, bool Axis, bool XInput, bool Button, bool Hat) +{ + // It needs the wxWidgets excape keycode + static const int WXK_ESCAPE = 27; + + // Update the internal status + SDL_JoystickUpdate(); + + // For the triggers we accept both a digital or an analog button + if(Axis) + { + for(int i = 0; i < axes; i++) + { + value = SDL_JoystickGetAxis(joy, i); + + if(AvoidValues(value)) continue; // Avoid values + + pressed = i + (LeftRight ? 1000 : 0); // Identify the analog triggers + type = InputCommon::CTL_AXIS; + Succeed = true; + } + Console::Print("Id: %i\n", joy); + } + + // Check for a hat + if(Hat) + { + for(int i = 0; i < hats; i++) + { + if(SDL_JoystickGetHat(joy, i)) + { + pressed = i; + type = InputCommon::CTL_HAT; + Succeed = true; + } + } + } + + // Check for a button + if(Button) + { + for(int i = 0; i < buttons; i++) + { + // Some kind of bug in SDL 1.3 would give button 9 and 10 (nonexistent) the value 48 on the 360 pad + if (SDL_JoystickGetButton(joy, i) > 1) continue; + + if(SDL_JoystickGetButton(joy, i)) + { + pressed = i; + type = InputCommon::CTL_BUTTON; + Succeed = true; + } + } + } + + // Check for a XInput trigger + #ifdef _WIN32 + if(XInput) + { + for(int i = 0; i <= InputCommon::XI_TRIGGER_R; i++) + { + if(XInput::GetXI(0, i)) + { + pressed = i + 1000; + type = InputCommon::CTL_AXIS; + Succeed = true; + } + } + } + #endif + + // Check for keyboard action + if (KeyboardKey) + { + if(Button) + { + // Todo: Add a separate keyboard vector to remove this restriction + if(KeyboardKey >= buttons) + { + pressed = KeyboardKey; + type = InputCommon::CTL_BUTTON; + Succeed = true; + KeyboardKey = 0; + if(pressed == WXK_ESCAPE) pressed = -1; // Check for the escape key + } + // Else show the error message + else + { + pressed = KeyboardKey; + KeyboardKey = -1; + Stop = true; + } + } + // Only accept the escape key + else + { + Succeed = true; + KeyboardKey = 0; + pressed = -1; + } + } +} +/////////////////////////////////////////////////////////// Configure button mapping + + + } // InputCommon \ No newline at end of file diff --git a/Source/Core/InputCommon/Src/SDL.h b/Source/Core/InputCommon/Src/SDL.h index 02305df771..3fb9d8b06d 100644 --- a/Source/Core/InputCommon/Src/SDL.h +++ b/Source/Core/InputCommon/Src/SDL.h @@ -41,6 +41,7 @@ #include // Externals #include "Common.h" // Common +#include "ConsoleWindow.h" //////////////////////////// @@ -148,6 +149,34 @@ enum XI_TRIGGER_L = 0, XI_TRIGGER_R }; + + +struct PadAxis +{ + int Lx; + int Ly; + int Rx; + int Ry; + int Tl; // Triggers + int Tr; +}; +struct CONTROLLER_STATE_NEW // GC PAD INFO/STATE +{ + PadAxis Axis; // 6 Axes (Main, Sub, Triggers) + SDL_Joystick *joy; // SDL joystick device +}; + +struct CONTROLLER_MAPPING_NEW // GC PAD MAPPING +{ + PadAxis Axis; // (See above) + bool enabled; // Pad attached? + int deadzone; // Deadzone... what else? + int ID; // SDL joystick device ID + int controllertype; // D-Pad type: Hat or custom buttons + int triggertype; // SDL or XInput trigger + std::string SDiagonal; + bool bSquareToCircle; +}; //////////////////////////// @@ -158,6 +187,7 @@ enum // General functions bool SearchDevices(std::vector &_joyinfo, int &NumPads, int &NumGoodPads); void GetJoyState(CONTROLLER_STATE &_PadState, CONTROLLER_MAPPING _PadMapping, int controller, int NumButtons); +void GetButton(SDL_Joystick*, int,int,int,int, int&,int&,int&,int&,bool&,bool&, bool,bool,bool,bool,bool); // Value conversion int Pad_Convert(int _val); -- cgit v1.2.3