InputCommon and Wiimote: Detect pads in the Wiimote plugin

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2151 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-02-08 15:39:28 +00:00
parent 94d8eb5d4e
commit 2757dbe2a8
11 changed files with 86 additions and 35 deletions

View File

@ -101,6 +101,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_Wiimote", "Plugins\Plugin_Wiimote\Plugin_Wiimote.vcproj", "{8D612734-FAA5-4B8A-804F-4DEA2367D495}"
ProjectSection(ProjectDependencies) = postProject
{48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F}
{C7E5D50A-2916-464B-86A7-E10B3CC88ADA} = {C7E5D50A-2916-464B-86A7-E10B3CC88ADA}
{0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0}
{71B16F46-0B00-4EDA-B253-D6D9D03A215C} = {71B16F46-0B00-4EDA-B253-D6D9D03A215C}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}

View File

@ -67,10 +67,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib wiiuse.lib rpcrt4.lib"
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib rpcrt4.lib"
OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_WiimoteD.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\win32"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\WiiUse\win32"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="0"
@ -151,10 +151,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib wiiuse.lib rpcrt4.lib"
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib rpcrt4.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_WiimoteD.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\x64"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\WiiUse\x64"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="0"
@ -233,10 +233,10 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/NODEFAULTLIB:msvcrt.lib"
AdditionalDependencies="comctl32.lib winmm.lib wiiuse.lib"
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_Wiimote.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\win32"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\WiiUse\win32"
GenerateManifest="false"
GenerateDebugInformation="false"
SubSystem="0"
@ -316,10 +316,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib wiiuse.lib"
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_Wiimote.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\x64"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\WiiUse\x64"
GenerateManifest="false"
GenerateDebugInformation="false"
SubSystem="0"
@ -396,10 +396,10 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/NODEFAULTLIB:msvcrt.lib"
AdditionalDependencies="comctl32.lib winmm.lib wiiuse.lib"
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_WiimoteDF.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\win32"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\WiiUse\win32"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
@ -476,10 +476,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib wiiuse.lib"
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_WiimoteDF.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\x64"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\WiiUse\x64"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"

View File

@ -31,6 +31,7 @@
#include "Config.h"
#include "EmuMain.h" // for LoadRecordedMovements()
#include "EmuSubroutines.h" // for WmRequestStatus
#include "EmuDefinitions.h" // for joyinfo
//////////////////////////////////////
@ -294,11 +295,10 @@ void ConfigDialog::CreateGUIControls()
// Search for devices and add them to the device list
wxArrayString StrJoyname; // The string array
int NumGoodPads = 0;
if(NumGoodPads > 0)
if(WiiMoteEmu::NumGoodPads > 0)
{
//for(int x = 0; x < joyinfo.size(); x++)
// arrayStringFor_Joyname.Add(wxString::FromAscii(joyinfo[x].Name.c_str()));
for(int x = 0; x < WiiMoteEmu::joyinfo.size(); x++)
StrJoyname.Add(wxString::FromAscii(WiiMoteEmu::joyinfo[x].Name.c_str()));
}
else
{

View File

@ -21,10 +21,10 @@
#ifndef _EMU_DEFINITIONS_
#define _EMU_DEFINITIONS_
#include "pluginspecs_wiimote.h"
#include <vector>
#include <string>
#include "pluginspecs_wiimote.h"
#include "Common.h"
#include "wiimote_hid.h"
#include "EmuDefinitions.h"
@ -60,6 +60,12 @@ std::vector<wm_ackdelay> AckDelay; // Ackk delay
wiimote_key g_ExtKey; // The extension encryption key
bool g_Encryption; // Encryption on or off
// Gamepad input
int NumPads = 0, NumGoodPads = 0; // Number of goods pads
std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
InputCommon::CONTROLLER_STATE PadState[4];
InputCommon::CONTROLLER_MAPPING PadMapping[4];
} // namespace
#endif //_EMU_DECLARATIONS_

View File

@ -18,14 +18,16 @@
#ifndef _EMU_DECLARATIONS_
#define _EMU_DECLARATIONS_
#include "pluginspecs_wiimote.h"
#include <vector>
#include <string>
#include "Common.h"
#include "../../../Core/InputCommon/Src/SDL.h" // Core
#include "../../../Core/InputCommon/Src/XInput.h"
#include "wiimote_hid.h"
#include "Common.h"
#include "pluginspecs_wiimote.h"
#include "wiimote_hid.h" // Local
#include "Encryption.h"
#include "Logging.h" // for startConsoleWin, Console::Print, GetConsoleHwnd
@ -168,6 +170,11 @@ static const u8 partially_id[] =
0x00, 0x00, 0x00, 0x00, 0xff, 0xff
};
// Gamepad input
extern int NumPads, NumGoodPads; // Number of goods pads
extern std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
extern InputCommon::CONTROLLER_STATE PadState[4];
extern InputCommon::CONTROLLER_MAPPING PadMapping[4];
} // namespace

View File

