Wiimote and nJoy > Gamepad changes

1. Added LiveUpdates, while the configuration window is open nJoy and Wiimote will check for connected/disconnected pads
2. Removed the 'Nintendo RVL-CNT-01' device from the device list, and other SDL devices with no axes/buttons
3. Added SDL (from the current SVN) to get debugging information for SDL.dll
4. Added 'Upright Wiimote' option to emulated Wiimote options

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4534 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson
2009-11-12 18:57:35 +00:00
parent b858befba2
commit 71506bc0f7
590 changed files with 197210 additions and 17135 deletions

View File

@ -46,6 +46,7 @@ Config::Config()
{
// Clear the memory
//memset(this, 0, sizeof(Config));
Loaded = false;
}
@ -95,7 +96,7 @@ void DEBUG_QUIT()
void Config::Save(int Slot)
{
// If there are no good pads don't save
if (NumGoodPads == 0) return;
if (NumPads == 0) return;
// Load ini file
IniFile file;
@ -127,22 +128,27 @@ void Config::Save(int Slot)
// Save the physical device ID
file.Set(SectionName.c_str(), "joy_id", PadMapping[i].ID);
file.Set(SectionName.c_str(), "joy_name", PadMapping[i].Name);
// ===================
// ==================================================================
// Joypad or slot specific settings
// -----------------
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: joyinfo[PadMapping[i].ID].Name
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: IDToName(PadMapping[i].ID])
if(g_Config.bSaveByID)
{
/* Save joypad specific settings. Check for "PadMapping[i].ID < SDL_NumJoysticks()" to
avoid reading a joyinfo that does't exist */
if((u32)PadMapping[i].ID >= joyinfo.size()) continue;
// Create a new section name after the joypad name
SectionName = joyinfo[PadMapping[i].ID].Name;
SectionName = IDToName(PadMapping[i].ID);
// Don't save a blank name
if (SectionName == "")
{
ERROR_LOG(PAD, "ID %i has no name, will not save", PadMapping[i].ID);
continue;
}
}
NOTICE_LOG(PAD, "Save settings for ID %i '%s' from PadMapping[%i]", PadMapping[i].ID, SectionName.c_str(), i);
file.Set(SectionName.c_str(), "l_shoulder", PadMapping[i].buttons[InputCommon::CTL_L_SHOULDER]);
file.Set(SectionName.c_str(), "r_shoulder", PadMapping[i].buttons[InputCommon::CTL_R_SHOULDER]);
@ -180,8 +186,6 @@ void Config::Save(int Slot)
file.Set(SectionName.c_str(), "SquareToCircleC", PadMapping[i].bSquareToCircleC);
}
INFO_LOG(CONSOLE, "%i: Save: %i\n", 0, PadMapping[0].halfpress);
file.Save(FULL_CONFIG_DIR "nJoy.ini");
}
@ -189,8 +193,7 @@ void Config::Save(int Slot)
// -----------------------
void Config::Load(bool ChangePad, bool ChangeSaveByID)
{
// If there are no good pads don't load
if (NumGoodPads == 0) return;
Loaded = true;
// Load file
IniFile file;
@ -211,6 +214,9 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
}
// =============
// If there are no good pads don't load anymore
if (NumPads == 0) return;
for (int i = 0; i < 4; i++)
{
std::string SectionName = StringFromFormat("PAD%i", i+1);
@ -219,23 +225,32 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
if (!ChangePad)
{
file.Get(SectionName.c_str(), "joy_id", &PadMapping[i].ID, 0);
file.Get(SectionName.c_str(), "joy_name", &PadMapping[i].Name, "");
}
// ==================================================================
// Joypad or slot specific settings
// -----------------
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: joyinfo[PadMapping[i].ID].Name
if(g_Config.bSaveByID)
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: IDToName(PadMapping[i].ID)
if (g_Config.bSaveByID)
{
// Prevent a crash from illegal access to joyinfo that will only have values for
// the current amount of connected pads
if((u32)PadMapping[i].ID >= joyinfo.size()) continue;
// Create a section name
SectionName = joyinfo[PadMapping[i].ID].Name;
SectionName = PadMapping[i].Name;
// Don't load settings for a non-connected device
if (!IsConnected(SectionName))
{
ERROR_LOG(PAD, "Slot %i: The device '%s' is not connected, will not load settings", SectionName.c_str());
continue;
}
// Don't load a blank ID
if (SectionName == "")
{
ERROR_LOG(PAD, "Slot %i has no device name, will not load settings", i);
continue;
}
}
file.Get(SectionName.c_str(), "l_shoulder", &PadMapping[i].buttons[InputCommon::CTL_L_SHOULDER], 4);
file.Get(SectionName.c_str(), "r_shoulder", &PadMapping[i].buttons[InputCommon::CTL_R_SHOULDER], 5);
file.Get(SectionName.c_str(), "a_button", &PadMapping[i].buttons[InputCommon::CTL_A_BUTTON], 0);
@ -269,8 +284,11 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
file.Get(SectionName.c_str(), "RadiusOnOffC", &Tmp, false); PadMapping[i].bRadiusOnOffC = Tmp;
file.Get(SectionName.c_str(), "DiagonalC", &PadMapping[i].SDiagonalC, "100%");
file.Get(SectionName.c_str(), "SquareToCircleC", &Tmp, false); PadMapping[i].bSquareToCircleC = Tmp;
NOTICE_LOG(PAD, "Slot %i: Load settings for ID %i '%s'", i, PadMapping[i].ID, SectionName.c_str());
}
INFO_LOG(CONSOLE, "%i: Load: %i\n", 0, PadMapping[0].halfpress);
//INFO_LOG(PAD, "%i: Load: %i\n", 0, PadMapping[0].halfpress);
}

