mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
InputCommon and nJoy: Moved functions to InputCommon, to be shared with the Wiimote plugin
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2147 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Version="9,00"
|
||||
Name="InputCommon"
|
||||
ProjectGUID="{C7E5D50A-2916-464B-86A7-E10B3CC88ADA}"
|
||||
RootNamespace="VideoCommon"
|
||||
@ -175,7 +175,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs;..\..\..\Externals\wxWidgets\include;..\..\..\Externals\wxWidgets\lib\vc_lib\msw;..\..\..\Externals\wxWidgets\include\msvc"
|
||||
AdditionalIncludeDirectories="..\..\..\Externals\SDL\include;../../Core/Common/Src;../../PluginSpecs;..\..\..\Externals\wxWidgets\include;..\..\..\Externals\wxWidgets\lib\vc_lib\msw;..\..\..\Externals\wxWidgets\include\msvc"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
@ -411,6 +411,14 @@
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<File
|
||||
RelativePath=".\Src\Configuration.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\Configuration.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\Event.hpp"
|
||||
>
|
||||
@ -435,6 +443,22 @@
|
||||
RelativePath=".\Src\SConscript"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\SDL.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\SDL.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\XInput.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\XInput.h"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
|
0
Source/Core/InputCommon/Src/Configuration.cpp
Normal file
0
Source/Core/InputCommon/Src/Configuration.cpp
Normal file
0
Source/Core/InputCommon/Src/Configuration.h
Normal file
0
Source/Core/InputCommon/Src/Configuration.h
Normal file
234
Source/Core/InputCommon/Src/SDL.cpp
Normal file
234
Source/Core/InputCommon/Src/SDL.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Project description
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// Name: SDL Input
|
||||
// Description: Common SDL Input Functions
|
||||
//
|
||||
// Author: Falcon4ever (nJoy@falcon4ever.com, www.multigesture.net), JPeterson etc
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Licensetype: GNU General Public License (GPL)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
//
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Include
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define _SDL_MAIN_ // Avoid certain declarations in SDL.h
|
||||
#include "SDL.h" // Local
|
||||
#include "XInput.h"
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
namespace InputCommon
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Search attached devices. Populate joyinfo for all attached physical devices.
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
|
||||
{
|
||||
// Load config
|
||||
#ifdef _DEBUG
|
||||
DEBUG_INIT();
|
||||
#endif
|
||||
|
||||
/* SDL 1.3 use DirectInput instead of the old Microsoft Multimeda API, and with this we need
|
||||
the SDL_INIT_VIDEO flag to */
|
||||
if (!SDL_WasInit(0))
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
|
||||
{
|
||||
PanicAlert("Could not initialize SDL: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
fprintf(pFile, "Scanning for devices\n");
|
||||
fprintf(pFile, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
||||
#endif
|
||||
|
||||
// Get device status
|
||||
int numjoy = SDL_NumJoysticks();
|
||||
for (int i = 0; i < numjoy; i++ )
|
||||
{
|
||||
CONTROLLER_INFO Tmp;
|
||||
|
||||
Tmp.joy = SDL_JoystickOpen(i);
|
||||
Tmp.ID = i;
|
||||
Tmp.NumAxes = SDL_JoystickNumAxes(Tmp.joy);
|
||||
Tmp.NumButtons = SDL_JoystickNumButtons(Tmp.joy);
|
||||
Tmp.NumBalls = SDL_JoystickNumBalls(Tmp.joy);
|
||||
Tmp.NumHats = SDL_JoystickNumHats(Tmp.joy);
|
||||
Tmp.Name = SDL_JoystickName(i);
|
||||
|
||||
// Check if the device is okay
|
||||
if ( Tmp.NumAxes == 0
|
||||
&& Tmp.NumBalls == 0
|
||||
&& Tmp.NumButtons == 0
|
||||
&& Tmp.NumHats == 0
|
||||
)
|
||||
{
|
||||
Tmp.Good = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_NumGoodPads++;
|
||||
Tmp.Good = true;
|
||||
}
|
||||
|
||||
_joyinfo.push_back(Tmp);
|
||||
|
||||
#ifdef _DEBUG
|
||||
fprintf(pFile, "ID: %d\n", i);
|
||||
fprintf(pFile, "Name: %s\n", joyinfo[i].Name);
|
||||
fprintf(pFile, "Buttons: %d\n", joyinfo[i].NumButtons);
|
||||
fprintf(pFile, "Axes: %d\n", joyinfo[i].NumAxes);
|
||||
fprintf(pFile, "Hats: %d\n", joyinfo[i].NumHats);
|
||||
fprintf(pFile, "Balls: %d\n\n", joyinfo[i].NumBalls);
|
||||
#endif
|
||||
|
||||
// We have now read the values we need so we close the device
|
||||
if (SDL_JoystickOpened(i)) SDL_JoystickClose(_joyinfo[i].joy);
|
||||
}
|
||||
|
||||
_NumPads = _joyinfo.size();
|
||||
|
||||
return true;
|
||||
}
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Supporting functions
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// Read current joystick status
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
The value PadMapping[].buttons[] is the number of the assigned joypad button,
|
||||
PadState[].buttons[] is the status of the button, it becomes 0 (no pressed) or 1 (pressed) */
|
||||
|
||||
|
||||
// Read buttons status. Called from GetJoyState().
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void ReadButton(CONTROLLER_STATE &_PadState, CONTROLLER_MAPPING _PadMapping, int button, int NumButtons)
|
||||
{
|
||||
int ctl_button = _PadMapping.buttons[button];
|
||||
if (ctl_button < NumButtons)
|
||||
{
|
||||
_PadState.buttons[button] = SDL_JoystickGetButton(_PadState.joy, ctl_button);
|
||||
}
|
||||
}
|
||||
|
||||
// Request joystick state.
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* Called from: PAD_GetStatus()
|
||||
Input: The virtual device 0, 1, 2 or 3
|
||||
Function: Updates the PadState struct with the current pad status. The input value "controller" is
|
||||
for a virtual controller 0 to 3. */
|
||||
void GetJoyState(CONTROLLER_STATE &_PadState, CONTROLLER_MAPPING _PadMapping, int controller, int NumButtons)
|
||||
{
|
||||
// Update the gamepad status
|
||||
SDL_JoystickUpdate();
|
||||
|
||||
// Update axis states. It doesn't hurt much if we happen to ask for nonexisting axises here.
|
||||
_PadState.axis[CTL_MAIN_X] = SDL_JoystickGetAxis(_PadState.joy, _PadMapping.axis[CTL_MAIN_X]);
|
||||
_PadState.axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(_PadState.joy, _PadMapping.axis[CTL_MAIN_Y]);
|
||||
_PadState.axis[CTL_SUB_X] = SDL_JoystickGetAxis(_PadState.joy, _PadMapping.axis[CTL_SUB_X]);
|
||||
_PadState.axis[CTL_SUB_Y] = SDL_JoystickGetAxis(_PadState.joy, _PadMapping.axis[CTL_SUB_Y]);
|
||||
|
||||
// Update the analog trigger axis values
|
||||
#ifdef _WIN32
|
||||
if (_PadMapping.triggertype == CTL_TRIGGER_SDL)
|
||||
{
|
||||
#endif
|
||||
// If we are using SDL analog triggers the buttons have to be mapped as 1000 or up, otherwise they are not used
|
||||
if(_PadMapping.buttons[CTL_L_SHOULDER] >= 1000) _PadState.axis[CTL_L_SHOULDER] = SDL_JoystickGetAxis(_PadState.joy, _PadMapping.buttons[CTL_L_SHOULDER] - 1000); else _PadState.axis[CTL_L_SHOULDER] = 0;
|
||||
if(_PadMapping.buttons[CTL_R_SHOULDER] >= 1000) _PadState.axis[CTL_R_SHOULDER] = SDL_JoystickGetAxis(_PadState.joy, _PadMapping.buttons[CTL_R_SHOULDER] - 1000); else _PadState.axis[CTL_R_SHOULDER] = 0;
|
||||
#ifdef _WIN32
|
||||
}
|
||||
else
|
||||
{
|
||||
_PadState.axis[CTL_L_SHOULDER] = XInput::GetXI(0, _PadMapping.buttons[CTL_L_SHOULDER] - 1000);
|
||||
_PadState.axis[CTL_R_SHOULDER] = XInput::GetXI(0, _PadMapping.buttons[CTL_R_SHOULDER] - 1000);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update button states to on or off
|
||||
ReadButton(_PadState, _PadMapping, CTL_L_SHOULDER, NumButtons);
|
||||
ReadButton(_PadState, _PadMapping, CTL_R_SHOULDER, NumButtons);
|
||||
ReadButton(_PadState, _PadMapping, CTL_A_BUTTON, NumButtons);
|
||||
ReadButton(_PadState, _PadMapping, CTL_B_BUTTON, NumButtons);
|
||||
ReadButton(_PadState, _PadMapping, CTL_X_BUTTON, NumButtons);
|
||||
ReadButton(_PadState, _PadMapping, CTL_Y_BUTTON, NumButtons);
|
||||
ReadButton(_PadState, _PadMapping, CTL_Z_TRIGGER, NumButtons);
|
||||
ReadButton(_PadState, _PadMapping, CTL_START, NumButtons);
|
||||
|
||||
//
|
||||
if (_PadMapping.halfpress < NumButtons)
|
||||
_PadState.halfpress = SDL_JoystickGetButton(_PadState.joy, _PadMapping.halfpress);
|
||||
|
||||
// Check if we have an analog or digital joypad
|
||||
if (_PadMapping.controllertype == CTL_DPAD_HAT)
|
||||
{
|
||||
_PadState.dpad = SDL_JoystickGetHat(_PadState.joy, _PadMapping.dpad);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Only do this if the assigned button is in range (to allow for the current way of saving keyboard
|
||||
keys in the same array) */
|
||||
if(_PadMapping.dpad2[CTL_D_PAD_UP] <= NumButtons)
|
||||
_PadState.dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(_PadState.joy, _PadMapping.dpad2[CTL_D_PAD_UP]);
|
||||
if(_PadMapping.dpad2[CTL_D_PAD_DOWN] <= NumButtons)
|
||||
_PadState.dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(_PadState.joy, _PadMapping.dpad2[CTL_D_PAD_DOWN]);
|
||||
if(_PadMapping.dpad2[CTL_D_PAD_LEFT] <= NumButtons)
|
||||
_PadState.dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(_PadState.joy, _PadMapping.dpad2[CTL_D_PAD_LEFT]);
|
||||
if(_PadMapping.dpad2[CTL_D_PAD_RIGHT] <= NumButtons)
|
||||
_PadState.dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(_PadState.joy, _PadMapping.dpad2[CTL_D_PAD_RIGHT]);
|
||||
}
|
||||
|
||||
/* Debugging
|
||||
Console::ClearScreen();
|
||||
Console::Print(
|
||||
"Controller and handle: %i %i\n"
|
||||
|
||||
"Triggers:%i %i %i %i %i | HalfPress: %i Mapping: %i\n",
|
||||
|
||||
controller, (int)_PadState.joy,
|
||||
|
||||
_PadMapping.triggertype,
|
||||
_PadMapping.buttons[CTL_L_SHOULDER], _PadMapping.buttons[CTL_R_SHOULDER],
|
||||
_PadState.axis[CTL_L_SHOULDER], _PadState.axis[CTL_R_SHOULDER],
|
||||
|
||||
_PadState.halfpress, _PadMapping.halfpress
|
||||
); */
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
} // InputCommon
|
168
Source/Core/InputCommon/Src/SDL.h
Normal file
168
Source/Core/InputCommon/Src/SDL.h
Normal file
@ -0,0 +1,168 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Project description
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// Name: SDL Input
|
||||
// Description: Common SDL Input Functions
|
||||
//
|
||||
// Author: Falcon4ever (nJoy@falcon4ever.com, www.multigesture.net), JPeterson etc
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Licensetype: GNU General Public License (GPL)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
//
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _SDL_h
|
||||
#define _SDL_h
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Include
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#include <iostream> // System
|
||||
#include <vector>
|
||||
|
||||
#include <SDL.h> // Externals
|
||||
|
||||
#include "Common.h" // Common
|
||||
////////////////////////////
|
||||
|
||||
|
||||
namespace InputCommon
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Structures
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CONTROLLER_STATE buttons (PadState) = 0 or 1
|
||||
CONTROLLER_MAPPING buttons (joystick) = 0 or 1, 2, 3, 4, a certain joypad button
|
||||
|
||||
Please remember: The axis limit is hardcoded here, if you allow more axises (for
|
||||
example for analog A and B buttons) you must first incrase the size of the axis array
|
||||
size here
|
||||
*/
|
||||
struct CONTROLLER_STATE // GC PAD INFO/STATE
|
||||
{
|
||||
int buttons[8]; // Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons
|
||||
int dpad; // Automatic SDL D-Pad (8 directions + neutral)
|
||||
int dpad2[4]; // D-pad using buttons
|
||||
int axis[6]; // 2 x 2 Axes (Main & Sub)
|
||||
int halfpress; // Halfpress... you know, like not fully pressed ;)...
|
||||
SDL_Joystick *joy; // SDL joystick device
|
||||
};
|
||||
|
||||
struct CONTROLLER_MAPPING // GC PAD MAPPING
|
||||
{
|
||||
int buttons[8]; // (See above)
|
||||
int dpad; // (See above)
|
||||
int dpad2[4]; // (See above)
|
||||
int axis[6]; // (See above)
|
||||
int halfpress; // (See above)
|
||||
int enabled; // Pad attached?
|
||||
int deadzone; // Deadzone... what else?
|
||||
int ID; // SDL joystick device ID
|
||||
int controllertype; // Hat: Hat or custom buttons
|
||||
int triggertype; // Triggers range
|
||||
std::string SDiagonal;
|
||||
bool bSquareToCircle;
|
||||
int eventnum; // Linux Event Number, Can't be found dynamically yet
|
||||
};
|
||||
|
||||
struct CONTROLLER_INFO // CONNECTED WINDOWS DEVICES INFO
|
||||
{
|
||||
int NumAxes; // Amount of Axes
|
||||
int NumButtons; // Amount of Buttons
|
||||
int NumBalls; // Amount of Balls
|
||||
int NumHats; // Amount of Hats (POV)
|
||||
std::string Name; // Joypad/stickname
|
||||
int ID; // SDL joystick device ID
|
||||
bool Good; // Pad is good (it has at least one button or axis)
|
||||
SDL_Joystick *joy; // SDL joystick device
|
||||
};
|
||||
enum
|
||||
{
|
||||
// CTL_L_SHOULDER and CTL_R_SHOULDER = 0 and 1
|
||||
CTL_MAIN_X = 2,
|
||||
CTL_MAIN_Y,
|
||||
CTL_SUB_X,
|
||||
CTL_SUB_Y
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CTL_L_SHOULDER = 0,
|
||||
CTL_R_SHOULDER,
|
||||
CTL_A_BUTTON,
|
||||
CTL_B_BUTTON,
|
||||
CTL_X_BUTTON,
|
||||
CTL_Y_BUTTON,
|
||||
CTL_Z_TRIGGER,
|
||||
CTL_START
|
||||
};
|
||||
// DPad Type
|
||||
enum
|
||||
{
|
||||
CTL_DPAD_HAT = 0, // Automatically use the first hat that SDL finds
|
||||
CTL_DPAD_CUSTOM // Custom directional pad settings
|
||||
};
|
||||
// Trigger Type
|
||||
enum
|
||||
{
|
||||
CTL_TRIGGER_SDL = 0, //
|
||||
CTL_TRIGGER_XINPUT // The XBox 360 pad
|
||||
};
|
||||
enum
|
||||
{
|
||||
CTL_D_PAD_UP = 0,
|
||||
CTL_D_PAD_DOWN,
|
||||
CTL_D_PAD_LEFT,
|
||||
CTL_D_PAD_RIGHT
|
||||
};
|
||||
// Button type for the configuration
|
||||
enum
|
||||
{
|
||||
CTL_AXIS = 0,
|
||||
CTL_HAT,
|
||||
CTL_BUTTON,
|
||||
CTL_KEY
|
||||
};
|
||||
// XInput buttons
|
||||
enum
|
||||
{
|
||||
XI_TRIGGER_L = 0,
|
||||
XI_TRIGGER_R
|
||||
};
|
||||
////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Declarations
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &NumPads, int &NumGoodPads);
|
||||
void GetJoyState(CONTROLLER_STATE &_PadState, CONTROLLER_MAPPING _PadMapping, int controller, int NumButtons);
|
||||
|
||||
#ifndef _SDL_MAIN_
|
||||
|
||||
#endif
|
||||
////////////////////////////
|
||||
|
||||
|
||||
} // InputCommon
|
||||
|
||||
|
||||
#endif // _SDL_h
|
136
Source/Core/InputCommon/Src/XInput.cpp
Normal file
136
Source/Core/InputCommon/Src/XInput.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Licensetype: GNU General Public License (GPL)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
//
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// File description
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Function: This file will get the status of the analog triggers of any connected XInput device.
|
||||
This code was made with the help of SimpleController.cpp in the June 2008 Microsoft DirectX SDK
|
||||
Samples.
|
||||
|
||||
///////////////////////////////////////////////////// */
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Includes
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#include <windows.h>
|
||||
#include <XInput.h> // XInput API
|
||||
|
||||
#include "SDL.h" // Local
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace XInput
|
||||
{
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Declarations
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
#define MAX_CONTROLLERS 4 // XInput handles up to 4 controllers
|
||||
|
||||
struct CONTROLER_STATE
|
||||
{
|
||||
XINPUT_STATE state;
|
||||
bool bConnected;
|
||||
};
|
||||
CONTROLER_STATE g_Controllers[MAX_CONTROLLERS];
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Init
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* Function: Calculate the number of connected XInput devices
|
||||
Todo: Implement this to figure out if there are multiple XInput controllers connected,
|
||||
we currently only try to connect to XInput device 0 */
|
||||
void Init()
|
||||
{
|
||||
// Init state
|
||||
//ZeroMemory( g_Controllers, sizeof( CONTROLER_STATE ) * MAX_CONTROLLERS );
|
||||
|
||||
// Declaration
|
||||
DWORD dwResult;
|
||||
|
||||
// Calculate the number of connected XInput devices
|
||||
for( DWORD i = 0; i < MAX_CONTROLLERS; i++ )
|
||||
{
|
||||
// Simply get the state of the controller from XInput.
|
||||
dwResult = XInputGetState( i, &g_Controllers[i].state );
|
||||
|
||||
if( dwResult == ERROR_SUCCESS )
|
||||
g_Controllers[i].bConnected = true;
|
||||
else
|
||||
g_Controllers[i].bConnected = false;
|
||||
}
|
||||
|
||||
}
|
||||
///////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get the trigger status
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int GetXI(int Controller, int Button)
|
||||
{
|
||||
// Update the internal status
|
||||
DWORD dwResult;
|
||||
dwResult = XInputGetState( Controller, &g_Controllers[Controller].state );
|
||||
|
||||
if( dwResult != ERROR_SUCCESS ) return -1;
|
||||
|
||||
switch(Button)
|
||||
{
|
||||
case InputCommon::XI_TRIGGER_L:
|
||||
return g_Controllers[0].state.Gamepad.bLeftTrigger;
|
||||
|
||||
case InputCommon::XI_TRIGGER_R:
|
||||
return g_Controllers[0].state.Gamepad.bRightTrigger;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Check if a certain controller is connected
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool IsConnected(int Controller)
|
||||
{
|
||||
DWORD dwResult = XInputGetState( Controller, &g_Controllers[Controller].state );
|
||||
|
||||
// Update the connected status
|
||||
if( dwResult == ERROR_SUCCESS )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
///////////////////////////////////////////
|
||||
|
||||
} // XInput
|
||||
|
||||
#endif
|
45
Source/Core/InputCommon/Src/XInput.h
Normal file
45
Source/Core/InputCommon/Src/XInput.h
Normal file
@ -0,0 +1,45 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Licensetype: GNU General Public License (GPL)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
//
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Includes
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#include <iostream>
|
||||
//////////////////////////////
|
||||
|
||||
|
||||
|
||||
namespace XInput
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Declarations
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void Init();
|
||||
int GetXI(int Controller, int Button);
|
||||
bool IsConnected(int Controller);
|
||||
//////////////////////////////
|
||||
|
||||
} // XInput
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user