mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
nJoy:
1. Circumvent the IDirectInputDevice2::SetDataFormat() error when opening the configuration window to. 2. Fixed the Allow out of focus input option again 3. Allow changing of the mapped pads while a game is running 4. Prevented crashes or problems from any combination of having the configuration window open when a game is started or stopped 5. Fixed a crash that would occur after nJoy was started with a connected pad, then stopped, and all pads disconnected, then started again git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2215 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -63,6 +63,8 @@ void Config::Load(bool ChangePad)
|
||||
iniFile.Get(SectionName.c_str(), "NoTriggerFilter", &bNoTriggerFilter, false);
|
||||
iniFile.Get(SectionName.c_str(), "TriggerType", &Trigger.Type, TRIGGER_OFF);
|
||||
iniFile.Get(SectionName.c_str(), "TriggerRange", &Trigger.Range, 50);
|
||||
iniFile.Get(SectionName.c_str(), "TriggerRoll", &Trigger.Roll, false);
|
||||
iniFile.Get(SectionName.c_str(), "TriggerPitch", &Trigger.Pitch, false);
|
||||
|
||||
// Don't update this when we are loading settings from the ConfigBox
|
||||
if(!ChangePad)
|
||||
@ -133,6 +135,8 @@ void Config::Save(int Slot)
|
||||
iniFile.Set(SectionName.c_str(), "NoTriggerFilter", bNoTriggerFilter);
|
||||
iniFile.Set(SectionName.c_str(), "TriggerType", Trigger.Type);
|
||||
iniFile.Set(SectionName.c_str(), "TriggerRange", Trigger.Range);
|
||||
iniFile.Set(SectionName.c_str(), "TriggerRoll", Trigger.Roll);
|
||||
iniFile.Set(SectionName.c_str(), "TriggerPitch", Trigger.Pitch);
|
||||
|
||||
// Save the physical device ID number
|
||||
iniFile.Set(SectionName.c_str(), "DeviceID", WiiMoteEmu::PadMapping[i].ID);
|
||||
|
@ -28,6 +28,8 @@ struct Config
|
||||
{
|
||||
int Type;
|
||||
int Range;
|
||||
int Roll;
|
||||
int Pitch;
|
||||
};
|
||||
|
||||
enum ETriggerType
|
||||
|
@ -585,12 +585,12 @@ void ConfigDialog::PadGetStatus()
|
||||
void ConfigDialog::UpdatePad(wxTimerEvent& WXUNUSED(event))
|
||||
{
|
||||
// Show the current status
|
||||
/**/
|
||||
/*
|
||||
#ifdef SHOW_PAD_STATUS
|
||||
m_pStatusBar->SetLabel(wxString::Format(
|
||||
"%s", ShowStatus(notebookpage).c_str()
|
||||
));
|
||||
#endif
|
||||
#endif*/
|
||||
|
||||
//LogMsg("Abc%s\n", ShowStatus(notebookpage).c_str());
|
||||
|
||||
|
@ -44,59 +44,84 @@
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
void PitchDegreeToAccelerometer(float _Degree, u8 &_y, u8 &_z)
|
||||
void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_z, bool RollOn, bool PitchOn)
|
||||
{
|
||||
// Then don't update z either
|
||||
if (!RollOn && ! PitchOn) return;
|
||||
|
||||
// Calculate the radian
|
||||
float d_rad = _Degree * M_PI / 180.0;
|
||||
float _RollRad = _Roll * M_PI / 180.0;
|
||||
float _PitchRad = _Pitch * M_PI / 180.0;
|
||||
|
||||
// Calculate a good set of y and z values for the degree
|
||||
float r = 1.0;
|
||||
float fy = r * sin(d_rad); // y
|
||||
float fz = r * cos(d_rad); // x
|
||||
float fx = r * sin(_RollRad); // y
|
||||
float fy = r * sin(_PitchRad); // y
|
||||
float fz = r * cos(_PitchRad); // x
|
||||
|
||||
// Multiple with the neutral of z and its g
|
||||
float xg = g_accel.cal_g.x;
|
||||
float yg = g_accel.cal_g.y;
|
||||
float zg = g_accel.cal_g.z;
|
||||
float x_zero = g_accel.cal_zero.x;
|
||||
float y_zero = g_accel.cal_zero.y;
|
||||
float z_zero = g_accel.cal_zero.z;
|
||||
fx = (int) (x_zero + xg * fx);
|
||||
fy = (int) (y_zero + yg * fy);
|
||||
fz = (int) (z_zero + zg * fz);
|
||||
|
||||
// Boundaries
|
||||
int ix = (int)fx;
|
||||
int iy = (int)fy;
|
||||
int iz = (int)fz;
|
||||
if (iy < 0) iy = 0;
|
||||
if (iy > 255) iy = 255;
|
||||
_y = iy;
|
||||
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 (RollOn) _x = ix;
|
||||
if (PitchOn) _y = iy;
|
||||
_z = iz;
|
||||
}
|
||||
|
||||
|
||||
int PitchAccelerometerToDegree(u8 _y, u8 _z)
|
||||
// The pitch and roll in 360<36>
|
||||
void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch)
|
||||
{
|
||||
/* find out how much it has to move to be 1g */
|
||||
float xg = (float)g_accel.cal_g.x;
|
||||
float yg = (float)g_accel.cal_g.y;
|
||||
float zg = (float)g_accel.cal_g.z;
|
||||
float d = 0;
|
||||
float Pitch = 0, Roll = 0;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
float x = ((float)_x - (float)g_accel.cal_zero.x) / xg;
|
||||
float y = ((float)_y - (float)g_accel.cal_zero.y) / yg;
|
||||
float z = ((float)_z - (float)g_accel.cal_zero.z) / zg;
|
||||
|
||||
/* make sure x,y,z are between -1 and 1 for the tan function */
|
||||
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 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 radian
|
||||
Roll = atan2(x, z);
|
||||
// Calculate the degree
|
||||
Roll = (Roll * 180.0) / M_PI;
|
||||
}
|
||||
|
||||
//if (abs(_y - g_accel.cal_zero.y) <= g_accel.cal_g.y)
|
||||
{
|
||||
// Calculate the radian
|
||||
d = atan2(y, z);
|
||||
Pitch = atan2(y, z);
|
||||
// Calculate the degree
|
||||
d = (d * 180.0) / M_PI;
|
||||
Pitch = (Pitch * 180.0) / M_PI;
|
||||
}
|
||||
return (int)d;
|
||||
_Roll = Roll;
|
||||
_Pitch = Pitch;
|
||||
}
|
||||
|
||||
}
|
||||
} // WiiMoteEmu
|
@ -51,8 +51,8 @@ void SetDefaultExtensionRegistry();
|
||||
// Gamepad
|
||||
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 PitchDegreeToAccelerometer(float _Degree, u8 &_y, u8 &_z);
|
||||
int PitchAccelerometerToDegree(u8 _y, u8 _z);
|
||||
void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_z, bool RollOn, bool PitchOn);
|
||||
void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch);
|
||||
|
||||
|
||||
}; // WiiMoteEmu
|
||||
|
@ -357,7 +357,7 @@ void SingleShake(u8 &_z, u8 &_y)
|
||||
}
|
||||
else // the default Z if nothing is pressed
|
||||
{
|
||||
z = Z;
|
||||
_z = Z;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -367,7 +367,7 @@ void SingleShake(u8 &_z, u8 &_y)
|
||||
measure of the tilting of the Wiimote. We are interested in this tilting range
|
||||
90<39> to -90<39> */
|
||||
// ---------------
|
||||
void TiltWiimoteGamepad(u8 &_y, u8 &_z)
|
||||
void TiltWiimoteGamepad(u8 &_x, u8 &_y, u8 &_z)
|
||||
{
|
||||
// Return if we have no pads
|
||||
if (NumGoodPads == 0) return;
|
||||
@ -395,10 +395,8 @@ void TiltWiimoteGamepad(u8 &_y, u8 &_z)
|
||||
}
|
||||
|
||||
// It's easier to use a float here
|
||||
float Degree = 0;
|
||||
// Calculate the present room between the neutral and the maximum values
|
||||
float RoomAbove = 255.0 - (float)Y;
|
||||
float RoomBelow = (float)Y;
|
||||
float Roll = 0;
|
||||
float Pitch = 0;
|
||||
// Save the Range in degrees, 45<34> and 90<39> are good values in some games
|
||||
float Range = (float)g_Config.Trigger.Range;
|
||||
|
||||
@ -409,8 +407,8 @@ void TiltWiimoteGamepad(u8 &_y, u8 &_z)
|
||||
Tl = Tl / 2;
|
||||
Tr = Tr / 2;
|
||||
|
||||
Degree = Tl * (Range / 128)
|
||||
- Tr * (Range / 128);
|
||||
Pitch = Tl * (Range / 128)
|
||||
- Tr * (Range / 128);
|
||||
}
|
||||
|
||||
// Analog stick
|
||||
@ -418,12 +416,14 @@ void TiltWiimoteGamepad(u8 &_y, u8 &_z)
|
||||
{
|
||||
// Adjust the trigger to go between negative and positive values
|
||||
Lx = Lx - 128;
|
||||
Ly = Ly - 128;
|
||||
// Produce the final value
|
||||
Degree = -Lx * (Range / 128);
|
||||
Pitch = -Lx * (Range / 128);
|
||||
Roll = -Ly * (Range / 128);
|
||||
}
|
||||
|
||||
// Calculate the acceleometer value from this tilt angle
|
||||
PitchDegreeToAccelerometer(Degree, _y, _z);
|
||||
// Calculate the accelerometer value from this tilt angle
|
||||
PitchDegreeToAccelerometer(Roll, Pitch, _x, _y, _z, g_Config.Trigger.Roll, g_Config.Trigger.Pitch);
|
||||
|
||||
//Console::ClearScreen();
|
||||
/*Console::Print("L:%2.1f R:%2.1f Lx:%2.1f Range:%2.1f Degree:%2.1f L:%i R:%i\n",
|
||||
@ -476,7 +476,8 @@ void TiltWiimoteKeyboard(u8 &_y, u8 &_z)
|
||||
}
|
||||
else
|
||||
{
|
||||
PitchDegreeToAccelerometer(KbDegree, _y, _z);
|
||||
u8 x;
|
||||
PitchDegreeToAccelerometer(KbDegree, 0, x, _y, _z, false, true);
|
||||
//Console::Print("Degree: %2.1f\n", KbDegree);
|
||||
}
|
||||
// --------------------
|
||||
@ -519,6 +520,11 @@ void FillReportAcc(wm_accel& _acc)
|
||||
// ------------------------------------------------
|
||||
// Wiimote to Gamepad translations
|
||||
// ------------
|
||||
|
||||
// The following functions may or may not update these values
|
||||
x = X;
|
||||
y = Y;
|
||||
z = Z;
|
||||
|
||||
// Shake the Wiimote
|
||||
SingleShake(z, y);
|
||||
@ -527,10 +533,10 @@ void FillReportAcc(wm_accel& _acc)
|
||||
if (g_Config.Trigger.Type == g_Config.KEYBOARD)
|
||||
TiltWiimoteKeyboard(y, z);
|
||||
else if (g_Config.Trigger.Type == g_Config.TRIGGER || g_Config.Trigger.Type == g_Config.ANALOG)
|
||||
TiltWiimoteGamepad(y, z);
|
||||
TiltWiimoteGamepad(x, y, z);
|
||||
|
||||
// Write values
|
||||
_acc.x = X;
|
||||
// Write final values
|
||||
_acc.x = x;
|
||||
_acc.y = y;
|
||||
_acc.z = z;
|
||||
|
||||
|
@ -626,10 +626,12 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
|
||||
std::string Tmp2 = TmpData.substr(68, (TmpData.length() - 68));
|
||||
TmpData = Tmp1 + StringFromFormat("%03i %03i %03i", data[19], data[20], data[21]) + Tmp2;
|
||||
}
|
||||
// Calculate the Wiimote pitch in degrees
|
||||
std::string Pitch = StringFromFormat("%i", WiiMoteEmu::PitchAccelerometerToDegree(data[5], data[6]));
|
||||
// Calculate the Wiimote roll and pitch in degrees
|
||||
int Roll, Pitch;
|
||||
WiiMoteEmu::PitchAccelerometerToDegree(data[4], data[5], data[6], Roll, Pitch);
|
||||
std::string RollPitch = StringFromFormat("%i %i", Roll, Pitch);
|
||||
|
||||
Console::Print("Read[%s]: %s| %s\n", (Emu ? "Emu" : "Real"), TmpData.c_str(), Pitch.c_str()); // No timestamp
|
||||
Console::Print("Read[%s]: %s| %s\n", (Emu ? "Emu" : "Real"), TmpData.c_str(), RollPitch.c_str()); // No timestamp
|
||||
//Console::Print(" (%s): %s\n", Tm(true).c_str(), Temp.c_str()); // Timestamp
|
||||
}
|
||||
if(g_DebugAccelerometer)
|
||||
|
Reference in New Issue
Block a user