View File

@ -23,9 +23,10 @@ struct Config
Config();
void Load(bool ChangePad = false, bool ChangeSaveByID = false);
void Save(int Slot = -1);
bool Loaded;
int CheckForDuplicateJoypads(bool OK);
// General
// Settings
bool bShowAdvanced; // Only allow one of these
bool bSaveByID;
bool bCheckFocus;

View File

@ -1,4 +1,3 @@
// Project description
// -------------------
// Name: nJoy
@ -32,14 +31,15 @@
// ---------
#include "ConfigBox.h"
#include "../nJoy.h"
#include "LogManager.h"
#include "Images/controller.xpm"
extern bool g_EmulatorRunning;
// Set PAD status
// --------------
void PADConfigDialognJoy::PadGetStatus()
{
void PADConfigDialognJoy::PadShowStatus()
{
// Return if it's not detected. The ID should never be less than zero here, it can only be that
// because of a manual ini file change, but we make that check anway.
if(PadMapping[notebookpage].ID < 0 || PadMapping[notebookpage].ID >= SDL_NumJoysticks())
@ -51,7 +51,7 @@ void PADConfigDialognJoy::PadGetStatus()
}
// Get physical device status
int PhysicalDevice = PadMapping[notebookpage].ID;
int ID = PadMapping[notebookpage].ID;
int TriggerType = PadMapping[notebookpage].triggertype;
// Get original values
@ -105,7 +105,6 @@ void PADConfigDialognJoy::PadGetStatus()
m_bmpDotOutC[notebookpage]->SetPosition(wxPoint(sub_x_out, sub_y_out));
///////////////////// Analog stick
// Triggers
// -----------------
@ -143,84 +142,12 @@ void PADConfigDialognJoy::PadGetStatus()
///////////////////// Triggers
}
// Show the current pad status
// -----------------
std::string ShowStatus(int VirtualController)
{
// Save the physical device
int PhysicalDevice = PadMapping[VirtualController].ID;
// Make local shortcut
SDL_Joystick *joy = PadState[VirtualController].joy;
// Make shortcuts for all pads
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;
int value;
// Get status
int Axes = joyinfo[PhysicalDevice].NumAxes;
int Balls = joyinfo[PhysicalDevice].NumBalls;
int Hats = joyinfo[PhysicalDevice].NumHats;
int Buttons = joyinfo[PhysicalDevice].NumButtons;
// Update the internal values
SDL_JoystickUpdate();
// Go through all axes and read out their values
for(int i = 0; i < Axes; i++)
{
value = SDL_JoystickGetAxis(joy, i);
StrAxes += StringFromFormat(" %i:%06i", i, value);
}
for(int i = 0;i < Hats; i++)
{
value = SDL_JoystickGetHat(joy, i);
StrHats += StringFromFormat(" %i:%i", i, value);
}
for(int i = 0;i < Buttons; i++)
{
value = SDL_JoystickGetButton(joy, i);
StrBut += StringFromFormat(" %i:%i", i+1, value);
}
return StringFromFormat(
"All pads:\n"
"ID: %i %i %i %i\n"
"Controllertype: %i %i %i %i\n"
"SquareToCircle: %i %i %i %i\n\n"
#ifdef _WIN32
"Handles: %i %i %i %i\n"
"XInput: %i %i %i\n"
#endif
"This pad:\n"
"Axes: %s\n"
"Hats: %s\n"
"But: %s\n"
"Device: Ax: %i Balls:%i Hats:%i But:%i",
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,
#ifdef _WIN32
joy0, joy1, joy2, joy3,
//PadState[PadMapping[0].ID].joy, PadState[PadMapping[1].ID].joy, PadState[PadMapping[2].ID].joy, PadState[PadMapping[3].ID].joy,
XInput::IsConnected(0), XInput::GetXI(0, InputCommon::XI_TRIGGER_L), XInput::GetXI(0, InputCommon::XI_TRIGGER_R),
#endif
StrAxes.c_str(), StrHats.c_str(), StrBut.c_str(),
Axes, Balls, Hats, Buttons
);
}
// Populate the advanced tab
// Update the advanced tab
// -----------------
void PADConfigDialognJoy::Update()
{
{
if (!IsPolling()) return;
// Check that Dolphin is in focus, otherwise don't update the pad status
/* If the emulator is running and unpaused GetJoyState() is run a little more often than needed,
but I allow that since it can confuse the user if the input status in the configuration window
@ -228,17 +155,41 @@ void PADConfigDialognJoy::Update()
if (g_Config.bCheckFocus || IsFocus()) // && !g_EmulatorRunning)
{
for (int i = 0; (u32)i < joyinfo.size(); i++)
InputCommon::GetJoyState(PadState[i], PadMapping[i], i, joyinfo[PadMapping[i].ID].NumButtons);
InputCommon::GetJoyState(PadState[notebookpage], PadMapping[notebookpage]);
PadShowStatus();
}
// Show the current status in a window in the wxPanel
#ifdef SHOW_PAD_STATUS
m_pStatusBar->SetLabel(wxString::Format(
"%s", ShowStatus(notebookpage).c_str()
));
m_pStatusBar->SetLabel(wxString::FromAscii(InputCommon::ShowStatus(
notebookpage, m_Joyname[notebookpage]->GetSelection(),
PadMapping, PadState, joyinfo
).c_str()));
#endif
}
// Search for devices
void PADConfigDialognJoy::UpdateSlow()
{
if (!LiveUpdates) return;
// Search for connected devices and update dialog
int OldNumDIDevices = NumDIDevices;
NumDIDevices = InputCommon::SearchDIDevices();
// Update if a pad has been connected/disconnected. Todo: Add a better check that also takes into consideration the pad id
// and other things to better ensure that nothing has changed
//DEBUG_LOG(PAD, "Found %i devices", NumDIDevices);
//DEBUG_LOG(PAD, "UpdateSlow: %i %i", OldNumPads, NumPads);
if (OldNumDIDevices != NumDIDevices)
{
WARN_LOG(PAD, "\n---- %s ----", (NumDIDevices > OldNumDIDevices) ? "Pad connected" : "Pad disconnected");
LocalSearchDevicesReset(joyinfo, NumPads);
UpdateDeviceList();
// Enable controls again, if disabled
UpdateGUIAll();
}
}
// Populate the advanced tab
// -----------------
@ -368,6 +319,5 @@ wxBitmap PADConfigDialognJoy::CreateBitmapArea(int Max, int Diagonal)
Points[7].x = (int)(-Diagonal * Adj + iAdj); Points[7].y = (int)(Diagonal * Adj + iAdj);
// Draw polygon
dc.DrawPolygon(8, Points);
return bitmap;
}

View File

@ -103,6 +103,7 @@ BEGIN_EVENT_TABLE(PADConfigDialognJoy,wxDialog)
EVT_BUTTON(IDB_ANALOG_SUB_Y, PADConfigDialognJoy::GetButtons)
#if wxUSE_TIMER
EVT_TIMER(IDTM_SLOW, PADConfigDialognJoy::OnSlowTimer)
EVT_TIMER(IDTM_CONSTANT, PADConfigDialognJoy::OnTimer)
EVT_TIMER(IDTM_BUTTON, PADConfigDialognJoy::OnButtonTimer)
#endif
@ -112,26 +113,40 @@ PADConfigDialognJoy::PADConfigDialognJoy(wxWindow *parent, wxWindowID id, const
const wxPoint &position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
// Define values
// Initialize values
notebookpage = 0;
g_Pressed = 0;
Debugging = false;
g_Pressed = 0;
m_TCDebugging = NULL;
ControlsCreated = false;
// Settings
Debugging = false;
// Only tested in Windows
#ifdef _WIN32
LiveUpdates = true;
#else
LiveUpdates = false;
#endif
// Create controls
CreateGUIControls();
// Update GUI
UpdateGUIAll();
// Update device list
UpdateDeviceList();
#if wxUSE_TIMER
m_SlowTimer = new wxTimer(this, IDTM_SLOW);
m_ConstantTimer = new wxTimer(this, IDTM_CONSTANT);
m_ButtonMappingTimer = new wxTimer(this, IDTM_BUTTON);
// Reset values
GetButtonWaitingID = 0; GetButtonWaitingTimer = 0;
// Start the constant timer
int TimesPerSecond = 30;
m_ConstantTimer->Start( floor((double)(1000 / TimesPerSecond)) );
// Start timers
StartTimer();
#endif
// wxEVT_KEY_DOWN is blocked for enter, tab and the directional keys
@ -148,6 +163,24 @@ PADConfigDialognJoy::~PADConfigDialognJoy()
#endif
}
void PADConfigDialognJoy::DoShow()
{
// Start timers
StartTimer();
// Show
ShowModal();
}
void PADConfigDialognJoy::StartTimer()
{
// Start the slow timer
double TimesPerSecond = 2;
m_SlowTimer->Start( floor((double)(1000.0 / TimesPerSecond)) );
// Start the constant timer
TimesPerSecond = 30;
m_ConstantTimer->Start( floor((double)(1000 / TimesPerSecond)) );
}
void PADConfigDialognJoy::OnKeyDown(wxKeyEvent& event)
{
g_Pressed = event.GetKeyCode();
@ -160,7 +193,9 @@ void PADConfigDialognJoy::OnClose(wxCloseEvent& event)
event.Skip();
// Stop the timer
m_SlowTimer->Stop();
m_ConstantTimer->Stop();
m_ButtonMappingTimer->Stop();
// Close pads, unless we are running a game
if (!g_EmulatorRunning) Shutdown();
@ -256,7 +291,7 @@ void PADConfigDialognJoy::DoSave(bool ChangePad, int Slot)
g_Config.Save(Slot);
// Now we can update the ID
PadMapping[notebookpage].ID = m_Joyname[notebookpage]->GetSelection();
UpdateID();
}
else
{
@ -268,6 +303,21 @@ void PADConfigDialognJoy::DoSave(bool ChangePad, int Slot)
// Then change it back to ""
ToBlank();
}
void PADConfigDialognJoy::UpdateID()
{
INFO_LOG(PAD, "Slot %i: Changed PadMapping ID from %i to %i", notebookpage, PadMapping[notebookpage].ID, m_Joyname[notebookpage]->GetSelection());
PadMapping[notebookpage].ID = joyinfo.at(m_Joyname[notebookpage]->GetSelection()).ID;
PadMapping[notebookpage].Name = joyinfo.at(m_Joyname[notebookpage]->GetSelection()).Name;
// Update all handles
for(int i = 0; i < 4; i++)
{
if (PadMapping[i].Name == PadMapping[notebookpage].Name)
{
if (m_Joyname[i]->GetSelection() >= 0 && joyinfo.size() > m_Joyname[i]->GetSelection())
PadState[i].joy = joyinfo.at(m_Joyname[i]->GetSelection()).joy;
}
}
}
// On changing the SaveById option we update all pages
void PADConfigDialognJoy::OnSaveById()
@ -290,11 +340,52 @@ void PADConfigDialognJoy::OnSaveById()
void PADConfigDialognJoy::DoChangeJoystick()
{
// Before changing the pad we save potential changes to the current pad (to support SaveByID)
WARN_LOG(PAD, "\n--- DoChangeJoystick ----");
WARN_LOG(PAD, "DoSave");
DoSave(true);
// Load the settings for the new Id
// Load the settings for the new ID
WARN_LOG(PAD, "Load");
g_Config.Load(true);
UpdateGUI(notebookpage); // Update the GUI
// Update the GUI
WARN_LOG(PAD, "UpdateGUI");
UpdateGUI(notebookpage);
WARN_LOG(PAD, "");
}
// Pads have been connected/disconnected
void PADConfigDialognJoy::UpdateDeviceList()
{
if (!ControlsCreated) return;
DEBUG_LOG(PAD, "UpdateDeviceList");
for (int i = 0; i < 4; i++)
{
// Save current selection
//std::string CurrentSel = m_Joyname[i]->GetValue().mb_str();
m_Joyname[i]->Clear();
// Search for devices and add them to the device list
if (NumPads > 0)
{
for (int j = 0; j < NumPads; j++)
m_Joyname[i]->Append(wxString::FromAscii(joyinfo.at(j).Name.c_str()));
// Set selection
//PanicAlert("%s", PadMapping[i].Name.c_str());
for (int j = 0; j < NumPads; j++)
{
if (joyinfo.at(j).Name == PadMapping[i].Name) m_Joyname[i]->SetSelection(j);
}
if (m_Joyname[i]->GetSelection() == -1) m_Joyname[i]->SetSelection(0);
// Load settings
DoChangeJoystick();
}
else
{
m_Joyname[i]->Append(wxString::FromAscii("<No Gamepad Detected>"));
m_Joyname[i]->SetSelection(0);
}
}
}
// Notebook page changed
@ -303,7 +394,7 @@ void PADConfigDialognJoy::NotebookPageChanged(wxNotebookEvent& event)
// Save current settings now, don't wait for OK
if (ControlsCreated && !g_Config.bSaveByID) DoSave(false, notebookpage);
// Update the global variable
// Update the global variable
notebookpage = event.GetSelection();
// Update GUI
@ -335,28 +426,28 @@ void PADConfigDialognJoy::ToBlank(bool ToBlank)
}
// Change settings
// Change settings for all slots that have this pad selected
// -----------------------
void PADConfigDialognJoy::SetButtonTextAll(int id, const char *text)
{
for (int i = 0; i < 4; i++)
{
// Safety check to avoid crash
if (joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[notebookpage].ID].Name)
SetButtonText(id, text, i);
if (IDToName(PadMapping[i].ID) == IDToName(PadMapping[notebookpage].ID))
{
SetButtonText(id, text, i);
DEBUG_LOG(PAD, "Updated button text for slot %i", i);
}
};
}
void PADConfigDialognJoy::SaveButtonMappingAll(int Slot)
{
for (int i = 0; i < 4; i++)
{
// This can occur when no gamepad is detected
if (joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[Slot].ID].Name)
SaveButtonMapping(i, false, Slot);
if (IDToName(PadMapping[i].ID) == IDToName(PadMapping[Slot].ID))
SaveButtonMapping(i, false, Slot);
}
}
// -----------------------
void PADConfigDialognJoy::UpdateGUIAll(int Slot)
{
@ -368,10 +459,8 @@ void PADConfigDialognJoy::UpdateGUIAll(int Slot)
{
for (int i = 0; i < 4; i++)
{
// Safety check to avoid crash
if (joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[Slot].ID].Name)
UpdateGUI(i);
if (IDToName(PadMapping[i].ID) == IDToName(PadMapping[Slot].ID))
UpdateGUI(i);
}
}
}
@ -438,8 +527,10 @@ void PADConfigDialognJoy::ChangeSettings( wxCommandEvent& event )
}
// Update all slots that use this device
if(g_Config.bSaveByID) SaveButtonMappingAll(notebookpage);
if(g_Config.bSaveByID) UpdateGUIAll(notebookpage);
//if(g_Config.bSaveByID)
SaveButtonMappingAll(notebookpage);
//if(g_Config.bSaveByID)
UpdateGUIAll(notebookpage);
}
@ -447,12 +538,18 @@ void PADConfigDialognJoy::ChangeSettings( wxCommandEvent& event )
// Called from: CreateGUIControls(), ChangeControllertype()
void PADConfigDialognJoy::UpdateGUI(int _notebookpage)
{
DEBUG_LOG(PAD, "UpdateGUI for slot %i, %i pads connected", _notebookpage, NumPads);
// If there are no good pads disable the entire notebook
if (NumGoodPads == 0)
if (NumPads == 0)
{
m_Notebook->Enable(false);
return;
}
else
{
m_Notebook->Enable(true);
}
// Update the GUI from PadMapping[]
UpdateGUIButtonMapping(_notebookpage);
@ -505,6 +602,8 @@ void PADConfigDialognJoy::UpdateGUI(int _notebookpage)
else m_CoBRadiusC[_notebookpage]->Enable(false);
if (PadMapping[_notebookpage].bSquareToCircleC) m_CoBDiagonalC[_notebookpage]->Enable(true);
else m_CoBDiagonalC[_notebookpage]->Enable(false);
DEBUG_LOG(PAD, "Main radius %s", PadMapping[_notebookpage].bRadiusOnOff ? "enabled" : "disabled");
}
// Repaint the background
@ -565,24 +664,9 @@ void PADConfigDialognJoy::CreateGUIControls()
m_Controller[3] = new wxPanel(m_Notebook, ID_CONTROLLERPAGE4, wxDefaultPosition, wxDefaultSize);
m_Notebook->AddPage(m_Controller[3], wxT("Controller 4"));
// Define bitmap for EVT_PAINT
WxStaticBitmap1_BITMAP = wxBitmap(ConfigBox_WxStaticBitmap1_XPM);
// Search for devices and add them to the device list
wxArrayString arrayStringFor_Joyname; // The string array
if (NumGoodPads > 0)
{
for(int x = 0; (u32)x < joyinfo.size(); x++)
{
arrayStringFor_Joyname.Add(wxString::FromAscii(joyinfo[x].Name.c_str()));
}
}
else
{
arrayStringFor_Joyname.Add(wxString::FromAscii("<No Gamepad Detected>"));
}
// Populate the DPad type and Trigger type list
wxArrayString wxAS_DPadType;
wxAS_DPadType.Add(wxString::FromAscii(DPadType[InputCommon::CTL_DPAD_HAT]));
@ -721,7 +805,7 @@ void PADConfigDialognJoy::CreateGUIControls()
// Populate Controller sizer
// Groups
#ifdef _WIN32
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(476, 21), arrayStringFor_Joyname, wxCB_READONLY);
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, wxEmptyString, wxDefaultPosition, wxSize(476, 21), 0, NULL, wxCB_READONLY);
#else
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(450, 25), arrayStringFor_Joyname, 0, wxDefaultValidator, wxT("m_Joyname"));
#endif
@ -954,9 +1038,6 @@ void PADConfigDialognJoy::CreateGUIControls()
// Show or hide it. We have to do this after we add it to its sizer
m_sMainRight[i]->Show(g_Config.bShowAdvanced);
// Update GUI
UpdateGUI(i);
} // end of loop
// Populate buttons sizer.
@ -975,7 +1056,7 @@ void PADConfigDialognJoy::CreateGUIControls()
// Debugging
#ifdef SHOW_PAD_STATUS
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), wxSize(200, -1));
#endif
// Set window size

View File

@ -62,12 +62,17 @@ class PADConfigDialognJoy : public wxDialog
long style = wxDEFAULT_DIALOG_STYLE);
virtual ~PADConfigDialognJoy();
// Timers
#if wxUSE_TIMER
void OnSlowTimer(wxTimerEvent& WXUNUSED(event)) { UpdateSlow(); }
void OnTimer(wxTimerEvent& WXUNUSED(event)) { Update(); }
void OnButtonTimer(wxTimerEvent& WXUNUSED(event)) { DoGetButtons(GetButtonWaitingID); }
wxTimer *m_ConstantTimer, *m_ButtonMappingTimer;
wxTimer *m_SlowTimer, *m_ConstantTimer, *m_ButtonMappingTimer;
#endif
// Functions
void DoShow();
// Debugging
wxStaticText* m_pStatusBar, * m_pStatusBar2;
wxTextCtrl* m_TCDebugging;
@ -195,7 +200,10 @@ class PADConfigDialognJoy : public wxDialog
*m_bmpSquare[4], *m_bmpDot[4], *m_bmpSquareOut[4], *m_bmpDotOut[4], *m_bmpAreaOut[4],
*m_bmpSquareC[4], *m_bmpDotC[4], *m_bmpSquareOutC[4], *m_bmpDotOutC[4], *m_bmpAreaOutC[4];
int notebookpage; bool ControlsCreated;
// Settings
int notebookpage;
bool ControlsCreated;
bool LiveUpdates;
private:
enum
@ -233,7 +241,7 @@ class PADConfigDialognJoy : public wxDialog
IDT_TRIGGERS, IDCB_CHECKFOCUS, IDCB_FILTER_SETTINGS,
// Timers
IDTM_CONSTANT, IDTM_BUTTON,
IDTM_SLOW, IDTM_CONSTANT, IDTM_BUTTON,
// ==============================================
@ -316,6 +324,8 @@ class PADConfigDialognJoy : public wxDialog
void OKClick(wxCommandEvent& event);
void CancelClick(wxCommandEvent& event);
void DoSave(bool ChangePad = false, int Slot = -1);
void UpdateID();
void StartTimer();
void DoChangeJoystick();
@ -323,20 +333,22 @@ class PADConfigDialognJoy : public wxDialog
void ChangeSettings(wxCommandEvent& event);
void ComboChange(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
void UpdateDeviceList();
void CreateGUIControls();
void CreateAdvancedControls(int i);
wxBitmap CreateBitmap();
wxBitmap CreateBitmapDot();
wxBitmap CreateBitmapArea(int,int);
void PadGetStatus();
void PadShowStatus();
void UpdateSlow();
void Update();
void UpdateGUIButtonMapping(int controller);
void SaveButtonMapping(int controller, bool DontChangeId = false, int FromSlot = -1);
void SaveButtonMappingAll(int Slot);
void UpdateGUIAll(int Slot);
void UpdateGUIAll(int Slot = -1);
void ToBlank(bool ToBlank = true);
void OnSaveById();

View File

@ -50,8 +50,11 @@ void PADConfigDialognJoy::UpdateGUIButtonMapping(int controller)
// http://wiki.wxwidgets.org/Converting_everything_to_and_from_wxString
wxString tmp;
// Assert
//if (!ControlsCreated[i]) return;
// Update selected gamepad
m_Joyname[controller]->SetSelection(PadMapping[controller].ID);
m_Joyname[controller]->SetValue(wxString::FromAscii(PadMapping[controller].Name.c_str()));
tmp << PadMapping[controller].buttons[InputCommon::CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear();
tmp << PadMapping[controller].buttons[InputCommon::CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear();
@ -99,7 +102,8 @@ void PADConfigDialognJoy::UpdateGUIButtonMapping(int controller)
tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear();
tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear();
}
NOTICE_LOG(PAD, "Loaded from PadMapping[%i] to slot %i", controller, controller);
}
/* Populate the PadMapping array with the dialog items settings (for example
@ -117,7 +121,21 @@ void PADConfigDialognJoy::SaveButtonMapping(int controller, bool DontChangeId, i
ToBlank(false);
// Set other settings
if(!DontChangeId) PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection();
if(!DontChangeId)
{
if (joyinfo.size() > m_Joyname[FromSlot]->GetSelection())
{
INFO_LOG(PAD, "%i: Changed PadMapping ID from %i to %i", controller, PadMapping[controller].ID, joyinfo.at(m_Joyname[FromSlot]->GetSelection()).ID);
PadMapping[controller].ID = joyinfo.at(m_Joyname[FromSlot]->GetSelection()).ID;
}
//else
// Assert
PadMapping[controller].Name = m_Joyname[FromSlot]->GetValue().mb_str();
}
NOTICE_LOG(PAD, "Saved PadMapping[%i] from slot %i", controller, FromSlot);
// Settings
PadMapping[controller].controllertype = m_ControlType[FromSlot]->GetSelection();
PadMapping[controller].triggertype = m_TriggerType[FromSlot]->GetSelection();
PadMapping[controller].deadzone = m_Deadzone[FromSlot]->GetSelection();
@ -264,6 +282,13 @@ void PADConfigDialognJoy::GetButtons(wxCommandEvent& event)
void PADConfigDialognJoy::DoGetButtons(int GetId)
{
//INFO_LOG(PAD, "DoGetButtons: %i", GetId);
if (!SDLPolling || SDL_JoystickEventState(SDL_QUERY) == SDL_ENABLE) return;
// Turn off live updates because the change the joy handles
LiveUpdates = false;
// =============================================
// Collect the starting values
// ----------------
@ -280,7 +305,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
int Axes = SDL_JoystickNumAxes(joy);
int Hats = SDL_JoystickNumHats(joy);
INFO_LOG(CONSOLE, "PadID: %i Axes: %i\n", PadID, joyinfo[PadID].NumAxes, joyinfo[PadID].joy);
//NOTICE_LOG(PAD, "PadID: %i Axes: %i Handle: %i\n", PadID, joyinfo[PadID].NumAxes, joyinfo[PadID].joy);
// Get the controller and trigger type
int ControllerType = PadMapping[Controller].controllertype;
@ -343,6 +368,8 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
#if wxUSE_TIMER
m_ButtonMappingTimer->Start( floor((double)(1000 / TimesPerSecond)) );
#endif
//INFO_LOG(PAD, "Timer started");
}
// ===============================================
@ -353,7 +380,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
else
{
InputCommon::GetButton(
joy, PadID, Buttons, Axes, Hats,
joy, PadID,
g_Pressed, value, type, pressed, Succeed, Stop,
LeftRight, Axis, XInput, Button, Hat, NoTriggerFilter);
}
@ -368,7 +395,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
GetButtonWaitingTimer++;
// This is run every second
if(GetButtonWaitingTimer % TimesPerSecond == 0)
if (GetButtonWaitingTimer % TimesPerSecond == 0)
{
// Current time
int TmpTime = Seconds - (GetButtonWaitingTimer / TimesPerSecond);
@ -379,7 +406,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
}
// Time's up
if( (GetButtonWaitingTimer / TimesPerSecond) >= Seconds )
if ( (GetButtonWaitingTimer / TimesPerSecond) >= Seconds )
{
Stop = true;
// Leave a blank mapping
@ -387,8 +414,10 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
}
// If we got a button
if(Succeed)
if (Succeed)
{
//INFO_LOG(PAD, "Button mapping succeeded: %i", pressed);
Stop = true;
// Write the number of the pressed button to the text box
sprintf(format, "%d", pressed);
@ -396,10 +425,12 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
}
// Stop the timer
if(Stop)
if (Stop)
{
m_ButtonMappingTimer->Stop();
GetButtonWaitingTimer = 0;
LiveUpdates = true;
//INFO_LOG(PAD, "Timer stopped");
/* Update the button mapping for all slots that use this device. (It doesn't make sense to have several slots
controlled by the same device, but several DirectInput instances of different but identical devices may possible

View File

@ -48,7 +48,8 @@ std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
InputCommon::CONTROLLER_STATE PadState[4];
InputCommon::CONTROLLER_MAPPING PadMapping[4];
bool g_EmulatorRunning = false;
int NumPads = 0, NumGoodPads = 0, LastPad = 0;
bool SDLPolling = true;
int NumPads = 0, NumDIDevices = 0, LastPad = 0;
#ifdef _WIN32
HWND m_hWnd = NULL, m_hConsole = NULL; // Handle to window
#endif
@ -154,11 +155,9 @@ void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
// ------------------
void DllConfig(HWND _hParent)
{
// Init Joystick + Haptic (force feedback) subsystem on SDL 1.3
// Populate joyinfo for all attached devices
Search_Devices(joyinfo, NumPads, NumGoodPads);
g_Config.Load(); // load settings
LocalSearchDevices(joyinfo, NumPads);
//g_Config.Load(); // load settings
#if defined(HAVE_WX) && HAVE_WX
if (!m_ConfigFrame)
@ -168,9 +167,9 @@ void DllConfig(HWND _hParent)
// Only allow one open at a time
if (!m_ConfigFrame->IsShown())
m_ConfigFrame->ShowModal();
m_ConfigFrame->DoShow();
else
m_ConfigFrame->Hide();
m_ConfigFrame->Hide();
#endif
}
@ -194,7 +193,7 @@ void Initialize(void *init)
#endif
// Populate joyinfo for all attached devices
Search_Devices(joyinfo, NumPads, NumGoodPads);
LocalSearchDevices(joyinfo, NumPads);
}
// Shutdown PAD (stop emulation)
@ -221,18 +220,16 @@ void Shutdown()
for (int i = 0; i < 4; i++)
{
if (joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo.at(PadMapping[i].ID).Good)
if(SDL_JoystickOpened(PadMapping[i].ID))
{
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
if(SDL_JoystickOpened(PadMapping[i].ID))
{
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
}
// Clear the physical device info
joyinfo.clear();
NumPads = 0;
NumGoodPads = 0;
// Finally close SDL
SDL_Quit();
@ -283,6 +280,12 @@ void DoState(unsigned char **ptr, int mode)
// Function: Gives the current pad status to the Core
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
{
if (!IsPolling()) return;
// Update joyinfo handles. This is in case the Wiimote plugin has restarted SDL after a pad was conencted/disconnected
// so that the handles are updated.
LocalSearchDevices(joyinfo, NumPads);
// Check if the pad is avaliable, currently we don't disable pads just because they are
// disconnected
if (!PadState[_numPAD].joy) return;
@ -292,7 +295,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// Check that Dolphin is in focus, otherwise don't update the pad status
if (g_Config.bCheckFocus || IsFocus())
GetJoyState(PadState[_numPAD], PadMapping[_numPAD], _numPAD, joyinfo[PadMapping[_numPAD].ID].NumButtons);
GetJoyState(PadState[_numPAD], PadMapping[_numPAD]);
// Get type
int TriggerType = PadMapping[_numPAD].triggertype;
@ -439,29 +442,137 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// Search for SDL 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)
bool LocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
{
// Turn off device polling while searching
EnablePolling(false);
//DEBUG_LOG(PAD, "LocalSearchDevices");
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads);
DoLocalSearchDevices(_joyinfo, _NumPads);
EnablePolling(true);
return Success;
}
bool LocalSearchDevicesReset(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
{
//DEBUG_LOG(PAD, "LocalSearchDevicesUpdate: %i", IsPolling());
bool Success = InputCommon::SearchDevicesReset(_joyinfo, _NumPads);
DoLocalSearchDevices(_joyinfo, _NumPads);
return Success;
}
bool DoLocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
{
// Don't warn the user if no gamepads are detected. If the pad doesn't respond he will open the configuration and fix it.
// Also, if he's using a Wii game he may not care that the gamepad is turned off.
if (_NumPads == 0 && g_EmulatorRunning)
{
PanicAlert("nJoy: No Gamepad Detected");
//PanicAlert("nJoy: No Gamepad Detected");
return false;
}
// Load PadMapping[] etc
g_Config.Load();
// Load the first time
if (!g_Config.Loaded) g_Config.Load();
// Update the PadState[].joy handle
for (int i = 0; i < 4; i++)
{
if (joyinfo.size() > (u32)PadMapping[i].ID)
if(joyinfo.at(PadMapping[i].ID).Good)
PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID);
for (int j = 0; j < joyinfo.size(); j++)
{
if (joyinfo.at(j).Name == PadMapping[i].Name)
{
PadState[i].joy = joyinfo.at(j).joy;
//DEBUG_LOG(PAD, "Slot %i: %s", i, joyinfo.at(j).Name.c_str());
}
}
}
return Success;
return true;
}
// Is the device connected?
// ----------------
bool IsConnected(std::string Name)
{
for (int i = 0; i < joyinfo.size(); i++)
{
//DEBUG_LOG(PAD, "IDToName: ID %i id %i %s", ID, i, joyinfo.at(i).Name.c_str());
if (joyinfo.at(i).Name == Name)
return true;
}
}
// Earlier versions of SDL could crash if SDL functions were called during SDL_Quit/SDL_Init. I could not get
// such a crash in the new version even with frequent SDL_Quit/SDL_Init so thse functions are disabled now.
// ----------------
bool IsPolling()
{
return true;
/*
if (!SDLPolling || SDL_JoystickEventState(SDL_QUERY) == SDL_ENABLE)
return false;
else
return true;
*/
}
void EnablePolling(bool Enable)
{
/*
if (Enable)
{
SDLPolling = true;
SDL_JoystickEventState(SDL_IGNORE);
}
else
{
SDLPolling = false;
SDL_JoystickEventState(SDL_ENABLE);
}
*/
}
// ID to Name
// ----------------
std::string IDToName(int ID)
{
for (int i = 0; i < joyinfo.size(); i++)
{
//DEBUG_LOG(PAD, "IDToName: ID %i id %i %s", ID, i, joyinfo.at(i).Name.c_str());
if (joyinfo.at(i).ID == ID)
return joyinfo.at(i).Name;
}
return "";
}
// ID to id - Get the gamepad id from a device ID (the ids will be all or some of the IDs)
// ----------------
int IDToid(int ID)
{
for (int i = 0; i < joyinfo.size(); i++)
{
if (joyinfo.at(i).ID == ID)
return i;
}
if (joyinfo.size() > 0)
{
ERROR_LOG(PAD, "IDToid error");
return 0;
}
else
{
PanicAlert("Error in IDToid. The plugin may crash.");
return -1;
}
}

View File

@ -95,13 +95,23 @@
#ifdef _WIN32
extern HWND m_hWnd, m_hConsole; // Handle to window
#endif
extern int NumPads, NumGoodPads, LastPad; // Number of goods pads
extern int NumPads, NumDIDevices, LastPad; // Number of pads
extern bool SDLPolling;
#endif
// Custom Functions
// ----------------
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads);
bool LocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads);
bool LocalSearchDevicesReset(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads);
bool DoLocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads);
int SearchDIDevices();
bool IsConnected(std::string Name);
bool IsPolling();
void EnablePolling(bool Enable);
std::string IDToName(int ID);
bool IsConnected(std::string Name);
int IDToid(int ID);
void DEBUG_INIT();
void DEBUG_QUIT();
bool IsFocus();