@ -24,6 +24,9 @@
#include <vector>
#include <string>
#include "../../../Core/InputCommon/Src/SDL.h" // Core
#include "../../../Core/InputCommon/Src/XInput.h"
#include "Common.h" // Common
#include "StringUtil.h" // for ArrayToString()
#include "IniFile.h"
@ -298,6 +301,37 @@ void SetDefaultExtensionRegistry()
UpdateEeprom();
}
// ===================================================
// Fill joyinfo with the current connected devices
// ----------------
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
{
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
// Warn the user if no gamepads are detected
if (_NumGoodPads == 0 && g_EmulatorRunning)
{
//PanicAlert("nJoy: No Gamepad Detected");
//return false;
}
// Load PadMapping[] etc
g_Config.Load();
// Update the PadState[].joy handle
for (int i = 0; i < 4; i++)
{
if (PadMapping[i].enabled && joyinfo.size() > PadMapping[i].ID)
if(joyinfo.at(PadMapping[i].ID).Good)
PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID);
}
return Success;
}
// ===========================
// ===================================================
/* Write initial values to Eeprom and registers. */
// ----------------
@ -332,6 +366,9 @@ void Initialize()
g_RecordingCurrentTime[i] = 0;
}
// Load avaliable pads
Search_Devices(joyinfo, NumPads, NumGoodPads);
/* The Nuncheck extension ID for homebrew applications that use the zero key. This writes 0x0000
in encrypted form (0xfefe) to 0xfe in the extension register. */
//WriteCrypted16(g_RegExt, 0xfe, 0x0000); // Fully inserted Nunchuk

View File

@ -866,8 +866,8 @@ void DoInitialize()
MoveWindow(Console::GetHwnd(), 200,0, 130*8,70*14, true); // big wide window*/
// ---------------
// Load config settings
g_Config.Load();
// Load config settings, will be done after the SDL functions in EmuMain.cpp
//g_Config.Load();
// Run this first so that WiiMoteReal::Initialize() overwrites g_Eeprom
WiiMoteEmu::Initialize();

View File

@ -37,7 +37,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
extern bool emulator_running;
extern bool g_EmulatorRunning;
////////////////////////
/* If we don't use this hack m_MainSizer->GetMinSize().GetWidth() will not change

View File

@ -39,7 +39,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
extern bool emulator_running;
extern bool g_EmulatorRunning;
// D-Pad type
static const char* DPadType[] =
@ -161,7 +161,7 @@ void ConfigBox::OnKeyDown(wxKeyEvent& event)
void ConfigBox::OnClose(wxCloseEvent& /*event*/)
{
EndModal(0);
if(!emulator_running) Shutdown(); // Close pads, unless we are running a game
if(!g_EmulatorRunning) Shutdown(); // Close pads, unless we are running a game
}
// Call about dialog
@ -946,7 +946,7 @@ void ConfigBox::CreateGUIControls()
m_sMainRight[i]->Show(g_Config.bShowAdvanced);
// Don't allow these changes when running
if(emulator_running)
if(g_EmulatorRunning)
{
m_Joyname[i]->Enable(false);
m_Joyattach[i]->Enable(false);

View File

@ -39,7 +39,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
extern bool emulator_running;
extern bool g_EmulatorRunning;
////////////////////////

View File

@ -87,7 +87,7 @@ HINSTANCE nJoy_hInst = NULL;
std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
InputCommon::CONTROLLER_STATE PadState[4];
InputCommon::CONTROLLER_MAPPING PadMapping[4];
bool emulator_running = false;
bool g_EmulatorRunning = false;
int NumPads = 0, NumGoodPads = 0;
HWND m_hWnd; // Handle to window
SPADInitialize *g_PADInitialize = NULL;
@ -191,7 +191,7 @@ void DllConfig(HWND _hParent)
#ifdef _WIN32
// Start the pads so we can use them in the configuration and advanced controls
if(!emulator_running)
if(!g_EmulatorRunning)
{
Search_Devices(joyinfo, NumPads, NumGoodPads); // Populate joyinfo for all attached devices
}
@ -232,7 +232,7 @@ void DllDebugger(HWND _hParent, bool Show) {}
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
/* Information: This function can not be run twice without a Shutdown in between. If
it's run twice the SDL_Init() will cause a crash. One solution to this is to keep a
global function that remembers the SDL_Init() and SDL_Quit() (emulator_running does
global function that remembers the SDL_Init() and SDL_Quit() (g_EmulatorRunning does
not do that since we can open and close this without any game running). But I would
suggest that avoiding to run this twice from the Core is better. */
void Initialize(void *init)
@ -241,7 +241,7 @@ void Initialize(void *init)
//Console::Open();
Console::Print("Initialize: %i\n", SDL_WasInit(0));
g_PADInitialize = (SPADInitialize*)init;
emulator_running = true;
g_EmulatorRunning = true;
#ifdef _DEBUG
DEBUG_INIT();
@ -270,7 +270,7 @@ bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_N
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
// Warn the user if no gamepads are detected
if (_NumGoodPads == 0 && emulator_running)
if (_NumGoodPads == 0 && g_EmulatorRunning)
{
PanicAlert("nJoy: No Gamepad Detected");
return false;
@ -319,7 +319,7 @@ void Shutdown()
//joyinfo = NULL;
joyinfo.clear();
emulator_running = false;
g_EmulatorRunning = false;
#ifdef _WIN32
#ifdef USE_RUMBLE_DINPUT_HACK