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

@ -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();