From 69fdb7ae5c226d015378de5c2c3d5ee7913fabc3 Mon Sep 17 00:00:00 2001 From: fgfemperor Date: Fri, 8 Jan 2010 20:27:54 +0000 Subject: [PATCH] Added Nunchuk to the Wiimote Recording window. Now you can know if your Nunchuk is working as it should =P Also fixed the crash when clicking OK while having one WiiMote active. Nunchuck's gravity is kinda wrong, don't know why though, We don't know if it's Wiiuse's fault or if the nunchuk has different vars... Punchout @ingame the nunchuk gravity also doesn't work... All the work done by sanchez! git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4794 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_Wiimote/Src/ConfigBasicDlg.cpp | 1 + .../Plugin_Wiimote/Src/ConfigRecording.cpp | 46 ++++++-- .../Plugin_Wiimote/Src/ConfigRecordingDlg.cpp | 6 +- .../Plugin_Wiimote/Src/ConfigRecordingDlg.h | 8 +- .../Plugin_Wiimote/Src/ReadWiimote.cpp | 102 +++++++++++++----- .../Plugin_Wiimote/Src/wiimote_real.cpp | 52 +++++++-- .../Plugins/Plugin_Wiimote/Src/wiimote_real.h | 3 +- 7 files changed, 169 insertions(+), 49 deletions(-) diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigBasicDlg.cpp b/Source/Plugins/Plugin_Wiimote/Src/ConfigBasicDlg.cpp index 68c1e8fd5a..b85a6198d8 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigBasicDlg.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigBasicDlg.cpp @@ -109,6 +109,7 @@ void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event) m_RecordingConfigFrame->ShowModal(); m_RecordingConfigFrame->Destroy(); m_RecordingConfigFrame = NULL; + m_Page = g_Config.CurrentPage; break; #ifdef WIN32 case ID_BUTTONPAIRUP: diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp index 7796144b80..b37d88ca1b 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp @@ -137,6 +137,13 @@ void WiimoteRecordingConfigDialog::CreateGUIControlsRecording() m_GaugeAccel[1] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); m_GaugeAccel[2] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); + m_GaugeAccelNunchuk[0] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); + m_GaugeAccelNunchuk[1] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); + m_GaugeAccelNunchuk[2] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); + m_GaugeGForceNunchuk[0] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); + m_GaugeGForceNunchuk[1] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); + m_GaugeGForceNunchuk[2] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH); + // The text controls m_TextIR = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Cursor: 000 000\nDistance: 0000")); @@ -152,14 +159,22 @@ void WiimoteRecordingConfigDialog::CreateGUIControlsRecording() sBoxAccel[0] = new wxBoxSizer(wxVERTICAL); sBoxAccel[1] = new wxBoxSizer(wxVERTICAL); sBoxAccel[2] = new wxBoxSizer(wxVERTICAL); - + wxBoxSizer * sBoxAccelNunchuk[3]; + sBoxAccelNunchuk[0] = new wxBoxSizer(wxVERTICAL); + sBoxAccelNunchuk[1] = new wxBoxSizer(wxVERTICAL); + sBoxAccelNunchuk[2] = new wxBoxSizer(wxVERTICAL); + wxBoxSizer * sBoxGForceNunchuk[3]; + sBoxGForceNunchuk[0] = new wxBoxSizer(wxVERTICAL); + sBoxGForceNunchuk[1] = new wxBoxSizer(wxVERTICAL); + sBoxGForceNunchuk[2] = new wxBoxSizer(wxVERTICAL); + wxStaticText * m_TextBattery = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Batt."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); wxStaticText * m_TextRoll = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Roll"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); wxStaticText * m_TextPitch = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Pitch"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); - wxStaticText *m_TextX[2], *m_TextY[2], *m_TextZ[2]; - m_TextX[0] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("X"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextX[1] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("X"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); - m_TextY[0] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Y"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextY[1] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Y"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); - m_TextZ[0] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Z"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextZ[1] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Z"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); + wxStaticText *m_TextX[4], *m_TextY[4], *m_TextZ[4]; + m_TextX[0] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("X"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextX[1] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("X"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextX[2] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("X"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextX[3] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("X"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); + m_TextY[0] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Y"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextY[1] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Y"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextY[2] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Y"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextY[3] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Y"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); + m_TextZ[0] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Z"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextZ[1] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Z"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextZ[2] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Z"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); m_TextZ[3] = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Z"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); sBoxBattery->Add(m_GaugeBattery, 0, wxEXPAND | (wxALL), 0); sBoxBattery->Add(m_TextBattery, 0, wxEXPAND | (wxUP), 5); @@ -174,12 +189,27 @@ void WiimoteRecordingConfigDialog::CreateGUIControlsRecording() sBoxAccel[1]->Add(m_GaugeAccel[1], 0, wxEXPAND | (wxUP | wxDOWN), 0); sBoxAccel[1]->Add(m_TextY[1], 0, wxEXPAND | (wxUP), 5); sBoxAccel[2]->Add(m_GaugeAccel[2], 0, wxEXPAND | (wxUP | wxDOWN | wxRIGHT), 0); sBoxAccel[2]->Add(m_TextZ[1], 0, wxEXPAND | (wxUP), 5); + sBoxGForceNunchuk[0]->Add(m_GaugeGForceNunchuk[0], 0, wxEXPAND | (wxUP | wxDOWN | wxLEFT), 0); sBoxGForceNunchuk[0]->Add(m_TextX[2], 0, wxEXPAND | (wxUP), 5); + sBoxGForceNunchuk[1]->Add(m_GaugeGForceNunchuk[1], 0, wxEXPAND | (wxUP | wxDOWN), 0); sBoxGForceNunchuk[1]->Add(m_TextY[2], 0, wxEXPAND | (wxUP), 5); + sBoxGForceNunchuk[2]->Add(m_GaugeGForceNunchuk[2], 0, wxEXPAND | (wxUP | wxDOWN | wxRIGHT), 0); sBoxGForceNunchuk[2]->Add(m_TextZ[2], 0, wxEXPAND | (wxUP), 5); + + sBoxAccelNunchuk[0]->Add(m_GaugeAccelNunchuk[0], 0, wxEXPAND | (wxUP | wxDOWN | wxLEFT), 0); sBoxAccelNunchuk[0]->Add(m_TextX[3], 0, wxEXPAND | (wxUP), 5); + sBoxAccelNunchuk[1]->Add(m_GaugeAccelNunchuk[1], 0, wxEXPAND | (wxUP | wxDOWN), 0); sBoxAccelNunchuk[1]->Add(m_TextY[3], 0, wxEXPAND | (wxUP), 5); + sBoxAccelNunchuk[2]->Add(m_GaugeAccelNunchuk[2], 0, wxEXPAND | (wxUP | wxDOWN | wxRIGHT), 0); sBoxAccelNunchuk[2]->Add(m_TextZ[3], 0, wxEXPAND | (wxUP), 5); + + + wxStaticBoxSizer * sbRealStatus = new wxStaticBoxSizer(wxVERTICAL, m_PageRecording, wxT("Status")); wxStaticBoxSizer * sbRealIR = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("IR")); wxStaticBoxSizer * sbRealBattery = new wxStaticBoxSizer(wxVERTICAL, m_PageRecording, wxT("Battery")); wxStaticBoxSizer * sbRealRoll = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("Roll and Pitch")); wxStaticBoxSizer * sbRealGForce = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("G-Force")); wxStaticBoxSizer * sbRealAccel = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("Accelerometer")); + wxStaticBoxSizer * sbRealGForceNunchuk = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("G-Force NC")); + wxStaticBoxSizer * sbRealAccelNunchuk = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("Accelerometer NC")); + + + // Status sbRealStatus->Add(m_TextUpdateRate, 0, wxEXPAND | (wxALL), 5); @@ -190,6 +220,8 @@ void WiimoteRecordingConfigDialog::CreateGUIControlsRecording() sbRealRoll->Add(sBoxRoll[0], 0, wxEXPAND | (wxALL), 5); sbRealRoll->Add(sBoxRoll[1], 0, wxEXPAND | (wxALL), 5); sbRealGForce->Add(sBoxGForce[0], 0, wxEXPAND | (wxALL), 5); sbRealGForce->Add(sBoxGForce[1], 0, wxEXPAND | (wxALL), 5); sbRealGForce->Add(sBoxGForce[2], 0, wxEXPAND | (wxALL), 5); sbRealAccel->Add(sBoxAccel[0], 0, wxEXPAND | (wxALL), 5); sbRealAccel->Add(sBoxAccel[1], 0, wxEXPAND | (wxALL), 5); sbRealAccel->Add(sBoxAccel[2], 0, wxEXPAND | (wxALL), 5); + sbRealAccelNunchuk->Add(sBoxAccelNunchuk[0], 0, wxEXPAND | (wxALL), 5); sbRealAccelNunchuk->Add(sBoxAccelNunchuk[1], 0, wxEXPAND | (wxALL), 5); sbRealAccelNunchuk->Add(sBoxAccelNunchuk[2], 0, wxEXPAND | (wxALL), 5); + sbRealGForceNunchuk->Add(sBoxGForceNunchuk[0], 0, wxEXPAND | (wxALL), 5); sbRealGForceNunchuk->Add(sBoxGForceNunchuk[1], 0, wxEXPAND | (wxALL), 5); sbRealGForceNunchuk->Add(sBoxGForceNunchuk[2], 0, wxEXPAND | (wxALL), 5); // Vertical leftmost status wxBoxSizer * sbStatusLeft = new wxBoxSizer(wxVERTICAL); @@ -202,6 +234,8 @@ void WiimoteRecordingConfigDialog::CreateGUIControlsRecording() sbRealWiimoteStatus->Add(sbRealRoll, 0, wxEXPAND | (wxLEFT), 5); sbRealWiimoteStatus->Add(sbRealGForce, 0, wxEXPAND | (wxLEFT), 5); sbRealWiimoteStatus->Add(sbRealAccel, 0, wxEXPAND | (wxLEFT), 5); + sbRealWiimoteStatus->Add(sbRealAccelNunchuk, 0, wxEXPAND | (wxLEFT), 5); + sbRealWiimoteStatus->Add(sbRealGForceNunchuk, 0, wxEXPAND | (wxLEFT), 5); m_GaugeBattery->SetToolTip(wxT("Press '+' to show the current status. Press '-' to stop recording the status.")); @@ -346,7 +380,7 @@ void WiimoteRecordingConfigDialog::ConvertToString() TmpStr += StringFromFormat("%s", m_vRecording.at(i).z >= 0 ? StringFromFormat("+%03i", m_vRecording.at(i).z).c_str() : StringFromFormat("%04i", m_vRecording.at(i).z).c_str()); if (i < ((int)m_vRecording.size() - 1)) TmpStr += ","; - //DEBUG_LOG(WIIMOTE, "%s", TmpStr.c_str()); + DEBUG_LOG(WIIMOTE, "%s", TmpStr.c_str()); // Write the IR data TmpIR += ArrayToString(m_vRecording.at(i).IR, IRBytes, 0, 30, false); diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.cpp b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.cpp index 341c03f11d..df438bf76b 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.cpp @@ -21,6 +21,8 @@ #include "ConfigBasicDlg.h" #include "Config.h" #include "EmuMain.h" // for LoadRecordedMovements() +#include "wiimote_real.h" + BEGIN_EVENT_TABLE(WiimoteRecordingConfigDialog,wxDialog) EVT_CLOSE(WiimoteRecordingConfigDialog::OnClose) @@ -95,7 +97,8 @@ void WiimoteRecordingConfigDialog::CloseClick(wxCommandEvent& event) switch(event.GetId()) { case ID_CLOSE: - Close(); + SetEvent(WiiMoteReal::g_StopThreadTemporary); //direct closing will result in crash @ReadWiimote, also dont try to waitforobject here, it will result in deadlock! because this thread is still needed to progress in the Readwiimote to get to the waitingobject @readwiimote itself..... + //Problem lies mainly in Readwiimote(), closing here leaves the thread readWiimote thread, trying to access vars which aint there anymore. break; case ID_APPLY: SaveFile(); @@ -141,4 +144,3 @@ void WiimoteRecordingConfigDialog::UpdateRecordingGUI(int Slot) if(ControlsCreated) m_PageRecording->FindItem(i)->Enable(ActiveRecording); #endif } - diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.h b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.h index 823e450038..6b83b31476 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.h +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.h @@ -28,6 +28,7 @@ #include #include #include +#include "Thread.h" class WiimoteRecordingConfigDialog : public wxDialog { @@ -40,7 +41,6 @@ class WiimoteRecordingConfigDialog : public wxDialog long style = wxDEFAULT_DIALOG_STYLE | wxWANTS_CHARS); virtual ~WiimoteRecordingConfigDialog(){;} - void UpdateRecordingGUI(int Slot = 0); void LoadFile(); void SaveFile(); @@ -67,12 +67,16 @@ class WiimoteRecordingConfigDialog : public wxDialog wxGauge *m_GaugeBattery, *m_GaugeRoll[2], *m_GaugeGForce[3], - *m_GaugeAccel[3]; + *m_GaugeAccel[3], + *m_GaugeAccelNunchuk[3], + *m_GaugeGForceNunchuk[3]; private: DECLARE_EVENT_TABLE(); bool ControlsCreated; + THREAD_RETURN SafeCloseReadWiimote_ThreadFunc2(void* arg); + Common::Thread* g_pReadThread2; wxPanel *m_PageRecording; wxButton *m_Close, diff --git a/Source/Plugins/Plugin_Wiimote/Src/ReadWiimote.cpp b/Source/Plugins/Plugin_Wiimote/Src/ReadWiimote.cpp index 4369858265..c435915d57 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ReadWiimote.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ReadWiimote.cpp @@ -85,6 +85,21 @@ void handle_event(struct wiimote_t* wm) //if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) g_Run = false; if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) DEBUG_LOG(WIIMOTE, "TWO pressed"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) DEBUG_LOG(WIIMOTE, "HOME pressed"); + // Create shortcut to the nunchuck + + struct nunchuk_t* nc = NULL; + + if (wm->exp.type == EXP_NUNCHUK) { + + nc = (nunchuk_t*)&wm->exp.nunchuk; + if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) + DEBUG_LOG(WIIMOTE, "C pressed"); + if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) + DEBUG_LOG(WIIMOTE, "Z pressed"); + } + + + // Pressing minus will tell the wiimote we are no longer interested in movement. @@ -95,6 +110,7 @@ void handle_event(struct wiimote_t* wm) wiiuse_set_ir(wm, 0); g_MotionSensing = false; } + // Turn aceelerometer and IR reporting on, there is some kind of bug that prevents us from turing these on // directly after each other, so we have to wait for another wiiuse_poll() this way if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) @@ -106,25 +122,24 @@ void handle_event(struct wiimote_t* wm) if (g_MotionSensing && !WIIUSE_USING_IR(wm)) wiiuse_set_ir(wm, 1); - // Print battery status + if (!m_RecordingConfigFrame) return; + + // Print battery status #if defined(HAVE_WX) && HAVE_WX if(m_RecordingConfigFrame && g_Config.bUpdateRealWiimote) m_RecordingConfigFrame->m_GaugeBattery->SetValue((int)floor((wm->battery_level * 100) + 0.5)); #endif - // Create shortcut to the nunchuck - struct nunchuk_t* nc = NULL; - if (wm->exp.type == EXP_NUNCHUK) - nc = (nunchuk_t*)&wm->exp.nunchuk; // If the accelerometer is turned on then print angles if (WIIUSE_USING_ACC(wm) && WIIUSE_USING_IR(wm)) { + /* std::string Tmp; Tmp += StringFromFormat("Roll: %2.1f ", wm->orient.roll); Tmp += StringFromFormat("Pitch: %2.1f ", wm->orient.pitch); Tmp += StringFromFormat("Battery: %1.2f\n", wm->battery_level); Tmp += StringFromFormat("G-Force x, y, z: %1.2f %1.2f %1.2f\n", wm->gforce.x, wm->gforce.y, wm->gforce.z); - Tmp += StringFromFormat("Accel x, y, z: %03i %03i %03i\n", wm->accel.x, wm->accel.y, wm->accel.z); + Tmp += StringFromFormat("Accel x, y, z: %03i %03i %03i\n", wm->accel.x, wm->accel.y, wm->accel.z); */ // wm->event_buf is cleared at the end of all wiiuse_poll(), so wm->event_buf will always be zero // after that. To get the raw IR data we need to read the wiimote again. This seems to work most of the time, @@ -132,7 +147,7 @@ void handle_event(struct wiimote_t* wm) if (wiiuse_io_read(wm)) if (IRDataOK(wm)) memcpy(g_EventBuffer, wm->event_buf, GetIRDataSize(wm)); - +/* // Go through each of the 4 possible IR sources for (int i = 0; i < 4; ++i) { @@ -149,7 +164,7 @@ void handle_event(struct wiimote_t* wm) { Tmp += "\n"; Tmp += StringFromFormat("Nunchuck accel x, y, z: %03i %03i %03i\n", nc->accel.x, nc->accel.y, nc->accel.z); - } + } */ //Tmp += "\n"; //std::string TmpData = ArrayToString(g_EventBuffer, ReportSize, 0, 30); @@ -158,7 +173,7 @@ void handle_event(struct wiimote_t* wm) //DEBUG_LOG(WIIMOTE, "%s", Tmp.c_str()); #if defined(HAVE_WX) && HAVE_WX - if(m_RecordingConfigFrame) + if(m_RecordingConfigFrame && g_Config.bUpdateRealWiimote) { // Produce adjusted accelerometer values float _Gx = (float)(wm->accel.x - wm->accel_calib.cal_zero.x) / (float)wm->accel_calib.cal_g.x; @@ -170,18 +185,9 @@ void handle_event(struct wiimote_t* wm) int Gy = (int)(_Gy * 100); int Gz = (int)(_Gz * 100); - // And for the Nunchuck - u8 AccelNX = 0, AccelNY = 0, AccelNZ = 0; - if(wm->exp.type == EXP_NUNCHUK) - { - if((nc->accel.x + g_Config.iAccNunNeutralX) <= 255) AccelNX = nc->accel.x + g_Config.iAccNunNeutralX; - if((nc->accel.y + g_Config.iAccNunNeutralY) <= 255) AccelNY = nc->accel.y + g_Config.iAccNunNeutralY; - if((nc->accel.z + g_Config.iAccNunNeutralZ) <= 255) AccelNZ = nc->accel.z + g_Config.iAccNunNeutralZ; - } - - if(g_Config.bUpdateRealWiimote) - { - // Update gauges + + { //Updating Wiimote Gauges. + m_RecordingConfigFrame->m_GaugeRoll[0]->SetValue(wm->orient.roll + 180); m_RecordingConfigFrame->m_GaugeRoll[1]->SetValue(wm->orient.pitch + 180); @@ -194,17 +200,47 @@ void handle_event(struct wiimote_t* wm) m_RecordingConfigFrame->m_GaugeAccel[1]->SetValue(wm->accel.y); m_RecordingConfigFrame->m_GaugeAccel[2]->SetValue(wm->accel.z); + if(wm->exp.type == EXP_NUNCHUK) // Updating Nunchuck Gauges + { + + m_RecordingConfigFrame->m_GaugeGForceNunchuk[0]->SetValue((int)floor((nc->gforce.x * 100) + 300.5)); + m_RecordingConfigFrame->m_GaugeGForceNunchuk[1]->SetValue((int)floor((nc->gforce.y * 100) + 300.5)); + m_RecordingConfigFrame->m_GaugeGForceNunchuk[2]->SetValue((int)floor((nc->gforce.z * 100) + 300.5)); + + m_RecordingConfigFrame->m_GaugeAccelNunchuk[0]->SetValue(nc->accel.x); + m_RecordingConfigFrame->m_GaugeAccelNunchuk[1]->SetValue(nc->accel.y); + m_RecordingConfigFrame->m_GaugeAccelNunchuk[2]->SetValue(nc->accel.z); + + //Produce valid data for recording + float _GNCx = (float)(nc->accel.x - nc->accel_calib.cal_zero.x) / (float)nc->accel_calib.cal_g.x; + float _GNCy = (float)(nc->accel.y - nc->accel_calib.cal_zero.y) / (float)nc->accel_calib.cal_g.y; + float _GNCz = (float)(nc->accel.z - nc->accel_calib.cal_zero.z) / (float)nc->accel_calib.cal_g.z; + + // Conver the data to integers + int GNCx = (int)(_GNCx * 100); + int GNCy = (int)(_GNCy * 100); + int GNCz = (int)(_GNCz * 100); + + } + m_RecordingConfigFrame->m_TextIR->SetLabel(wxString::Format( wxT("Cursor: %03u %03u\nDistance:%4.0f"), wm->ir.x, wm->ir.y, wm->ir.z)); //m_RecordingConfigFrame->m_TextAccNeutralCurrent->SetLabel(wxString::Format( // wxT("Current: %03u %03u %03u"), Gx, Gy, Gz)); - if(m_RecordingConfigFrame->m_bRecording) - DEBUG_LOG(WIIMOTE, "Wiiuse Recorded accel x, y, z: %03i %03i %03i", Gx, Gy, Gz); + if(m_RecordingConfigFrame->m_bRecording) { + if(wm->exp.type == EXP_NUNCHUK) { + DEBUG_LOG(WIIMOTE, "Wiiuse Recorded accel x, y, z: %03i %03i %03i", Gx, Gy, Gz); + } + else { + DEBUG_LOG(WIIMOTE, "Wiiuse Recorded accel x, y, z: %03i %03i %03i; NCx, NCy, NCz: %03i %03i %03i",Gx,Gy,Gz, GNCx, GNCy, GNCz); + } + } } - // Send the data to be saved + + // Send the data to be saved //todo: passing nunchuck x,y,z vars as well m_RecordingConfigFrame->DoRecordMovement(Gx, Gy, Gz, g_EventBuffer + 6, GetIRDataSize(wm)); // Turn recording on and off @@ -238,6 +274,7 @@ void handle_event(struct wiimote_t* wm) #if defined(HAVE_WX) && HAVE_WX if (m_RecordingConfigFrame) { + NOTICE_LOG(BOOT, "readwiimote, reset bars to zero"); m_RecordingConfigFrame->m_GaugeRoll[0]->SetValue(0); m_RecordingConfigFrame->m_GaugeRoll[1]->SetValue(0); @@ -249,6 +286,14 @@ void handle_event(struct wiimote_t* wm) m_RecordingConfigFrame->m_GaugeAccel[1]->SetValue(0); m_RecordingConfigFrame->m_GaugeAccel[2]->SetValue(0); + m_RecordingConfigFrame->m_GaugeAccelNunchuk[0]->SetValue(0); + m_RecordingConfigFrame->m_GaugeAccelNunchuk[1]->SetValue(0); + m_RecordingConfigFrame->m_GaugeAccelNunchuk[2]->SetValue(0); + + m_RecordingConfigFrame->m_GaugeGForceNunchuk[0]->SetValue(0); + m_RecordingConfigFrame->m_GaugeGForceNunchuk[1]->SetValue(0); + m_RecordingConfigFrame->m_GaugeGForceNunchuk[2]->SetValue(0); + m_RecordingConfigFrame->m_TextIR->SetLabel(wxT("Cursor:\nDistance:")); } #endif @@ -266,7 +311,6 @@ void ReadWiimote() { handle_event(g_WiiMotesFromWiiUse[i]); } - // Declaration std::string Temp; @@ -336,9 +380,8 @@ void ReadWiimote() * threshold values. By default they are the same * as the wiimote. */ - //wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f); - //wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100); - DEBUG_LOG(WIIMOTE, "Nunchuk inserted."); + //wiiuse_set_nunchuk_orient_threshold(g_WiiMotesFromWiiUse[i], 90.0f); + //wiiuse_set_nunchuk_accel_threshold(g_WiiMotesFromWiiUse[i], 100); break; case WIIUSE_CLASSIC_CTRL_INSERTED: @@ -352,6 +395,9 @@ void ReadWiimote() break; case WIIUSE_NUNCHUK_REMOVED: + DEBUG_LOG(WIIMOTE, "Nunchuck was removed."); + break; + case WIIUSE_CLASSIC_CTRL_REMOVED: case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: // some expansion was removed diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp index 67231bed75..36d3b9e3c3 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp @@ -34,6 +34,8 @@ #include "EmuDefinitions.h" #define EXCLUDE_H // Avoid certain declarations in wiimote_real.h #include "wiimote_real.h" +#include "ConfigRecordingDlg.h" + #ifdef WIN32 #include #include @@ -50,6 +52,7 @@ namespace WiiMoteReal class CWiiMote; THREAD_RETURN ReadWiimote_ThreadFunc(void* arg); +THREAD_RETURN SafeCloseReadWiimote_ThreadFunc(void* arg); // Variable declarations @@ -58,7 +61,8 @@ Common::Thread* g_pReadThread = NULL; int g_NumberOfWiiMotes; CWiiMote* g_WiiMotes[MAX_WIIMOTES]; bool g_Shutdown = false; -bool g_ThreadGoing = false; +HANDLE g_StartThread = false; +HANDLE g_StopThreadTemporary; bool g_LocalThread = true; bool g_IRSensing = false; bool g_MotionSensing = false; @@ -472,12 +476,12 @@ void DoState(PointerWrap &p) void Shutdown(void) { // Stop the loop in the thread - g_Shutdown = true; + g_Shutdown = true; // not safe .. might crash when still @ReadWiimote // Stop the thread if (g_pReadThread != NULL) { - delete g_pReadThread; + delete g_pReadThread; g_pReadThread = NULL; } @@ -526,25 +530,53 @@ void Update(int _WiimoteNumber) time to avoid a potential collision. */ THREAD_RETURN ReadWiimote_ThreadFunc(void* arg) { + WiiMoteReal::g_StopThreadTemporary = CreateEvent(NULL, TRUE, FALSE, NULL); + WiiMoteReal::g_StartThread = CreateEvent(NULL, TRUE, FALSE, NULL); + while (!g_Shutdown) { - // We need g_ThreadGoing to do a manual WaitForSingleObject() from the configuration window - g_ThreadGoing = true; // There is at least one Real Wiimote in use + if (g_Config.bNumberRealWiimotes > 0 && !g_RunTemporary) { for (int i = 0; i < MAX_WIIMOTES; i++) if (g_WiimoteInUse[i]) g_WiiMotes[i]->ReadData(); } - else - ReadWiimote(); - g_ThreadGoing = false; + else { + + switch (WaitForSingleObject(WiiMoteReal::g_StopThreadTemporary,0)) + { + // Event object was signaled, exiting thread to close ConfigRecordingDlg + case WAIT_OBJECT_0: + + new Common::Thread(SafeCloseReadWiimote_ThreadFunc, NULL); + SetEvent(WiiMoteReal::g_StartThread); //tell the new thread to get going + return 0; + + default: + ReadWiimote(); + } + + + } + } return 0; } - - +THREAD_RETURN SafeCloseReadWiimote_ThreadFunc(void* arg) // 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; +{ + WiiMoteReal::g_Shutdown = true; + WaitForSingleObject(WiiMoteReal::g_StartThread,INFINITE); //Ready to start cleaning + + if (g_RealWiiMoteInitialized) + WiiMoteReal::Shutdown(); + m_RecordingConfigFrame->Close(true); + if (!g_RealWiiMoteInitialized) + WiiMoteReal::Initialize(); + + return 0; +} // WiiMote Pair-Up #ifdef WIN32 int WiimotePairUp(void) diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h index 4c59b38c2a..72dda054b3 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h +++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h @@ -48,7 +48,8 @@ bool IRDataOK(struct wiimote_t* wm); #ifndef EXCLUDE_H extern wiimote_t** g_WiiMotesFromWiiUse; extern bool g_Shutdown; - extern bool g_ThreadGoing; + extern HANDLE g_StopThreadTemporary; + extern HANDLE g_StartThread; extern int g_NumberOfWiiMotes; extern bool g_MotionSensing; extern bool g_IRSensing;