revert to r4531, but keep the changes from the following revisions: 4533,4550-4551,4556-4559

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4566 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2009-11-14 17:08:32 +00:00
commit 06aa62504c
66 changed files with 2170 additions and 1570 deletions

View file

@ -67,10 +67,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="xinput.lib comctl32.lib winmm.lib wiiuse.lib rpcrt4.lib wxbase28ud.lib wxmsw28ud_core.lib"
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib rpcrt4.lib wxbase28ud.lib wxmsw28ud_core.lib"
OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_WiimoteD.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\VisualC\SDL\$(ConfigurationName)&quot;;..\..\..\Externals\WiiUse\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\WiiUse\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -154,7 +154,7 @@
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib rpcrt4.lib wxbase28ud.lib wxmsw28ud_core.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_WiimoteD.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\VisualC\SDL\$(PlatformName)\$(ConfigurationName)&quot;;..\..\..\Externals\WiiUse\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\WiiUse\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -238,7 +238,7 @@
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib wxbase28u.lib wxmsw28u_core.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_Wiimote.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\VisualC\SDL\$(ConfigurationName);..\..\..\Externals\WiiUse\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\WiiUse\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -323,7 +323,7 @@
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib wxbase28u.lib wxmsw28u_core.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_Wiimote.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\VisualC\SDL\$(PlatformName)\$(ConfigurationName)&quot;;..\..\..\Externals\WiiUse\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\WiiUse\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -405,7 +405,7 @@
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib wxbase28u.lib wxmsw28u_core.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_WiimoteDF.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\VisualC\SDL\Debug;..\..\..\Externals\WiiUse\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\WiiUse\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -487,7 +487,7 @@
AdditionalDependencies="SDL.lib xinput.lib comctl32.lib winmm.lib wiiuse.lib wxbase28u.lib wxmsw28u_core.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_WiimoteDF.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\VisualC\SDL\$(PlatformName)\Debug&quot;;..\..\..\Externals\WiiUse\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\WiiUse\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"

View file

@ -24,7 +24,6 @@
#include "Config.h"
#include "EmuDefinitions.h" // for PadMapping
#include "EmuMain.h"
#include "main.h"
// Configuration file control names
@ -243,13 +242,10 @@ Config::Config()
{
// Set all default values to zero
memset(this, 0, sizeof(Config));
Loaded = false;
}
void Config::Load(bool ChangePad)
{
Loaded = true;
std::string temp;
IniFile iniFile;
iniFile.Load(FULL_CONFIG_DIR "Wiimote.ini");
@ -277,7 +273,6 @@ void Config::Load(bool ChangePad)
sprintf(SectionName, "Wiimote%i", i + 1);
iniFile.Get(SectionName, "NoTriggerFilter", &bNoTriggerFilter, false);
iniFile.Get(SectionName, "TriggerType", &Trigger.Type, Trigger.TRIGGER_OFF);
iniFile.Get(SectionName, "TriggerUpright", &Trigger.Upright, false);
iniFile.Get(SectionName, "TriggerRollRange", &Trigger.Range.Roll, 50);
iniFile.Get(SectionName, "TriggerPitchRange", &Trigger.Range.Pitch, false);
@ -300,49 +295,38 @@ void Config::Load(bool ChangePad)
iniFile.Get(SectionName, gh3ControlNames[x], &WiiMoteEmu::PadMapping[i].GH3c.keyForControls[x], GH3DefaultControls[x]);
// Don't update this when we are loading settings from the ConfigBox
if (!ChangePad)
if(!ChangePad)
{
// This pad Id could possibly be higher than the number of pads that are connected,
// but we check later, when needed, that that is not the case
iniFile.Get(SectionName, "DeviceID", &WiiMoteEmu::PadMapping[i].ID, 0);
iniFile.Get(SectionName, "DeviceName", &WiiMoteEmu::PadMapping[i].Name, 0);
iniFile.Get(SectionName, "Enabled", &WiiMoteEmu::PadMapping[i].enabled, true);
}
// Joypad specific settings
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: PadMapping[i].Name
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: joyinfo[PadMapping[i].ID].Name
// Prevent a crash from illegal access to joyinfo that will only have values for
// the current amount of connected PadMapping
if((u32)WiiMoteEmu::PadMapping[i].ID >= WiiMoteEmu::joyinfo.size()) continue;
// Create a section name
std::string JoySectionName = WiiMoteEmu::PadMapping[i].Name;
// Don't load settings for a non-connected device
if (!WiiMoteEmu::IsConnected(JoySectionName))
{
ERROR_LOG(PAD, "Slot %i: The device '%s' is not connected, will not load settings", i, JoySectionName.c_str());
continue;
}
// Don't load a blank ID
if (JoySectionName == "")
{
ERROR_LOG(PAD, "Slot %i has no device name, will not load settings", i);
continue;
}
std::string joySectionName = WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[i].ID].Name;
iniFile.Get(JoySectionName.c_str(), "left_x", &WiiMoteEmu::PadMapping[i].Axis.Lx, 0);
iniFile.Get(JoySectionName.c_str(), "left_y", &WiiMoteEmu::PadMapping[i].Axis.Ly, 1);
iniFile.Get(JoySectionName.c_str(), "right_x", &WiiMoteEmu::PadMapping[i].Axis.Rx, 2);
iniFile.Get(JoySectionName.c_str(), "right_y", &WiiMoteEmu::PadMapping[i].Axis.Ry, 3);
iniFile.Get(JoySectionName.c_str(), "l_trigger", &WiiMoteEmu::PadMapping[i].Axis.Tl, 1004);
iniFile.Get(JoySectionName.c_str(), "r_trigger", &WiiMoteEmu::PadMapping[i].Axis.Tr, 1005);
iniFile.Get(JoySectionName.c_str(), "DeadZoneL", &WiiMoteEmu::PadMapping[i].DeadZoneL, 0);
iniFile.Get(JoySectionName.c_str(), "DeadZoneR", &WiiMoteEmu::PadMapping[i].DeadZoneR, 0);
iniFile.Get(JoySectionName.c_str(), "TriggerType", &WiiMoteEmu::PadMapping[i].triggertype, 0);
iniFile.Get(JoySectionName.c_str(), "Diagonal", &WiiMoteEmu::PadMapping[i].SDiagonal, "100%");
iniFile.Get(JoySectionName.c_str(), "Circle2Square", &WiiMoteEmu::PadMapping[i].bCircle2Square, false);
iniFile.Get(JoySectionName.c_str(), "RollInvert", &WiiMoteEmu::PadMapping[i].bRollInvert, false);
iniFile.Get(JoySectionName.c_str(), "PitchInvert", &WiiMoteEmu::PadMapping[i].bPitchInvert, false);
NOTICE_LOG(WIIMOTE, "Slot %i: Load settings for ID %i '%s'", i, WiiMoteEmu::PadMapping[i].ID, JoySectionName.c_str());
iniFile.Get(joySectionName.c_str(), "left_x", &WiiMoteEmu::PadMapping[i].Axis.Lx, 0);
iniFile.Get(joySectionName.c_str(), "left_y", &WiiMoteEmu::PadMapping[i].Axis.Ly, 1);
iniFile.Get(joySectionName.c_str(), "right_x", &WiiMoteEmu::PadMapping[i].Axis.Rx, 2);
iniFile.Get(joySectionName.c_str(), "right_y", &WiiMoteEmu::PadMapping[i].Axis.Ry, 3);
iniFile.Get(joySectionName.c_str(), "l_trigger", &WiiMoteEmu::PadMapping[i].Axis.Tl, 1004);
iniFile.Get(joySectionName.c_str(), "r_trigger", &WiiMoteEmu::PadMapping[i].Axis.Tr, 1005);
iniFile.Get(joySectionName.c_str(), "DeadZoneL", &WiiMoteEmu::PadMapping[i].DeadZoneL, 0);
iniFile.Get(joySectionName.c_str(), "DeadZoneR", &WiiMoteEmu::PadMapping[i].DeadZoneR, 0);
iniFile.Get(joySectionName.c_str(), "TriggerType", &WiiMoteEmu::PadMapping[i].triggertype, 0);
iniFile.Get(joySectionName.c_str(), "Diagonal", &WiiMoteEmu::PadMapping[i].SDiagonal, "100%");
iniFile.Get(joySectionName.c_str(), "Circle2Square", &WiiMoteEmu::PadMapping[i].bCircle2Square, false);
iniFile.Get(joySectionName.c_str(), "RollInvert", &WiiMoteEmu::PadMapping[i].bRollInvert, false);
iniFile.Get(joySectionName.c_str(), "PitchInvert", &WiiMoteEmu::PadMapping[i].bPitchInvert, false);
}
// Load the IR cursor settings if it's avaliable for the GameId, if not load the default settings
iniFile.Load(FULL_CONFIG_DIR "IR Pointer.ini");
@ -391,7 +375,6 @@ void Config::Save(int Slot)
iniFile.Set(SectionName, "Enabled", WiiMoteEmu::PadMapping[i].enabled);
iniFile.Set(SectionName, "NoTriggerFilter", bNoTriggerFilter);
iniFile.Set(SectionName, "TriggerType", Trigger.Type);
iniFile.Set(SectionName, "TriggerUpright", Trigger.Upright);
iniFile.Set(SectionName, "TriggerRollRange", Trigger.Range.Roll);
iniFile.Set(SectionName, "TriggerPitchRange", Trigger.Range.Pitch);
@ -417,23 +400,18 @@ void Config::Save(int Slot)
// Save the physical device ID number
iniFile.Set(SectionName, "DeviceID", WiiMoteEmu::PadMapping[i].ID);
iniFile.Set(SectionName, "DeviceName", WiiMoteEmu::PadMapping[i].Name);
// Joypad specific settings
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: IDToName(PadMapping[i].ID])
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: joyinfo[PadMapping[i].ID].Name
// Save joypad specific settings. Check for "PadMapping[i].ID < SDL_NumJoysticks()" to
// avoid reading a joyinfo that does't exist
if((u32)WiiMoteEmu::PadMapping[i].ID >= WiiMoteEmu::joyinfo.size()) continue;
// Create a new section name after the joypad name
std::string joySectionName = WiiMoteEmu::IDToName(WiiMoteEmu::PadMapping[i].ID);
// Don't save a blank name
if (SectionName == "")
{
ERROR_LOG(WIIMOTE, "ID %i has no name, will not load", WiiMoteEmu::PadMapping[i].ID);
continue;
}
NOTICE_LOG(WIIMOTE, "Save settings for ID %i '%s' from PadMapping[%i]", WiiMoteEmu::PadMapping[i].ID, joySectionName.c_str(), i);
std::string joySectionName = WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[i].ID].Name;
iniFile.Set(joySectionName.c_str(), "left_x", WiiMoteEmu::PadMapping[i].Axis.Lx);
iniFile.Set(joySectionName.c_str(), "left_y", WiiMoteEmu::PadMapping[i].Axis.Ly);
iniFile.Set(joySectionName.c_str(), "right_x", WiiMoteEmu::PadMapping[i].Axis.Rx);

