nJoy: Made it tolerate a bad device (the Wiimote DirectInput device for example)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2003 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson
2009-01-24 22:13:53 +00:00
parent 2a13bedfc8
commit a3c383ad4a
8 changed files with 278 additions and 241 deletions

View File

@ -37,7 +37,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
extern CONTROLLER_INFO *joyinfo;
//extern CONTROLLER_INFO *joyinfo;
extern bool emulator_running;
////////////////////////
@ -82,10 +82,10 @@ void ConfigBox::PadGetStatus()
//int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone+1));
// Get original values
int main_x = joystate[notebookpage].axis[CTL_MAIN_X];
int main_y = joystate[notebookpage].axis[CTL_MAIN_Y];
//int sub_x = (joystate[_numPAD].axis[CTL_SUB_X];
//int sub_y = -(joystate[_numPAD].axis[CTL_SUB_Y];
int main_x = PadState[notebookpage].axis[CTL_MAIN_X];
int main_y = PadState[notebookpage].axis[CTL_MAIN_Y];
//int sub_x = (PadState[_numPAD].axis[CTL_SUB_X];
//int sub_y = -(PadState[_numPAD].axis[CTL_SUB_Y];
// Get adjusted values
int main_x_after = main_x, main_y_after = main_y;
@ -131,7 +131,7 @@ void ConfigBox::PadGetStatus()
// Triggers
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int TriggerValue = 255;
if (joystate[notebookpage].halfpress) TriggerValue = 100;
if (PadState[notebookpage].halfpress) TriggerValue = 100;
// Get the selected keys
long Left, Right;
@ -139,8 +139,8 @@ void ConfigBox::PadGetStatus()
m_JoyShoulderR[notebookpage]->GetValue().ToLong(&Right);
// Get the trigger values
int TriggerLeft = joystate[notebookpage].axis[CTL_L_SHOULDER];
int TriggerRight = joystate[notebookpage].axis[CTL_R_SHOULDER];
int TriggerLeft = PadState[notebookpage].axis[CTL_L_SHOULDER];
int TriggerRight = PadState[notebookpage].axis[CTL_R_SHOULDER];
// Convert the triggers values
if (PadMapping[notebookpage].triggertype == CTL_TRIGGER_SDL)
@ -154,8 +154,8 @@ void ConfigBox::PadGetStatus()
if(Right < 1000) TriggerRight = 0;
// Get the digital values
if(Left < 1000 && joystate[notebookpage].buttons[CTL_L_SHOULDER]) TriggerLeft = TriggerValue;
if(Right < 1000 && joystate[notebookpage].buttons[CTL_R_SHOULDER]) TriggerRight = TriggerValue;
if(Left < 1000 && PadState[notebookpage].buttons[CTL_L_SHOULDER]) TriggerLeft = TriggerValue;
if(Right < 1000 && PadState[notebookpage].buttons[CTL_R_SHOULDER]) TriggerRight = TriggerValue;
m_TStatusTriggers[notebookpage]->SetLabel(wxString::Format(
wxT("Left:%03i Right:%03i"),
@ -175,13 +175,13 @@ std::string ShowStatus(int VirtualController)
int PhysicalDevice = PadMapping[VirtualController].ID;
// Make local shortcut
SDL_Joystick *joy = joystate[VirtualController].joy;
SDL_Joystick *joy = PadState[VirtualController].joy;
// Make shortcuts for all pads
SDL_Joystick *joy0 = joystate[PadMapping[0].ID].joy;
SDL_Joystick *joy1 = joystate[PadMapping[1].ID].joy;
SDL_Joystick *joy2 = joystate[PadMapping[2].ID].joy;
SDL_Joystick *joy3 = joystate[PadMapping[3].ID].joy;
SDL_Joystick *joy0 = PadState[0].joy;
SDL_Joystick *joy1 = PadState[1].joy;
SDL_Joystick *joy2 = PadState[2].joy;
SDL_Joystick *joy3 = PadState[3].joy;
// Temporary storage
std::string StrAxes, StrHats, StrBut;
@ -215,20 +215,23 @@ std::string ShowStatus(int VirtualController)
return StringFromFormat(
"PadMapping\n"
"Enabled: %i %i %i %i\n"
"ID: %i %i %i %i\n"
"Controllertype: %i %i %i %i\n"
"SquareToCircle: %i %i %i %i\n\n"
"Handles: %i %i %i %i\n"
"Handles: %p %p %p %p\n"
"XInput: %i %i %i\n"
"Axes: %s\n"
"Hats: %s\n"
"But: %s\n"
"Device: Ax: %i Balls:%i But:%i Hats:%i",
"Device: Ax: %i Balls:%i Hats:%i But:%i",
PadMapping[0].enabled, PadMapping[1].enabled, PadMapping[2].enabled, PadMapping[3].enabled,
PadMapping[0].ID, PadMapping[1].ID, PadMapping[2].ID, PadMapping[3].ID,
PadMapping[0].controllertype, PadMapping[1].controllertype, PadMapping[2].controllertype, PadMapping[3].controllertype,
PadMapping[0].bSquareToCircle, PadMapping[1].bSquareToCircle, PadMapping[2].bSquareToCircle, PadMapping[3].bSquareToCircle,
joy0, joy1, joy2, joy3,
//PadState[PadMapping[0].ID].joy, PadState[PadMapping[1].ID].joy, PadState[PadMapping[2].ID].joy, PadState[PadMapping[3].ID].joy,
#ifdef _WIN32
XInput::IsConnected(0), XInput::GetXI(0, XI_TRIGGER_L), XInput::GetXI(0, XI_TRIGGER_R),
@ -242,14 +245,18 @@ std::string ShowStatus(int VirtualController)
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::Update()
{
if(StrangeHack) PadGetStatus();
if(!g_Config.bShowAdvanced) StrangeHack = false; else StrangeHack = true;
// Show the current status
/*
/**/
m_pStatusBar->SetLabel(wxString::Format(
"%s", ShowStatus(notebookpage).c_str()
));*/
));
Console::Print("3: %p\n", PadState[PadMapping[3].ID].joy);
//LogMsg("Abc%s\n", ShowStatus(notebookpage).c_str());
if(StrangeHack) PadGetStatus();
if(!g_Config.bShowAdvanced) StrangeHack = false; else StrangeHack = true;
}

View File

@ -39,7 +39,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
extern CONTROLLER_INFO *joyinfo;
//extern CONTROLLER_INFO *joyinfo;
//extern CONTROLLER_MAPPING PadMapping[4];
extern bool emulator_running;
@ -116,7 +116,7 @@ ConfigBox::ConfigBox(wxWindow *parent, wxWindowID id, const wxString &title,
// Define values
notebookpage = 0;
g_Pressed = 0;
Debugging = false;
Debugging = true;
m_TCDebugging = NULL;
ControlsCreated = false;
@ -216,23 +216,21 @@ void ConfigBox::CancelClick(wxCommandEvent& event)
void ConfigBox::LogMsg(const char* format, ...)
{
#ifdef _WIN32
/*
if(Debugging)
{
const int MaxMsgSize = 1024*2;
char buffer[MaxMsgSize];
va_list args;
va_start(args, format);
CharArrayFromFormatV(buffer, MaxMsgSize, format, args);
va_end(args);
if(Debugging)
{
const int MaxMsgSize = 1024*2;
char buffer[MaxMsgSize];
va_list args;
va_start(args, format);
CharArrayFromFormatV(buffer, MaxMsgSize, format, args);
va_end(args);
// Add timestamp
std::string StrTmp = buffer;
//StrTmp += Common::Timer::GetTimeFormatted();
// Add timestamp
std::string StrTmp = buffer;
//StrTmp += Common::Timer::GetTimeFormatted();
if(m_TCDebugging) m_TCDebugging->AppendText(StrTmp.c_str());
}
*/
if(m_TCDebugging) m_TCDebugging->AppendText(StrTmp.c_str());
}
#endif
}
@ -292,11 +290,11 @@ void ConfigBox::OnSaveById()
// Change Joystick
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* Function: When changing the joystick we save and load the settings and update the PadMapping
and joystate array */
and PadState array */
void ConfigBox::DoChangeJoystick()
{
// Close the current pad
if (PadMapping[notebookpage].enabled) PadClose(notebookpage);
// Close the current pad, unless it's used by another slot
//if (PadMapping[notebookpage].enabled) PadClose(notebookpage);
// Before changing the pad we save potential changes to the current pad (to support SaveByID)
DoSave(true);
@ -310,11 +308,19 @@ void ConfigBox::DoChangeJoystick()
}
void ConfigBox::PadOpen(int Open) // Open for slot 1, 2, 3 or 4
{
joystate[Open].joy = SDL_JoystickOpen(PadMapping[Open].ID);
// Check that we got a good pad
if (!joyinfo.at(PadMapping[Open].ID).Good)
{
PadState[Open].joy = NULL;
return;
}
PadState[Open].joy = SDL_JoystickOpen(PadMapping[Open].ID);
}
void ConfigBox::PadClose(int Close) // Close for slot 1, 2, 3 or 4
{
if (SDL_JoystickOpened(PadMapping[Close].ID)) SDL_JoystickClose(joystate[Close].joy);
if (SDL_JoystickOpened(PadMapping[Close].ID)) SDL_JoystickClose(PadState[Close].joy);
PadState[Close].joy = NULL;
}
// Notebook page changed
@ -496,6 +502,8 @@ void ConfigBox::OnPaint( wxPaintEvent &event )
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::CreateGUIControls()
{
Console::Print("CreateGUIControls()\n");
#ifndef _DEBUG
SetTitle(wxT("Configure: nJoy v"INPUT_VERSION" Input Plugin"));
#else
@ -547,9 +555,9 @@ void ConfigBox::CreateGUIControls()
// Search for devices and add them to the device list
// -----------------------------
wxArrayString arrayStringFor_Joyname; // The string array
if(SDL_NumJoysticks() > 0)
if(NumGoodPads > 0)
{
for(int x = 0; x < SDL_NumJoysticks(); x++)
for(int x = 0; x < joyinfo.size(); x++)
{
arrayStringFor_Joyname.Add(wxString::FromAscii(joyinfo[x].Name.c_str()));
}
@ -919,15 +927,15 @@ void ConfigBox::CreateGUIControls()
// --------------------------------------------------------------------
// Debugging
// -----------------------------
/*m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(135, 100), wxDefaultSize);
m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(135, 100), wxDefaultSize);
//m_pStatusBar2 = new wxStaticText(this, IDT_DEBUGGING2, wxT("Debugging2"), wxPoint(125, 200), wxDefaultSize);
//m_pStatusBar->SetLabel(wxString::Format("Debugging text"));*/
//m_pStatusBar->SetLabel(wxString::Format("Debugging text"));
/*m_TCDebugging = new wxTextCtrl(this, IDT_DEBUGGING3, _T(""), wxDefaultPosition, wxSize(400, 400),
/**/m_TCDebugging = new wxTextCtrl(this, IDT_DEBUGGING3, _T(""), wxDefaultPosition, wxSize(400, 400),
wxTE_RICH | wxTE_MULTILINE | wxTE_DONTWRAP | wxNO_BORDER);
wxBoxSizer * m_LogSizer = new wxBoxSizer(wxVERTICAL);
m_LogSizer->Add(m_TCDebugging, 0, wxEXPAND | (wxALL), 0);
m_MainSizer->Add(m_LogSizer, 0, wxEXPAND | ( wxLEFT | wxRIGHT | wxBOTTOM), 5);*/
m_MainSizer->Add(m_LogSizer, 0, wxEXPAND | ( wxLEFT | wxRIGHT | wxBOTTOM), 5);
// --------------------------------------------------------------------
// Set window size
@ -937,6 +945,8 @@ void ConfigBox::CreateGUIControls()
// All done
ControlsCreated = true;
Console::Print("CreateGUIControls() end\n");
}
void ConfigBox::SizeWindow()

View File

@ -39,8 +39,6 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
extern CONTROLLER_INFO *joyinfo;
//extern CONTROLLER_MAPPING PadMapping[4];
extern bool emulator_running;
////////////////////////
@ -387,7 +385,10 @@ void ConfigBox::DoGetButtons(int GetId)
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;
@ -398,20 +399,20 @@ void ConfigBox::DoGetButtons(int GetId)
}
// Check for a XInput trigger
#ifdef _WIN32
if(XInput)
{
for(int i = 0; i <= XI_TRIGGER_R; i++)
{
if(XInput::GetXI(0, i))
{
pressed = i + 1000;
type = CTL_AXIS;
Succeed = true;
#ifdef _WIN32
if(XInput)
{
for(int i = 0; i <= XI_TRIGGER_R; i++)
{
if(XInput::GetXI(0, i))
{
pressed = i + 1000;
type = CTL_AXIS;
Succeed = true;
}
}
}
}
#endif
#endif
// Check for keyboard action
if (g_Pressed && Button)