mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Some Wiimote Cleanup, re/moved some globals to where they belong.
A few things could be solved differently/in a better way, but that would involve some classes and stuff (plus work) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5097 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@@ -65,10 +65,8 @@ WiimoteBasicConfigDialog::WiimoteBasicConfigDialog(wxWindow *parent, wxWindowID
|
||||
ControlsCreated = false;
|
||||
m_Page = 0;
|
||||
|
||||
m_bEnableUseRealWiimote = true;
|
||||
// Initialize the Real WiiMotes here, so we get a count of how many were found and set everything properly
|
||||
if (!g_RealWiiMoteInitialized)
|
||||
WiiMoteReal::Initialize();
|
||||
WiiMoteReal::Initialize();
|
||||
|
||||
CreateGUIControls();
|
||||
UpdateGUI();
|
||||
@@ -293,19 +291,17 @@ void WiimoteBasicConfigDialog::UpdateOnce(wxTimerEvent& event)
|
||||
{
|
||||
case IDTM_UPDATE_ONCE:
|
||||
// Reenable the checkbox
|
||||
m_bEnableUseRealWiimote = true;
|
||||
SetCursor(wxCursor(wxCURSOR_ARROW));
|
||||
UpdateGUI();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_WIIUSE
|
||||
void WiimoteBasicConfigDialog::DoRefreshReal()
|
||||
{
|
||||
if (g_RealWiiMoteInitialized)
|
||||
WiiMoteReal::Shutdown();
|
||||
if (!g_RealWiiMoteInitialized)
|
||||
WiiMoteReal::Initialize();
|
||||
WiiMoteReal::Shutdown();
|
||||
WiiMoteReal::Initialize();
|
||||
}
|
||||
|
||||
void WiimoteBasicConfigDialog::DoUseReal()
|
||||
@@ -332,7 +328,6 @@ void WiimoteBasicConfigDialog::DoUseReal()
|
||||
{
|
||||
// Disable the checkbox for a moment
|
||||
SetCursor(wxCursor(wxCURSOR_WAIT));
|
||||
m_bEnableUseRealWiimote = false;
|
||||
// We may not need this if there is already a message queue that allows the nessesary timeout
|
||||
//sleep(100);
|
||||
|
||||
@@ -342,6 +337,7 @@ void WiimoteBasicConfigDialog::DoUseReal()
|
||||
m_TimeoutOnce->Start(1000, true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Generate connect/disconnect status event
|
||||
void WiimoteBasicConfigDialog::DoExtensionConnectedDisconnected(int Extension)
|
||||
|
||||
@@ -56,7 +56,7 @@ class WiimoteBasicConfigDialog : public wxDialog
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
bool ControlsCreated, m_bEnableUseRealWiimote;
|
||||
bool ControlsCreated;
|
||||
int m_Page;
|
||||
|
||||
wxNotebook *m_Notebook;
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
#endif
|
||||
|
||||
// Replace the harder to understand -1 with "" for the sake of user friendliness
|
||||
void WiimotePadConfigDialog::ToBlank(bool ToBlank, int Id)
|
||||
void WiimotePadConfigDialog::ToBlank(bool toBlank, int Id)
|
||||
{
|
||||
if (!m_ControlsCreated)
|
||||
return;
|
||||
|
||||
if(ToBlank)
|
||||
if(toBlank)
|
||||
{
|
||||
if (GetButtonText(Id) == wxString(wxT("-1")))
|
||||
SetButtonText(Id, wxString());
|
||||
|
||||
@@ -97,9 +97,9 @@ void WiimoteRecordingConfigDialog::CloseClick(wxCommandEvent& event)
|
||||
switch(event.GetId())
|
||||
{
|
||||
case ID_CLOSE:
|
||||
if (g_RealWiiMoteInitialized)
|
||||
WiiMoteReal::g_StopThreadTemporary.Set(); //WiiMoteReal::SafecloseRemoteFunc over takes the closing of the Dlg
|
||||
else
|
||||
#if HAVE_WIIUSE
|
||||
if (!WiiMoteReal::SafeClose())
|
||||
#endif
|
||||
Close();
|
||||
break;
|
||||
case ID_APPLY:
|
||||
|
||||
@@ -417,246 +417,4 @@ void RotateIRDot(int &_x, int &_y, STiltData &_TiltData)
|
||||
if (_y < 0 || _y > 767) _y = 0xFFFF;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
// Test the calculations
|
||||
void TiltTest(u8 x, u8 y, u8 z)
|
||||
{
|
||||
int Roll, Pitch, RollAdj, PitchAdj;
|
||||
PitchAccelerometerToDegree(x, y, z, Roll, Pitch, RollAdj, PitchAdj);
|
||||
std::string From = StringFromFormat("From: X:%i Y:%i Z:%i Roll:%s Pitch:%s", x, y, z,
|
||||
(Roll >= 0) ? StringFromFormat(" %03i", Roll).c_str() : StringFromFormat("%04i", Roll).c_str(),
|
||||
(Pitch >= 0) ? StringFromFormat(" %03i", Pitch).c_str() : StringFromFormat("%04i", Pitch).c_str());
|
||||
|
||||
float _Roll = (float)Roll, _Pitch = (float)Pitch;
|
||||
PitchDegreeToAccelerometer(_Roll, _Pitch, x, y, 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());
|
||||
NOTICE_LOG(CONSOLE, "\n%s", To.c_str());
|
||||
}
|
||||
|
||||
// Accelerometer to roll and pitch angles
|
||||
float AccelerometerToG(float Current, float Neutral, float G)
|
||||
{
|
||||
float _G = (Current - Neutral) / G;
|
||||
return _G;
|
||||
}
|
||||
|
||||
void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, int &_RollAdj, int &_PitchAdj)
|
||||
{
|
||||
// Definitions
|
||||
float Roll = 0, Pitch = 0;
|
||||
|
||||
// Calculate how many g we are from the neutral
|
||||
float x = AccelerometerToG((float)_x, (float)g_wm.cal_zero.x, (float)g_wm.cal_g.x);
|
||||
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.bUpright)
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
_Roll = (int)Roll;
|
||||
_Pitch = (int)Pitch;
|
||||
|
||||
// Don't allow forces bigger than 1g
|
||||
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.bUpright)
|
||||
{
|
||||
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));
|
||||
}
|
||||
_RollAdj = (int)Roll;
|
||||
_PitchAdj = (int)Pitch;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// IR data functions
|
||||
//******************************************************************************
|
||||
|
||||
// Calculate dot positions from the basic 10 byte IR data
|
||||
void IRData2DotsBasic(u8 *Data)
|
||||
{
|
||||
struct SDot* Dot = g_Wiimote_kbd.IR.Dot;
|
||||
|
||||
Dot[0].Rx = 1023 - (Data[0] | ((Data[2] & 0x30) << 4));
|
||||
Dot[0].Ry = Data[1] | ((Data[2] & 0xc0) << 2);
|
||||
|
||||
Dot[1].Rx = 1023 - (Data[3] | ((Data[2] & 0x03) << 8));
|
||||
Dot[1].Ry = Data[4] | ((Data[2] & 0x0c) << 6);
|
||||
|
||||
Dot[2].Rx = 1023 - (Data[5] | ((Data[7] & 0x30) << 4));
|
||||
Dot[2].Ry = Data[6] | ((Data[7] & 0xc0) << 2);
|
||||
|
||||
Dot[3].Rx = 1023 - (Data[8] | ((Data[7] & 0x03) << 8));
|
||||
Dot[3].Ry = Data[9] | ((Data[7] & 0x0c) << 6);
|
||||
|
||||
// set each IR spot to visible if spot is in range
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
if (Dot[i].Ry == 1023)
|
||||
{
|
||||
Dot[i].Visible = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dot[i].Visible = 1;
|
||||
Dot[i].Size = 0; // since we don't know the size, set it as 0
|
||||
}
|
||||
|
||||
// For now we let our virtual resolution be the same as the default one
|
||||
Dot[i].X = Dot[i].Rx; Dot[i].Y = Dot[i].Ry;
|
||||
}
|
||||
|
||||
// Calculate the other values
|
||||
ReorderIRDots();
|
||||
IRData2Distance();
|
||||
}
|
||||
|
||||
// Calculate dot positions from the extented 12 byte IR data
|
||||
void IRData2Dots(u8 *Data)
|
||||
{
|
||||
struct SDot* Dot = g_Wiimote_kbd.IR.Dot;
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
//Console::Print("Rx: %i\n", Dot[i].Rx);
|
||||
|
||||
Dot[i].Rx = 1023 - (Data[3*i] | ((Data[(3*i)+2] & 0x30) << 4));
|
||||
Dot[i].Ry = Data[(3*i)+1] | ((Data[(3*i)+2] & 0xc0) << 2);
|
||||
|
||||
Dot[i].Size = Data[(3*i)+2] & 0x0f;
|
||||
|
||||
// if in range set to visible
|
||||
if (Dot[i].Ry == 1023)
|
||||
Dot[i].Visible = false;
|
||||
else
|
||||
Dot[i].Visible = true;
|
||||
|
||||
//Console::Print("Rx: %i\n", Dot[i].Rx);
|
||||
|
||||
// For now we let our virtual resolution be the same as the default one
|
||||
Dot[i].X = Dot[i].Rx; Dot[i].Y = Dot[i].Ry;
|
||||
}
|
||||
|
||||
// Calculate the other values
|
||||
ReorderIRDots();
|
||||
IRData2Distance();
|
||||
}
|
||||
|
||||
// Reorder the IR dots according to their x-axis value
|
||||
void ReorderIRDots()
|
||||
{
|
||||
// Create a shortcut
|
||||
SDot* Dot = g_Wiimote_kbd.IR.Dot;
|
||||
|
||||
// Variables
|
||||
int i, j, order;
|
||||
|
||||
// Reset the dot ordering to zero
|
||||
for (i = 0; i < 4; ++i)
|
||||
Dot[i].Order = 0;
|
||||
|
||||
// is this just a weird filter+sort?
|
||||
for (order = 1; order < 5; ++order)
|
||||
{
|
||||
i = 0;
|
||||
|
||||
//
|
||||
for (; !Dot[i].Visible || Dot[i].Order; ++i)
|
||||
if (i > 4) return;
|
||||
|
||||
//
|
||||
for (j = 0; j < 4; ++j)
|
||||
{
|
||||
if (Dot[j].Visible && !Dot[j].Order && (Dot[j].X < Dot[i].X))
|
||||
i = j;
|
||||
}
|
||||
|
||||
Dot[i].Order = order;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate dot positions from the extented 12 byte IR data
|
||||
void IRData2Distance()
|
||||
{
|
||||
// Create a shortcut
|
||||
struct SDot* Dot = g_Wiimote_kbd.IR.Dot;
|
||||
|
||||
// Make these ones global
|
||||
int i1, i2;
|
||||
|
||||
for (i1 = 0; i1 < 4; ++i1)
|
||||
if (Dot[i1].Visible) break;
|
||||
|
||||
// Only one dot was visible, we can not calculate the distance
|
||||
if (i1 == 4) { g_Wiimote_kbd.IR.Distance = 0; return; }
|
||||
|
||||
// Look at the next dot
|
||||
for (i2 = i1 + 1; i2 < 4; ++i2)
|
||||
if (Dot[i2].Visible) break;
|
||||
|
||||
// Only one dot was visible, we can not calculate the distance
|
||||
if (i2 == 4) { g_Wiimote_kbd.IR.Distance = 0; return; }
|
||||
|
||||
// For the emulated Wiimote the y distance is always zero so then the distance is the
|
||||
// simple distance between the x dots, i.e. the sensor bar width
|
||||
int xd = Dot[i2].X - Dot[i1].X;
|
||||
int yd = Dot[i2].Y - Dot[i1].Y;
|
||||
|
||||
// Save the distance
|
||||
g_Wiimote_kbd.IR.Distance = (int)sqrt((float)(xd*xd) + (float)(yd*yd));
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// Classic Controller functions
|
||||
//******************************************************************************
|
||||
|
||||
std::string CCData2Values(u8 *Data)
|
||||
{
|
||||
return StringFromFormat(
|
||||
"Tl:%03i Tr:%03i Lx:%03i Ly:%03i Rx:%03i Ry:%03i",
|
||||
(((Data[2] & 0x60) >> 2) | ((Data[3] & 0xe0) >> 5)),
|
||||
(Data[3] & 0x1f),
|
||||
(Data[0] & 0x3f),
|
||||
(Data[1] & 0x3f),
|
||||
((Data[0] & 0xc0) >> 3) | ((Data[1] & 0xc0) >> 5) | ((Data[2] & 0x80) >> 7),
|
||||
(Data[2] & 0x1f));
|
||||
}
|
||||
*/
|
||||
|
||||
} // WiiMoteEmu
|
||||
|
||||
@@ -36,6 +36,14 @@ extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
// Settings
|
||||
accel_cal g_wm;
|
||||
nu_cal g_nu;
|
||||
cc_cal g_ClassicContCalibration;
|
||||
gh3_cal g_GH3Calibration;
|
||||
|
||||
bool g_EmulatedWiiMoteInitialized = false;
|
||||
|
||||
/* Homebrew encryption for 16 byte zero keys. */
|
||||
void CryptBuffer(u8* _buffer, u8 _size)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,14 @@
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
// TODO: those are only used with Emulated wiimote.
|
||||
// if it were a class, we didn't need the extern here.
|
||||
// Settings
|
||||
extern accel_cal g_wm;
|
||||
extern nu_cal g_nu;
|
||||
extern cc_cal g_ClassicContCalibration;
|
||||
extern gh3_cal g_GH3Calibration;
|
||||
|
||||
u32 convert24bit(const u8* src);
|
||||
u16 convert16bit(const u8* src);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -63,15 +63,6 @@ struct SRecordingAll
|
||||
extern u32 g_ISOId;
|
||||
extern bool g_SearchDeviceDone;
|
||||
extern bool g_RealWiiMotePresent;
|
||||
extern bool g_RealWiiMoteInitialized;
|
||||
extern bool g_RealWiiMoteAllocated;
|
||||
extern bool g_EmulatedWiiMoteInitialized;
|
||||
|
||||
// Settings
|
||||
extern accel_cal g_wm;
|
||||
extern nu_cal g_nu;
|
||||
extern cc_cal g_ClassicContCalibration;
|
||||
extern gh3_cal g_GH3Calibration;
|
||||
|
||||
// Debugging
|
||||
extern bool g_DebugAccelerometer;
|
||||
|
||||
@@ -49,6 +49,9 @@ extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
namespace WiiMoteReal
|
||||
{
|
||||
|
||||
bool g_RealWiiMoteInitialized = false;
|
||||
bool g_RealWiiMoteAllocated = false;
|
||||
|
||||
// Forwarding
|
||||
|
||||
class CWiiMote;
|
||||
@@ -387,6 +390,8 @@ int Initialize()
|
||||
// Allocate each Real WiiMote found to a WiiMote slot with Source set to "WiiMote Real"
|
||||
void Allocate()
|
||||
{
|
||||
if (g_RealWiiMoteAllocated)
|
||||
return;
|
||||
if (!g_RealWiiMoteInitialized)
|
||||
Initialize();
|
||||
|
||||
@@ -469,6 +474,8 @@ void DoState(PointerWrap &p)
|
||||
|
||||
void Shutdown(void)
|
||||
{
|
||||
if (!g_RealWiiMoteInitialized)
|
||||
return;
|
||||
// Stop the loop in the thread
|
||||
g_Shutdown = true; // not safe .. might crash when still @ReadWiimote
|
||||
|
||||
@@ -553,6 +560,20 @@ THREAD_RETURN ReadWiimote_ThreadFunc(void* arg)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Returns whether SafeClose_ThreadFunc will take over closing of Recording dialog.
|
||||
// FIXME: this whole threading stuff is bad, and should be removed.
|
||||
// OSX is having problems with the threading anyways, since WiiUse is used
|
||||
// from multiple threads, and not just the one where it was created on.
|
||||
bool SafeClose()
|
||||
{
|
||||
if (!g_RealWiiMoteInitialized)
|
||||
return false;
|
||||
|
||||
g_StopThreadTemporary.Set();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Thread to avoid racing conditions by directly closing of ReadWiimote_ThreadFunc() resp. ReadWiimote()
|
||||
// shutting down the Dlg while still beeing @ReadWiimote will result in a crash;
|
||||
THREAD_RETURN SafeCloseReadWiimote_ThreadFunc(void* arg)
|
||||
|
||||
@@ -45,6 +45,8 @@ void SendAcc(u8 _ReportID);
|
||||
void SetDataReportingMode(u8 ReportingMode = 0);
|
||||
void ClearEvents();
|
||||
|
||||
bool SafeClose();
|
||||
|
||||
// The alternative Wiimote loop
|
||||
void ReadWiimote();
|
||||
bool IRDataOK(struct wiimote_t* wm);
|
||||
|
||||
Reference in New Issue
Block a user