View file

@ -41,7 +41,6 @@ struct Config
Config();
void Load(bool ChangePad = false);
void Save(int Slot = -1);
bool Loaded;
struct PadRange
{
@ -60,7 +59,6 @@ struct Config
TRIGGER
};
int Type;
bool Upright;
PadRange Range;
};
struct PadNunchuck

View file

@ -34,7 +34,6 @@ BEGIN_EVENT_TABLE(WiimoteBasicConfigDialog,wxDialog)
EVT_CHECKBOX(ID_CONNECT_REAL, WiimoteBasicConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(ID_USE_REAL, WiimoteBasicConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(ID_SIDEWAYSDPAD, WiimoteBasicConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(ID_UPRIGHTWIIMOTE, WiimoteBasicConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(ID_MOTIONPLUSCONNECTED, WiimoteBasicConfigDialog::GeneralSettingsChanged)
EVT_CHOICE(ID_EXTCONNECTED, WiimoteBasicConfigDialog::GeneralSettingsChanged)
// IR cursor
@ -208,9 +207,9 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
// Emulated Wiimote
m_SidewaysDPad[i] = new wxCheckBox(m_Controller[i], ID_SIDEWAYSDPAD, wxT("Sideways D-Pad"));
m_SidewaysDPad[i]->SetValue(g_Config.bSidewaysDPad);
m_UprightWiimote[i] = new wxCheckBox(m_Controller[i], ID_UPRIGHTWIIMOTE, wxT("Upright Wiimote"));
m_UprightWiimote[i]->SetValue(g_Config.Trigger.Upright);
m_UprightWiimote[i]->SetToolTip(wxT("Treat the upright position as neutral for roll and pitch"));
m_SizeEmu[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Emulated Wiimote"));
m_SizeEmu[i]->Add(m_SidewaysDPad[i], 0, wxEXPAND | wxALL, 5);
//IR Pointer
m_TextScreenWidth[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Width: 000"));
@ -252,12 +251,6 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
m_CheckAR169[i]->Enable(false);
m_Crop[i]->Enable(false);
// Sizers
m_SizeEmu[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Emulated Wiimote"));
m_SizeEmu[i]->Add(m_SidewaysDPad[i], 0, wxEXPAND | wxALL, 5);
m_SizeEmu[i]->Add(m_UprightWiimote[i], 0, wxEXPAND | (wxLEFT | wxDOWN | wxRIGHT), 5);
m_SizerIRPointerScreen[i] = new wxBoxSizer(wxHORIZONTAL);
m_SizerIRPointerScreen[i]->Add(m_TextAR[i], 0, wxEXPAND | (wxTOP), 0);
m_SizerIRPointerScreen[i]->Add(m_CheckAR43[i], 0, wxEXPAND | (wxLEFT), 5);
@ -398,9 +391,6 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
case ID_SIDEWAYSDPAD:
g_Config.bSidewaysDPad = m_SidewaysDPad[Page]->IsChecked();
break;
case ID_UPRIGHTWIIMOTE:
g_Config.Trigger.Upright = m_UprightWiimote[Page]->IsChecked();
break;
case ID_MOTIONPLUSCONNECTED:

View file

@ -79,7 +79,6 @@ class WiimoteBasicConfigDialog : public wxDialog
// Emulated Wiimote settings
wxCheckBox *m_SidewaysDPad[4],
*m_UprightWiimote[4],
*m_WiimoteOnline[4],
*m_WiiMotionPlusConnected[4],
*m_CheckAR43[4],
@ -127,7 +126,6 @@ class WiimoteBasicConfigDialog : public wxDialog
// Emulated Wiimote
ID_SIDEWAYSDPAD,
ID_UPRIGHTWIIMOTE,
ID_MOTIONPLUSCONNECTED,
ID_EXTCONNECTED,
IDC_WIMOTE_ON,

View file

@ -30,15 +30,36 @@
is only used the first time the pads are checked. */
void WiimotePadConfigDialog::DoChangeJoystick()
{
WARN_LOG(WIIMOTE, "---- DoChangeJoystick ----");
// 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
DoSave(true);
// Load the settings for the new Id
g_Config.Load(true);
// Update the GUI
UpdateGUI(Page);
UpdateGUI(Page); // Update the GUI
// Open the new pad
if (WiiMoteEmu::PadMapping[Page].enabled) PadOpen(Page);
}
void WiimotePadConfigDialog::PadOpen(int Open) // Open for slot 1, 2, 3 or 4
{
// Check that we got a good pad
if (!WiiMoteEmu::joyinfo.at(WiiMoteEmu::PadMapping[Open].ID).Good)
{
DEBUG_LOG(WIIMOTE, "A bad pad was selected");
WiiMoteEmu::PadState[Open].joy = NULL;
return;
}
DEBUG_LOG(WIIMOTE, "Update the Slot %i handle to Id %i", Page, WiiMoteEmu::PadMapping[Open].ID);
WiiMoteEmu::PadState[Open].joy = SDL_JoystickOpen(WiiMoteEmu::PadMapping[Open].ID);
}
void WiimotePadConfigDialog::PadClose(int _Close) // Close for slot 1, 2, 3 or 4
{
if (SDL_JoystickOpened(WiiMoteEmu::PadMapping[_Close].ID)) SDL_JoystickClose(WiiMoteEmu::PadState[_Close].joy);
WiiMoteEmu::PadState[_Close].joy = NULL;
}
void WiimotePadConfigDialog::DoChangeDeadZone(bool Left)
@ -69,29 +90,30 @@ void WiimotePadConfigDialog::DoChangeDeadZone(bool Left)
// Set the button text for all four Wiimotes
void WiimotePadConfigDialog::SetButtonTextAll(int id, char text[128])
{
for (int i = 0; i < MAX_WIIMOTES; i++)
for (int i = 0; i < 1; i++)
{
if (WiiMoteEmu::IDToName(WiiMoteEmu::PadMapping[i].ID) == WiiMoteEmu::IDToName(WiiMoteEmu::PadMapping[Page].ID))
{
SetButtonText(id, text, i);
DEBUG_LOG(PAD, "Updated button text for slot %i", i);
}
// Safety check to avoid crash
if ((int)WiiMoteEmu::joyinfo.size() > WiiMoteEmu::PadMapping[i].ID)
if (WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[i].ID].Name == WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[Page].ID].Name)
SetButtonText(id, text, i);
};
}
void WiimotePadConfigDialog::SaveButtonMappingAll(int Slot)
{
for (int i = 0; i < MAX_WIIMOTES; i++)
for (int i = 0; i < 4; i++)
{
if (WiiMoteEmu::PadMapping[i].Name.length() > 0 && WiiMoteEmu::PadMapping[i].Name == WiiMoteEmu::PadMapping[Slot].Name)
SaveButtonMapping(i, false, Slot);
// This can occur when no gamepad is detected
if ((int)WiiMoteEmu::joyinfo.size() > WiiMoteEmu::PadMapping[i].ID && WiiMoteEmu::PadMapping[i].ID >= 0)
if (WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[i].ID].Name == WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[Slot].ID].Name)
SaveButtonMapping(i, false, Slot);
}
}
// Set dialog items from saved values
void WiimotePadConfigDialog::UpdateGUIButtonMapping(int controller)
{
NOTICE_LOG(WIIMOTE, "Load ButtonMapping | controller:%i", controller);
// Temporary storage
wxString tmp;
@ -182,19 +204,12 @@ void WiimotePadConfigDialog::UpdateGUIButtonMapping(int controller)
void WiimotePadConfigDialog::SaveButtonMapping(int controller, bool DontChangeId, int FromSlot)
{
// Log
NOTICE_LOG(WIIMOTE, "SaveButtonMapping | controller:%i FromSlot:%i", controller, FromSlot);
// Temporary storage
wxString tmp;
long value;
// Save from or to the same or different slots
if (FromSlot == -1) FromSlot = controller;
// TEMPORARY
// There is only one slot at the moment
if (FromSlot > MAX_WIIMOTES-1) FromSlot = MAX_WIIMOTES-1;
// Replace "" with "-1" in the GUI controls
ToBlank(false);
@ -203,11 +218,7 @@ void WiimotePadConfigDialog::SaveButtonMapping(int controller, bool DontChangeId
-1 that's a bug that should be fixed. Because the m_Joyname[] combo box should always show <No Gamepad Detected>, or a gamepad name, not a
a blank selection. */
if (!DontChangeId)
{
if (m_Joyname[FromSlot]->GetSelection() >= WiiMoteEmu::joyinfo.size()) PanicAlert("Bug in SaveButtonMapping");
WiiMoteEmu::PadMapping[controller].ID = WiiMoteEmu::joyinfo.at(m_Joyname[FromSlot]->GetSelection()).ID;
WiiMoteEmu::PadMapping[controller].Name = m_Joyname[FromSlot]->GetValue().mb_str();
}
WiiMoteEmu::PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection();
// Set enabled or disable status
if (FromSlot == controller)
WiiMoteEmu::PadMapping[controller].enabled = true; //m_Joyattach[FromSlot]->GetValue(); // Only enable one
@ -361,11 +372,6 @@ void WiimotePadConfigDialog::GetButtons(wxCommandEvent& event)
void WiimotePadConfigDialog::DoGetButtons(int _GetId)
{
DEBUG_LOG(WIIMOTE, "DoGetButtons");
bool _LiveUpdates = LiveUpdates;
LiveUpdates = false;
// Collect the starting values
// Get the current controller
@ -393,7 +399,7 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
// Values used in this function
char format[128];
int Seconds = 4; // Seconds to wait for
int TimesPerSecond = 60; // How often to run the check
int TimesPerSecond = 40; // How often to run the check
// Values returned from InputCommon::GetButton()
int value; // Axis value
@ -432,7 +438,7 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
m_ButtonMappingTimer->Start( floor((double)(1000 / TimesPerSecond)) );
#endif
DEBUG_LOG(WIIMOTE, "Timer Started for Pad:%i _GetId:%i"
" Allowed input is Axis:%i LeftRight:%i XInput:%i Button:%i Hat:%i\n",
"Allowed input is Axis:%i LeftRight:%i XInput:%i Button:%i Hat:%i\n",
WiiMoteEmu::PadMapping[Controller].ID, _GetId,
Axis, LeftRight, XInput, Button, Hat);
}
@ -443,7 +449,7 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
else
{
InputCommon::GetButton(
WiiMoteEmu::PadState[Page].joy, PadID,
WiiMoteEmu::joyinfo[PadID].joy, PadID, WiiMoteEmu::joyinfo[PadID].NumButtons, WiiMoteEmu::joyinfo[PadID].NumAxes, WiiMoteEmu::joyinfo[PadID].NumHats,
g_Pressed, value, type, pressed, Succeed, Stop,
LeftRight, Axis, XInput, Button, Hat, NoTriggerFilter);
}
@ -476,7 +482,7 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
}
// If we got a button
if (Succeed)
if(Succeed)
{
Stop = true;
// Write the number of the pressed button to the text box
@ -485,11 +491,10 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
}
// Stop the timer
if (Stop)
if(Stop)
{
m_ButtonMappingTimer->Stop();
GetButtonWaitingTimer = 0;
LiveUpdates = _LiveUpdates;
/* Update the button mapping for all slots that use this device. (It
doesn't make sense to have several slots controlled by the same
@ -540,12 +545,12 @@ void WiimotePadConfigDialog::Convert2Box(int &x)
// Update the input status boxes
void WiimotePadConfigDialog::PadGetStatus()
{
//DEBUG_LOG(WIIMOTE, "PadGetStatus");
//DEBUG_LOG(WIIMOTE, "SDL_WasInit: %i", SDL_WasInit(0));
/* 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 (WiiMoteEmu::PadMapping[Page].ID < 0 || WiiMoteEmu::PadMapping[Page].ID >= SDL_NumJoysticks())
if(WiiMoteEmu::PadMapping[Page].ID < 0 || WiiMoteEmu::PadMapping[Page].ID >= SDL_NumJoysticks())
{
m_TStatusLeftIn[Page]->SetLabel(wxT("Not connected"));
m_TStatusLeftOut[Page]->SetLabel(wxT("Not connected"));
@ -569,13 +574,15 @@ void WiimotePadConfigDialog::PadGetStatus()
}
// Get physical device status
int ID = WiiMoteEmu::PadMapping[Page].ID;
int PhysicalDevice = WiiMoteEmu::PadMapping[Page].ID;
int TriggerType = WiiMoteEmu::PadMapping[Page].triggertype;
// Check that Dolphin is in focus, otherwise don't update the pad status
//if (IsFocus())
WiiMoteEmu::GetJoyState(WiiMoteEmu::PadState[Page], WiiMoteEmu::PadMapping[Page], Page);
WiiMoteEmu::GetJoyState(WiiMoteEmu::PadState[Page], WiiMoteEmu::PadMapping[Page], Page, WiiMoteEmu::joyinfo.at(WiiMoteEmu::PadMapping[Page].ID).NumButtons);
// Analog stick
// Set Deadzones perhaps out of function
//int deadzone = (int)(((float)(128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone+1));
@ -688,45 +695,16 @@ void WiimotePadConfigDialog::PadGetStatus()
wxT("%03i"), TriggerRight));
}
// Slow timer, once a second
void WiimotePadConfigDialog::Update(wxTimerEvent& WXUNUSED(event))
{
if (!LiveUpdates) return;
// Don't run this the first time
int OldNumDIDevices;
if (WiiMoteEmu::NumDIDevices == -1)
OldNumDIDevices = InputCommon::SearchDIDevices();
else
// Search for connected devices and update dialog
OldNumDIDevices = WiiMoteEmu::NumDIDevices;
WiiMoteEmu::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 ensure nothing has changed
//DEBUG_LOG(WIIMOTE, "Found %i devices", WiiMoteEmu::NumDIDevices);
//DEBUG_LOG(WIIMOTE, "Update: %i %i", OldNumPads, WiiMoteEmu::NumPads);
if (OldNumDIDevices != WiiMoteEmu::NumDIDevices)
{
WiiMoteEmu::LocalSearchDevicesReset(WiiMoteEmu::joyinfo, WiiMoteEmu::NumPads);
WiimotePadConfigDialog::UpdateDeviceList();
}
}
// Populate the advanced tab
void WiimotePadConfigDialog::UpdatePad(wxTimerEvent& WXUNUSED(event))
{
if (!WiiMoteEmu::IsPolling()) return;
//DEBUG_LOG(WIIMOTE, "UpdatePad");
// Show the current status
/*
#ifdef SHOW_PAD_STATUS
m_pStatusBar->SetLabel(wxString::FromAscii(InputCommon::DoShowStatus(
Page, m_Joyname[Page]->GetSelection(),
WiiMoteEmu::PadMapping, WiiMoteEmu::PadState, WiiMoteEmu::joyinfo
).c_str()));
#endif
m_pStatusBar->SetLabel(wxString::Format(
"%s", ShowStatus(notebookpage).c_str()
));
#endif*/
//LogMsg("Abc%s\n", ShowStatus(notebookpage).c_str());

View file

@ -98,7 +98,6 @@ BEGIN_EVENT_TABLE(WiimotePadConfigDialog,wxDialog)
EVT_BUTTON(IDB_TRIGGER_L, WiimotePadConfigDialog::GetButtons)
EVT_BUTTON(IDB_TRIGGER_R, WiimotePadConfigDialog::GetButtons)
EVT_TIMER(IDTM_BUTTON, WiimotePadConfigDialog::OnButtonTimer)
EVT_TIMER(IDTM_UPDATE, WiimotePadConfigDialog::Update)
EVT_TIMER(IDTM_UPDATE_PAD, WiimotePadConfigDialog::UpdatePad)
END_EVENT_TABLE()
@ -108,18 +107,14 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
{
#if wxUSE_TIMER
m_ButtonMappingTimer = new wxTimer(this, IDTM_BUTTON);
m_Update = new wxTimer(this, IDTM_UPDATE);
m_UpdatePad = new wxTimer(this, IDTM_UPDATE_PAD);
m_UpdatePad = new wxTimer(this, IDTM_UPDATE_PAD);
// Reset values
GetButtonWaitingID = 0;
GetButtonWaitingTimer = 0;
// Start the slow timer
int TimesPerSecond = 2;
m_Update->Start( floor((double)(1000 / TimesPerSecond)) );
// Start the fast timer
TimesPerSecond = 30;
// Start the permanent timer
const int TimesPerSecond = 30;
m_UpdatePad->Start( floor((double)(1000 / TimesPerSecond)) );
#endif
@ -133,9 +128,6 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
// Set control values
UpdateGUI();
// Update device list
UpdateDeviceList();
wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
wxKeyEventHandler(WiimotePadConfigDialog::OnKeyDown),
@ -212,13 +204,9 @@ void WiimotePadConfigDialog::OnClose(wxCloseEvent& event)
{
g_FrameOpen = false;
SaveButtonMappingAll(Page);
// Stop timers
if(m_Update) m_Update->Stop();
if(m_UpdatePad) m_UpdatePad->Stop();
if(m_ButtonMappingTimer) m_ButtonMappingTimer->Stop();
INFO_LOG(WIIMOTE, "All timers stopped");
if(m_UpdatePad)
m_UpdatePad->Stop();
g_Config.Save();
event.Skip();
}
@ -240,20 +228,18 @@ void WiimotePadConfigDialog::CloseClick(wxCommandEvent& event)
void WiimotePadConfigDialog::DoSave(bool ChangePad, int Slot)
{
WARN_LOG(WIIMOTE, "DoSave - %i slot %i", ChangePad, Slot);
// Replace "" with "-1" before we are saving
ToBlank(false);
if(ChangePad)
{
// Since we are selecting the pad to save to by the Id we can't update it when we change the pad
for(int i = 0; i < MAX_WIIMOTES; i++)
for(int i = 0; i < 4; i++)
SaveButtonMapping(i, true);
// Save the settings for the current pad
g_Config.Save(Slot);
// Now we can update the ID
UpdateID();
WiiMoteEmu::PadMapping[Page].ID = m_Joyname[Page]->GetSelection();
}
else
{
@ -265,14 +251,8 @@ void WiimotePadConfigDialog::DoSave(bool ChangePad, int Slot)
// Then change it back to ""
ToBlank();
}
void WiimotePadConfigDialog::UpdateID()
{
INFO_LOG(WIIMOTE, "PadMapping[%i].ID = %i from %i",
Page, WiiMoteEmu::joyinfo.at(m_Joyname[Page]->GetSelection()).ID, WiiMoteEmu::PadMapping[Page].ID);
WiiMoteEmu::PadMapping[Page].ID = WiiMoteEmu::joyinfo.at(m_Joyname[Page]->GetSelection()).ID;
WiiMoteEmu::PadMapping[Page].Name = m_Joyname[Page]->GetValue().mb_str();
WiiMoteEmu::PadState[Page].joy = WiiMoteEmu::joyinfo.at(m_Joyname[Page]->GetSelection()).joy;
DEBUG_LOG(WIIMOTE, "WiiMoteEmu::PadMapping[%i].ID = %i", Page, m_Joyname[Page]->GetSelection());
}
// Bitmap box and dot
@ -345,40 +325,24 @@ wxBitmap WiimotePadConfigDialog::CreateBitmapClear()
return bitmap;
}
void WiimotePadConfigDialog::UpdateDeviceList()
{
if (!ControlsCreated) return;
DEBUG_LOG(WIIMOTE, "UpdateDeviceList");
for (int i = 0; i < MAX_WIIMOTES; 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 (WiiMoteEmu::joyinfo.size() > 0)
{
for (int j = 0; j < WiiMoteEmu::joyinfo.size(); j++)
m_Joyname[i]->Append(wxString::FromAscii(WiiMoteEmu::joyinfo.at(j).Name.c_str()));
// Set selection
for (int j = 0; j < WiiMoteEmu::joyinfo.size(); j++)
if (WiiMoteEmu::joyinfo.at(j).Name == WiiMoteEmu::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);
}
}
}
void WiimotePadConfigDialog::CreatePadGUIControls()
{
// Search for devices and add them to the device list
wxArrayString StrJoyname; // The string array
if (WiiMoteEmu::NumGoodPads > 0)
{
for (int x = 0; x < (int)WiiMoteEmu::joyinfo.size(); x++)
StrJoyname.Add(wxString::FromAscii(WiiMoteEmu::joyinfo[x].Name.c_str()));
}
else
{
StrJoyname.Add(wxString::FromAscii("<No Gamepad Detected>"));
}
// The tilt list
wxArrayString StrTilt;
StrTilt.Add(wxString::FromAscii("<Off>"));
@ -408,17 +372,13 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
wxArrayString StrCcTriggers;
StrCcTriggers.Add(wxString::FromAscii("Keyboard"));
StrCcTriggers.Add(wxString::FromAscii("Triggers"));
#ifdef SHOW_PAD_STATUS
m_Notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxSize(-1, 600));
m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(250, 250), wxDefaultSize);
#else
m_Notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize);
#endif
for (int i = 0; i < MAX_WIIMOTES; i++)
{
m_Controller[i] = new wxPanel(m_Notebook, ID_CONTROLLERPAGE1 + i, wxDefaultPosition, wxDefaultSize);
{
m_Controller[i] = new wxPanel(m_Notebook, ID_CONTROLLERPAGE1 + i, wxDefaultPosition, wxDefaultSize);
m_Notebook->AddPage(m_Controller[i], wxString::Format(wxT("Wiimote %d"), i+1));
// A small type font
@ -427,8 +387,9 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
// Configuration controls sizes
static const int TxtW = 50, TxtH = 19, BtW = 75, BtH = 20;
// Controller
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_READONLY);
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, StrJoyname[0], wxDefaultPosition, wxSize(200, -1), StrJoyname, wxCB_READONLY);
// Circle to square
m_CheckC2S[i] = new wxCheckBox(m_Controller[i], IDC_LEFT_C2S, wxT("Circle To Square"));
@ -985,6 +946,7 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
}
m_Apply = new wxButton(this, ID_APPLY, wxT("Apply"));
m_Close = new wxButton(this, ID_CLOSE, wxT("Close"));
m_Close->SetToolTip(wxT("Apply and Close"));
@ -1075,16 +1037,14 @@ void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
void WiimotePadConfigDialog::UpdateGUI(int Slot)
{
DEBUG_LOG(WIIMOTE, "UpdateGUI");
UpdateGUIButtonMapping(Page);
DoChangeDeadZone(true); DoChangeDeadZone(false);
// Linux has no FindItem()
// Disable all pad items if no pads are detected
if (ControlsCreated)
if(ControlsCreated)
{
bool PadEnabled = WiiMoteEmu::NumPads != 0;
bool PadEnabled = WiiMoteEmu::NumGoodPads != 0;
#ifdef _WIN32
for(int i = IDB_ANALOG_LEFT_X; i <= IDB_TRIGGER_R; i++) m_Notebook->FindItem(i)->Enable(PadEnabled);
m_Notebook->FindItem(IDC_JOYNAME)->Enable(PadEnabled);

View file

@ -59,12 +59,9 @@ class WiimotePadConfigDialog : public wxDialog
void Convert2Box(int &x);
void ConvertToString();
void OnButtonTimer(wxTimerEvent& WXUNUSED(event)) { DoGetButtons(GetButtonWaitingID); }
void Update(wxTimerEvent& WXUNUSED(event));
void UpdatePad(wxTimerEvent& WXUNUSED(event));
void UpdateDeviceList();
wxTimer *m_Update,
*m_UpdatePad,
wxTimer *m_UpdatePad,
*m_ButtonMappingTimer;
wxStaticBitmap *m_bmpDotLeftIn[4],
@ -77,7 +74,6 @@ class WiimotePadConfigDialog : public wxDialog
DECLARE_EVENT_TABLE();
bool ControlsCreated;
bool LiveUpdates;
int Page, BoxW, BoxH, g_Pressed;
wxNotebook *m_Notebook;
@ -146,9 +142,7 @@ class WiimotePadConfigDialog : public wxDialog
*m_Button_GH3[GH3_CONTROLS][4],
*m_bGH3_Analog[4];
wxStaticText
*m_pStatusBar,
*m_TextScreenWidth[4], *m_TextScreenHeight[4], *m_TextScreenLeft[4], *m_TextScreenTop[4], *m_TextAR[4],
wxStaticText *m_TextScreenWidth[4], *m_TextScreenHeight[4], *m_TextScreenLeft[4], *m_TextScreenTop[4], *m_TextAR[4],
*m_tAnalogX[8], *m_tAnalogY[8], *m_TiltTextRoll[4], *m_TiltTextPitch[4],
*m_CheckC2SLabel[4], *m_ComboDeadZoneLabel[4], *m_TStatusLeftIn[4], *m_TStatusLeftOut[4], *m_TStatusRightIn[4], *m_TStatusRightOut[4],
*m_TriggerStatusL[4], *m_TriggerStatusR[4], *m_TriggerStatusLx[4], *m_TriggerStatusRx[4],
@ -184,12 +178,10 @@ class WiimotePadConfigDialog : public wxDialog
{
ID_CLOSE = 1000,
ID_APPLY,
IDTM_EXIT, // Timer
IDTM_EXIT,
IDTM_BUTTON,
IDTM_UPDATE,
IDTM_UPDATE_PAD,
IDT_DEBUGGING,
IDTM_UPDATE_PAD, // Timer
ID_NOTEBOOK,
ID_CONTROLLERPAGE1,
ID_CONTROLLERPAGE2,
@ -265,9 +257,8 @@ class WiimotePadConfigDialog : public wxDialog
void SaveKeyboardMapping(int Controller, int Id, int Key);
void ToBlank(bool ToBlank = true);
void PadGetStatus();
void UpdateID();
void DoSave(bool ChangePad = false, int Slot = -1);
void DoChangeJoystick(); void DoChangeDeadZone(bool Left);
void DoChangeJoystick(); void PadOpen(int Open); void PadClose(int Close); void DoChangeDeadZone(bool Left);
void OnButtonClick(wxCommandEvent& event);
// Configure buttons

View file

@ -57,14 +57,7 @@ wiimote_key g_ExtKey; // The extension encryption key
bool g_Encryption; // Encryption on or off
// Gamepad input
int NumPads = 0, NumDIDevices = -1; // Number of pads
bool SDLPolling = true;
#ifdef _WIN32
bool LiveUpdates = false;
#else
bool LiveUpdates = false;
#endif
int NumPads = 0, NumGoodPads = 0; // Number of goods pads
std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
InputCommon::CONTROLLER_STATE_NEW PadState[4];
InputCommon::CONTROLLER_MAPPING_NEW PadMapping[4];

View file

@ -182,9 +182,7 @@ static const u8 partially_id[] =
};
// Gamepad input
extern int NumPads, NumDIDevices; // Number of pads
extern bool SDLPolling; // Turn off polling
extern bool LiveUpdates;
extern int NumPads, NumGoodPads; // Number of goods pads
extern std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
extern InputCommon::CONTROLLER_STATE_NEW PadState[4];
extern InputCommon::CONTROLLER_MAPPING_NEW PadMapping[4];

View file

@ -22,7 +22,6 @@
#include "../../../Core/InputCommon/Src/XInput.h"
#include "Common.h" // Common
#include "LogManager.h"
#include "MathUtil.h"
#include "StringUtil.h" // for ArrayToString()
#include "IniFile.h"
@ -60,8 +59,7 @@ void TiltTest(u8 x, u8 y, u8 z)
std::string To = StringFromFormat("%s\nTo: X:%i Y:%i Z:%i Roll:%s Pitch:%s", From.c_str(), x, y, z,
(_Roll >= 0) ? StringFromFormat(" %03i", (int)_Roll).c_str() : StringFromFormat("%04i", (int)_Roll).c_str(),
(_Pitch >= 0) ? StringFromFormat(" %03i", (int)_Pitch).c_str() : StringFromFormat("%04i", (int)_Pitch).c_str());
ConsoleListener* Console = LogManager::GetInstance()->getConsoleListener();
Console->CustomLog(StringFromFormat("\n%s", To.c_str()).c_str());
DEBUG_LOG(WIIMOTE, "%s", To.c_str());
}
@ -102,29 +100,14 @@ void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_
// In these cases we can use the simple and accurate formula
if(g_Config.Trigger.Range.Pitch == 0)
{
if (!g_Config.Trigger.Upright)
{
x = sin(_Roll);
z = cos(_Roll);
}
else
{
z = sin(_Roll);
y = -cos(_Roll);
}
x = sin(_Roll);
z = cos(_Roll);
}
else if (g_Config.Trigger.Range.Roll == 0)
{
if (!g_Config.Trigger.Upright)
{
y = sin(_Pitch);
z = cos(_Pitch);
}
else
{
x = -sin(_Pitch);
y = -cos(_Pitch);
}
y = sin(_Pitch);
z = cos(_Pitch);
}
else
{
@ -135,28 +118,16 @@ void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_
and Pitch. But if we select a Z from the smallest of the absolute
value of cos(Roll) and cos (Pitch) we get the right values. */
// ---------
if (!g_Config.Trigger.Upright)
{
if (abs(cos(_Roll)) < abs(cos(_Pitch))) z = cos(_Roll); else z = cos(_Pitch);
/* I got these from reversing the calculation in
PitchAccelerometerToDegree() in a math program. */
float x_num = 2 * tanf(0.5f * _Roll) * z;
float x_den = pow2f(tanf(0.5f * _Roll)) - 1;
x = - (x_num / x_den);
float y_num = 2 * tanf(0.5f * _Pitch) * z;
float y_den = pow2f(tanf(0.5f * _Pitch)) - 1;
y = - (y_num / y_den);
}
else
{
if (abs(-cos(_Roll)) < abs(-cos(_Pitch))) y = -cos(_Roll); else y = -cos(_Pitch);
float z_num = 2 * tanf(0.5f * _Roll) * y;
float z_den = pow2f(tanf(0.5f * _Roll)) - 1;
z = (z_num / z_den);
float x_num = 2 * tanf(0.5f * _Pitch) * y;
float x_den = pow2f(tanf(0.5f * _Pitch)) - 1;
x = - (x_num / x_den);
}
if (abs(cos(_Roll)) < abs(cos(_Pitch))) z = cos(_Roll); else z = cos(_Pitch);
/* I got these from reversing the calculation in
PitchAccelerometerToDegree() in a math program I don't know if we
can derive these from some kind of matrix or something */
float x_num = 2 * tanf(0.5f * _Roll) * z;
float x_den = pow2f(tanf(0.5f * _Roll)) - 1;
x = - (x_num / x_den);
float y_num = 2 * tanf(0.5f * _Pitch) * z;
float y_den = pow2f(tanf(0.5f * _Pitch)) - 1;
y = - (y_num / y_den);
}
// Multiply with the neutral of z and its g
@ -174,18 +145,9 @@ void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_
if (ix < 0) ix = 0; if (ix > 255) ix = 255;
if (iy < 0) iy = 0; if (iy > 255) iy = 255;
if (iz < 0) iz = 0; if (iz > 255) iz = 255;
if (!g_Config.Trigger.Upright)
{
if(g_Config.Trigger.Range.Roll != 0) _x = ix;
if(g_Config.Trigger.Range.Pitch != 0) _y = iy;
_z = iz;
}
else
{
if(g_Config.Trigger.Range.Roll != 0) _z = iz;
if(g_Config.Trigger.Range.Pitch != 0) _x = ix;
_y = iy;
}
if(g_Config.Trigger.Range.Roll != 0) _x = ix;
if(g_Config.Trigger.Range.Pitch != 0) _y = iy;
_z = iz;
}
// Accelerometer to roll and pitch angles
@ -205,34 +167,17 @@ void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, in
float y = AccelerometerToG((float)_y, (float)g_wm.cal_zero.y, (float)g_wm.cal_g.y);
float z = AccelerometerToG((float)_z, (float)g_wm.cal_zero.z, (float)g_wm.cal_g.z);
if (!g_Config.Trigger.Upright)
// If it is over 1g then it is probably accelerating and may not reliable
//if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x)
{
// If it is over 1g then it is probably accelerating and may not reliable
//if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x)
{
// Calculate the degree
Roll = InputCommon::Rad2Deg(atan2(x, z));
}
//if (abs(_y - g_wm.cal_zero.y) <= g_wm.cal_g.y)
{
// Calculate the degree
Pitch = InputCommon::Rad2Deg(atan2(y, z));
}
// Calculate the degree
Roll = InputCommon::Rad2Deg(atan2(x, z));
}
else
{
//if (abs(accel->z - ac->cal_zero.z) <= ac->cal_g.x)
{
// Calculate the degree
Roll = InputCommon::Rad2Deg(atan2(z, -y));
}
//if (abs(_x - g_wm.cal_zero.x) <= g_wm.cal_g.x)
{
// Calculate the degree
Pitch = InputCommon::Rad2Deg(atan2(-x, -y));
}
//if (abs(_y - g_wm.cal_zero.y) <= g_wm.cal_g.y)
{
// Calculate the degree
Pitch = InputCommon::Rad2Deg(atan2(y, z));
}
_Roll = (int)Roll;
@ -242,16 +187,9 @@ void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, in
if (x < -1.0) x = -1.0; else if (x > 1.0) x = 1.0;
if (y < -1.0) y = -1.0; else if (y > 1.0) y = 1.0;
if (z < -1.0) z = -1.0; else if (z > 1.0) z = 1.0;
if (!g_Config.Trigger.Upright)
{
Roll = InputCommon::Rad2Deg(atan2(x, z));
Pitch = InputCommon::Rad2Deg(atan2(y, z));
}
else
{
Roll = InputCommon::Rad2Deg(atan2(z, -y));
Pitch = InputCommon::Rad2Deg(atan2(-x, -y));
}
Roll = InputCommon::Rad2Deg(atan2(x, z));
Pitch = InputCommon::Rad2Deg(atan2(y, z));
_RollAdj = (int)Roll;
_PitchAdj = (int)Pitch;
}

View file

@ -34,11 +34,6 @@
#include "Encryption.h" // for extension encryption
#include "Config.h" // for g_Config
#if defined(HAVE_WX) && HAVE_WX
#include "ConfigPadDlg.h"
extern WiimotePadConfigDialog *m_PadConfigFrame;
#endif
extern SWiimoteInitialize g_WiimoteInitialize;
namespace WiiMoteEmu
@ -443,12 +438,10 @@ void Initialize()
/* Populate joyinfo for all attached devices and do g_Config.Load() if the
configuration window is not already open, if it's already open we
continue with the settings we have */
#if defined(HAVE_WX) && HAVE_WX
if (!m_PadConfigFrame)
if(!g_FrameOpen)
{
LocalSearchDevices(joyinfo, NumPads);
Search_Devices(joyinfo, NumPads, NumGoodPads);
}
#endif
// Copy extension id and calibration to its register, g_Config.Load() is needed before this
UpdateExtRegisterBlocks();
@ -493,6 +486,7 @@ void DoState(PointerWrap &p)
p.Do(g_Encryption);
p.Do(NumPads);
p.Do(NumGoodPads);
p.Do(joyinfo);
p.DoArray(PadState, 4);
p.DoArray(PadMapping, 4);
@ -515,16 +509,20 @@ void Shutdown(void)
for (int i = 0; i < 1; i++)
{
if (PadMapping[i].enabled && joyinfo.size() > (u32)PadMapping[i].ID)
INFO_LOG(WIIMOTE, "ShutDown: %i", PadState[i].joy);
/* SDL_JoystickClose() crashes for some reason so I avoid this
for now, SDL_Quit() should close the pads to I think */
//if(SDL_JoystickOpened(PadMapping[i].ID)) SDL_JoystickClose(PadState[i].joy);
//PadState[i].joy = NULL;
if (joyinfo.at(PadMapping[i].ID).Good)
{
INFO_LOG(WIIMOTE, "ShutDown: %i", PadState[i].joy);
/* SDL_JoystickClose() crashes for some reason so I avoid this
for now, SDL_Quit() should close the pads to I think */
//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
if (SDL_WasInit(0)) SDL_Quit();
@ -695,8 +693,21 @@ void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
of times per second. */
void Update()
{
readKeyboard();
//LOG(WIIMOTE, "Wiimote_Update");
//INFO_LOG(WIIMOTE, "Emu Update: %i", g_ReportingMode);
// Check if the pad state should be updated
if ((g_Config.Trigger.Type == g_Config.Trigger.TRIGGER || g_Config.Trigger.Type == g_Config.Trigger.ANALOG1 || g_Config.Trigger.Type == g_Config.Trigger.ANALOG2
|| g_Config.Nunchuck.Type == g_Config.Nunchuck.ANALOG1 || g_Config.Nunchuck.Type == g_Config.Nunchuck.ANALOG2
|| g_Config.ClassicController.LType == g_Config.ClassicController.ANALOG1 || g_Config.ClassicController.LType == g_Config.ClassicController.ANALOG2
|| g_Config.ClassicController.RType == g_Config.ClassicController.ANALOG1 || g_Config.ClassicController.RType == g_Config.ClassicController.ANALOG2)
&& NumGoodPads > 0 && joyinfo.size() > (u32)PadMapping[0].ID)
{
const int Page = 0;
WiiMoteEmu::GetJoyState(PadState[Page], PadMapping[Page], Page, joyinfo[PadMapping[Page].ID].NumButtons);
}
switch(g_ReportingMode)
{
case 0:
@ -710,22 +721,9 @@ void Update()
// Potentially send a delayed acknowledgement to an InterruptChannel() Output
CheckAckDelay();
ReadKeyboard();
// Check if the pad state should be updated
if ((g_Config.Trigger.Type == g_Config.Trigger.TRIGGER || g_Config.Trigger.Type == g_Config.Trigger.ANALOG1 || g_Config.Trigger.Type == g_Config.Trigger.ANALOG2
|| g_Config.Nunchuck.Type == g_Config.Nunchuck.ANALOG1 || g_Config.Nunchuck.Type == g_Config.Nunchuck.ANALOG2
|| g_Config.ClassicController.LType == g_Config.ClassicController.ANALOG1 || g_Config.ClassicController.LType == g_Config.ClassicController.ANALOG2
|| g_Config.ClassicController.RType == g_Config.ClassicController.ANALOG1 || g_Config.ClassicController.RType == g_Config.ClassicController.ANALOG2)
&& NumPads > 0 && joyinfo.size() > (u32)PadMapping[0].ID)
{
const int Page = 0;
WiiMoteEmu::GetJoyState(PadState[Page], PadMapping[Page], Page);
}
}
void ReadKeyboard()
void readKeyboard()
{
#if defined(HAVE_X11) && HAVE_X11
XEvent E;

View file

@ -41,7 +41,7 @@ void Shutdown(void);
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size);
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ;
void Update();
void ReadKeyboard();
void readKeyboard();
// Recordings
void LoadRecordedMovements();
@ -52,14 +52,8 @@ void UpdateEeprom();
void UpdateExtRegisterBlocks();
// Gamepad
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);
bool IsConnected(std::string Name);
bool IsPolling();
void EnablePolling(bool Enable);
std::string IDToName(int ID);
void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONTROLLER_MAPPING_NEW _PadMapping, int controller);
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads);
void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONTROLLER_MAPPING_NEW _PadMapping, int controller, int NumButtons);
void PadStateAdjustments(int &Lx, int &Ly, int &Rx, int &Ry, int &Tl, int &Tr);
// Accelerometer

View file

@ -23,7 +23,6 @@
#include "../../../Core/InputCommon/Src/XInput.h"
#include "Common.h" // Common
#include "LogManager.h"
#include "StringUtil.h" // for ArrayToString()
#include "IniFile.h"
#include "pluginspecs_wiimote.h"
@ -36,125 +35,37 @@
#include "Encryption.h" // for extension encryption
#include "Config.h" // for g_Config
#if defined(HAVE_WX) && HAVE_WX
#include "ConfigPadDlg.h"
extern WiimotePadConfigDialog *m_PadConfigFrame;
#endif
extern SWiimoteInitialize g_WiimoteInitialize;
namespace WiiMoteEmu
{
bool LocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
{
//DEBUG_LOG(PAD, "LocalSearchDevices");
bool bSuccess = InputCommon::SearchDevices(_joyinfo, _NumPads);
DoLocalSearchDevices(_joyinfo, _NumPads);
return bSuccess;
}
bool LocalSearchDevicesReset(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
{
DEBUG_LOG(CONSOLE, "LocalSearchDevicesReset");
// Turn off device polling while resetting
EnablePolling(false);
bool bSuccess = InputCommon::SearchDevicesReset(_joyinfo, _NumPads);
DoLocalSearchDevices(_joyinfo, _NumPads);
EnablePolling(true);
return true;
}
// Fill joyinfo with the current connected devices
bool DoLocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
{
//DEBUG_LOG(WIIMOTE, "LocalSearchDevices");
bool WasGotten = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
// Warn the user if no gamepads are detected
if (_NumPads == 0 && g_EmulatorRunning)
if (_NumGoodPads == 0 && g_EmulatorRunning)
{
//PanicAlert("Wiimote: No Gamepad Detected");
//PanicAlert("nJoy: No Gamepad Detected");
//return false;
}
// Load the first time
if (!g_Config.Loaded) g_Config.Load();
// Load PadMapping[] etc
g_Config.Load();
// Update the PadState[].joy handle
// If the saved ID matches, select this device for this slot
bool Match = false;
for (int i = 0; i < MAX_WIIMOTES; i++)
{
for (int j = 0; j < joyinfo.size(); j++)
{
if (joyinfo.at(j).Name == PadMapping[i].Name)
{
PadState[i].joy = joyinfo.at(j).joy;
Match = true;
//INFO_LOG(WIIMOTE, "Slot %i: '%s' %06i", i, joyinfo.at(j).Name.c_str(), PadState[i].joy);
}
}
if (!Match) PadState[i].joy = NULL;
}
return true;
}
// Is the device connected?
// ----------------
bool IsConnected(std::string Name)
{
for (int i = 0; i < joyinfo.size(); i++)
for (int i = 0; i < 1; i++)
{
DEBUG_LOG(WIIMOTE, "Pad %i: IsConnected checking '%s' against '%s'", i, joyinfo.at(i).Name.c_str(), Name.c_str());
if (joyinfo.at(i).Name == Name)
return true;
if (PadMapping[i].enabled && joyinfo.size() > (u32)PadMapping[i].ID)
if(joyinfo.at(PadMapping[i].ID).Good)
PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID);
}
}
// See description of the equivalent functions in nJoy.cpp...
// ----------------
bool IsPolling()
{
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(WIIMOTE, "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 "";
return WasGotten;
}
// Return adjusted input values
void PadStateAdjustments(int &Lx, int &Ly, int &Rx, int &Ry, int &Tl, int &Tr)
{
@ -208,20 +119,11 @@ void PadStateAdjustments(int &Lx, int &Ly, int &Rx, int &Ry, int &Tl, int &Tr)
Function: Updates the PadState struct with the current pad status. The input
value "controller" is for a virtual controller 0 to 3. */
void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONTROLLER_MAPPING_NEW _PadMapping, int controller)
void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONTROLLER_MAPPING_NEW _PadMapping, int controller, int NumButtons)
{
//DEBUG_LOG(WIIMOTE, "GetJoyState: Polling:%i NumPads:%i", SDLPolling, NumPads);
// Return if polling is off
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. We don't need to run this this often. Once a second would be enough.
if (LiveUpdates) LocalSearchDevices(joyinfo, NumPads);
// Return if we have no pads
if (NumPads == 0) return;
// Read info
int NumButtons = SDL_JoystickNumButtons(_PadState.joy);
if (NumGoodPads == 0) return;
// Update the gamepad status
SDL_JoystickUpdate();
@ -250,13 +152,14 @@ void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONT
}
#endif
/* Debugging
ConsoleListener* Console = LogManager::GetInstance()->getConsoleListener();
Console->ClearScreen();
Console->CustomLog(StringFromFormat(
"Controller: %i Handle: %i\n"
"Triggers: %i %i %i %i %i\n"
"Analog: %06i %06i \n",
/* Debugging
// Console::ClearScreen();
DEBUG_LOG(CONSOLE,
"Controller and handle: %i %i\n"
"Triggers:%i %i %i %i %i\n"
"Analog:%06i %06i \n",
controller, (int)_PadState.joy,
@ -265,8 +168,7 @@ void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONT
_PadState.Axis.Tl, _PadState.Axis.Tr,
_PadState.Axis.Lx, _PadState.Axis.Ly
).c_str());
*/
);*/
}

View file

@ -21,7 +21,6 @@
#include <string>
#include "Common.h" // Common
#include "LogManager.h"
#include "Timer.h"
#include "pluginspecs_wiimote.h"
#include "StringUtil.h" // For ArrayToString
@ -441,7 +440,7 @@ void SingleShake(u8 &_y, u8 &_z, int i)
void TiltWiimoteGamepad(float &Roll, float &Pitch)
{
// Return if we have no pads
if (NumPads == 0) return;
if (NumGoodPads == 0) return;
// This has to be changed if multiple Wiimotes are to be supported later
const int Page = 0;

View file

@ -420,13 +420,11 @@ bool IsFocus()
HWND Parent = GetParent(RenderingWindow);
HWND TopLevel = GetParent(Parent);
// Allow updates when the config window is in focus to
HWND Config = NULL, ConfigPad = NULL, ConfigRecording = NULL;
if (m_BasicConfigFrame) Config = (HWND)m_BasicConfigFrame->GetHWND();
if (m_PadConfigFrame) ConfigPad = (HWND)m_PadConfigFrame->GetHWND();
if (m_RecordingConfigFrame) ConfigRecording = (HWND)m_RecordingConfigFrame->GetHWND();
HWND Config = NULL;
if (m_BasicConfigFrame)
Config = (HWND)m_BasicConfigFrame->GetHWND();
// Support both rendering to main window and not
if (GetForegroundWindow() == TopLevel || GetForegroundWindow() == RenderingWindow || GetForegroundWindow() == Config
|| GetForegroundWindow() == ConfigPad || GetForegroundWindow() == ConfigRecording)
if (GetForegroundWindow() == TopLevel || GetForegroundWindow() == RenderingWindow || GetForegroundWindow() == Config)
return true;
else
return false;
@ -759,14 +757,12 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
// ---------------------------------------------
// Test the angles to x, y, z values formula by calculating the values back and forth
// -----------
/**/
ConsoleListener* Console = LogManager::GetInstance()->getConsoleListener();
Console->ClearScreen();
/* //Console::ClearScreen();
// Show a test of our calculations
WiiMoteEmu::TiltTest(data[4], data[5], data[6]);
//u8 x, y, z;
//WiiMoteEmu::Tilt(x, y, z);
//WiiMoteEmu::TiltTest(x, y, z);
u8 x, y, z;
WiiMoteEmu::Tilt(x, y, z);
WiiMoteEmu::TiltTest(x, y, z);*/
// -------------------------
// ---------------------------------------------

View file

@ -35,7 +35,7 @@ int GetUpdateRate();
void InterruptDebugging(bool Emu, const void* _pData);
void ReadDebugging(bool Emu, const void* _pData, int Size);
bool IsFocus();
#define MAX_WIIMOTES 1
// Movement recording
#define RECORDING_ROWS 15

View file

@ -26,6 +26,8 @@
namespace WiiMoteReal
{
#define MAX_WIIMOTES 1
int Initialize();
void DoState(PointerWrap &p);
void Shutdown(void);