Guest User

Untitled

a guest
Jul 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.97 KB | None | 0 0
  1. Index: Plugins/Plugin_Wiimote/Src/ConfigBasicDlg.cpp
  2. ===================================================================
  3. --- Plugins/Plugin_Wiimote/Src/ConfigBasicDlg.cpp (revision 4793)
  4. +++ Plugins/Plugin_Wiimote/Src/ConfigBasicDlg.cpp (working copy)
  5. @@ -109,6 +109,7 @@
  6. m_RecordingConfigFrame->ShowModal();
  7. m_RecordingConfigFrame->Destroy();
  8. m_RecordingConfigFrame = NULL;
  9. + m_Page = g_Config.CurrentPage;
  10. break;
  11. #ifdef WIN32
  12. case ID_BUTTONPAIRUP:
  13. Index: Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp
  14. ===================================================================
  15. --- Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp (revision 4793)
  16. +++ Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp (working copy)
  17. @@ -137,6 +137,13 @@
  18. m_GaugeAccel[1] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  19. m_GaugeAccel[2] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  20.  
  21. + m_GaugeAccelNunchuk[0] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  22. + m_GaugeAccelNunchuk[1] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  23. + m_GaugeAccelNunchuk[2] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  24. + m_GaugeGForceNunchuk[0] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  25. + m_GaugeGForceNunchuk[1] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  26. + m_GaugeGForceNunchuk[2] = new wxGauge( m_PageRecording, wxID_ANY, 255, wxDefaultPosition, wxSize(Gw, Gh), wxGA_VERTICAL | wxNO_BORDER | wxGA_SMOOTH);
  27. +
  28. // The text controls
  29. m_TextIR = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Cursor: 000 000\nDistance: 0000"));
  30.  
  31. @@ -152,14 +159,22 @@
  32. sBoxAccel[0] = new wxBoxSizer(wxVERTICAL);
  33. sBoxAccel[1] = new wxBoxSizer(wxVERTICAL);
  34. sBoxAccel[2] = new wxBoxSizer(wxVERTICAL);
  35. -
  36. + wxBoxSizer * sBoxAccelNunchuk[3];
  37. + sBoxAccelNunchuk[0] = new wxBoxSizer(wxVERTICAL);
  38. + sBoxAccelNunchuk[1] = new wxBoxSizer(wxVERTICAL);
  39. + sBoxAccelNunchuk[2] = new wxBoxSizer(wxVERTICAL);
  40. + wxBoxSizer * sBoxGForceNunchuk[3];
  41. + sBoxGForceNunchuk[0] = new wxBoxSizer(wxVERTICAL);
  42. + sBoxGForceNunchuk[1] = new wxBoxSizer(wxVERTICAL);
  43. + sBoxGForceNunchuk[2] = new wxBoxSizer(wxVERTICAL);
  44. +
  45. wxStaticText * m_TextBattery = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Batt."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
  46. wxStaticText * m_TextRoll = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Roll"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
  47. wxStaticText * m_TextPitch = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Pitch"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
  48. - wxStaticText *m_TextX[2], *m_TextY[2], *m_TextZ[2];
  49. - 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);
  50. - 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);
  51. - 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);
  52. + wxStaticText *m_TextX[4], *m_TextY[4], *m_TextZ[4];
  53. + 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);
  54. + 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);
  55. + 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);
  56.  
  57. sBoxBattery->Add(m_GaugeBattery, 0, wxEXPAND | (wxALL), 0); sBoxBattery->Add(m_TextBattery, 0, wxEXPAND | (wxUP), 5);
  58.  
  59. @@ -174,13 +189,28 @@
  60. sBoxAccel[1]->Add(m_GaugeAccel[1], 0, wxEXPAND | (wxUP | wxDOWN), 0); sBoxAccel[1]->Add(m_TextY[1], 0, wxEXPAND | (wxUP), 5);
  61. sBoxAccel[2]->Add(m_GaugeAccel[2], 0, wxEXPAND | (wxUP | wxDOWN | wxRIGHT), 0); sBoxAccel[2]->Add(m_TextZ[1], 0, wxEXPAND | (wxUP), 5);
  62.  
  63. + sBoxGForceNunchuk[0]->Add(m_GaugeGForceNunchuk[0], 0, wxEXPAND | (wxUP | wxDOWN | wxLEFT), 0); sBoxGForceNunchuk[0]->Add(m_TextX[2], 0, wxEXPAND | (wxUP), 5);
  64. + sBoxGForceNunchuk[1]->Add(m_GaugeGForceNunchuk[1], 0, wxEXPAND | (wxUP | wxDOWN), 0); sBoxGForceNunchuk[1]->Add(m_TextY[2], 0, wxEXPAND | (wxUP), 5);
  65. + sBoxGForceNunchuk[2]->Add(m_GaugeGForceNunchuk[2], 0, wxEXPAND | (wxUP | wxDOWN | wxRIGHT), 0); sBoxGForceNunchuk[2]->Add(m_TextZ[2], 0, wxEXPAND | (wxUP), 5);
  66. +
  67. + sBoxAccelNunchuk[0]->Add(m_GaugeAccelNunchuk[0], 0, wxEXPAND | (wxUP | wxDOWN | wxLEFT), 0); sBoxAccelNunchuk[0]->Add(m_TextX[3], 0, wxEXPAND | (wxUP), 5);
  68. + sBoxAccelNunchuk[1]->Add(m_GaugeAccelNunchuk[1], 0, wxEXPAND | (wxUP | wxDOWN), 0); sBoxAccelNunchuk[1]->Add(m_TextY[3], 0, wxEXPAND | (wxUP), 5);
  69. + sBoxAccelNunchuk[2]->Add(m_GaugeAccelNunchuk[2], 0, wxEXPAND | (wxUP | wxDOWN | wxRIGHT), 0); sBoxAccelNunchuk[2]->Add(m_TextZ[3], 0, wxEXPAND | (wxUP), 5);
  70. +
  71. +
  72. +
  73. wxStaticBoxSizer * sbRealStatus = new wxStaticBoxSizer(wxVERTICAL, m_PageRecording, wxT("Status"));
  74. wxStaticBoxSizer * sbRealIR = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("IR"));
  75. wxStaticBoxSizer * sbRealBattery = new wxStaticBoxSizer(wxVERTICAL, m_PageRecording, wxT("Battery"));
  76. wxStaticBoxSizer * sbRealRoll = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("Roll and Pitch"));
  77. wxStaticBoxSizer * sbRealGForce = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("G-Force"));
  78. wxStaticBoxSizer * sbRealAccel = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("Accelerometer"));
  79. + wxStaticBoxSizer * sbRealGForceNunchuk = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("G-Force NC"));
  80. + wxStaticBoxSizer * sbRealAccelNunchuk = new wxStaticBoxSizer(wxHORIZONTAL, m_PageRecording, wxT("Accelerometer NC"));
  81. +
  82. +
  83.  
  84. +
  85. // Status
  86. sbRealStatus->Add(m_TextUpdateRate, 0, wxEXPAND | (wxALL), 5);
  87. sbRealStatus->Add(m_UpdateMeters, 0, wxEXPAND | (wxLEFT | wxRIGHT | wxDOWN), 5);
  88. @@ -190,6 +220,8 @@
  89. sbRealRoll->Add(sBoxRoll[0], 0, wxEXPAND | (wxALL), 5); sbRealRoll->Add(sBoxRoll[1], 0, wxEXPAND | (wxALL), 5);
  90. sbRealGForce->Add(sBoxGForce[0], 0, wxEXPAND | (wxALL), 5); sbRealGForce->Add(sBoxGForce[1], 0, wxEXPAND | (wxALL), 5); sbRealGForce->Add(sBoxGForce[2], 0, wxEXPAND | (wxALL), 5);
  91. sbRealAccel->Add(sBoxAccel[0], 0, wxEXPAND | (wxALL), 5); sbRealAccel->Add(sBoxAccel[1], 0, wxEXPAND | (wxALL), 5); sbRealAccel->Add(sBoxAccel[2], 0, wxEXPAND | (wxALL), 5);
  92. + sbRealAccelNunchuk->Add(sBoxAccelNunchuk[0], 0, wxEXPAND | (wxALL), 5); sbRealAccelNunchuk->Add(sBoxAccelNunchuk[1], 0, wxEXPAND | (wxALL), 5); sbRealAccelNunchuk->Add(sBoxAccelNunchuk[2], 0, wxEXPAND | (wxALL), 5);
  93. + sbRealGForceNunchuk->Add(sBoxGForceNunchuk[0], 0, wxEXPAND | (wxALL), 5); sbRealGForceNunchuk->Add(sBoxGForceNunchuk[1], 0, wxEXPAND | (wxALL), 5); sbRealGForceNunchuk->Add(sBoxGForceNunchuk[2], 0, wxEXPAND | (wxALL), 5);
  94.  
  95. // Vertical leftmost status
  96. wxBoxSizer * sbStatusLeft = new wxBoxSizer(wxVERTICAL);
  97. @@ -202,6 +234,8 @@
  98. sbRealWiimoteStatus->Add(sbRealRoll, 0, wxEXPAND | (wxLEFT), 5);
  99. sbRealWiimoteStatus->Add(sbRealGForce, 0, wxEXPAND | (wxLEFT), 5);
  100. sbRealWiimoteStatus->Add(sbRealAccel, 0, wxEXPAND | (wxLEFT), 5);
  101. + sbRealWiimoteStatus->Add(sbRealAccelNunchuk, 0, wxEXPAND | (wxLEFT), 5);
  102. + sbRealWiimoteStatus->Add(sbRealGForceNunchuk, 0, wxEXPAND | (wxLEFT), 5);
  103.  
  104. m_GaugeBattery->SetToolTip(wxT("Press '+' to show the current status. Press '-' to stop recording the status."));
  105.  
  106. @@ -346,7 +380,7 @@
  107. 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());
  108. if (i < ((int)m_vRecording.size() - 1)) TmpStr += ",";
  109.  
  110. - //DEBUG_LOG(WIIMOTE, "%s", TmpStr.c_str());
  111. + DEBUG_LOG(WIIMOTE, "%s", TmpStr.c_str());
  112.  
  113. // Write the IR data
  114. TmpIR += ArrayToString(m_vRecording.at(i).IR, IRBytes, 0, 30, false);
  115. Index: Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.cpp
  116. ===================================================================
  117. --- Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.cpp (revision 4793)
  118. +++ Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.cpp (working copy)
  119. @@ -21,7 +21,9 @@
  120. #include "ConfigBasicDlg.h"
  121. #include "Config.h"
  122. #include "EmuMain.h" // for LoadRecordedMovements()
  123. +#include "wiimote_real.h"
  124.  
  125. +
  126. BEGIN_EVENT_TABLE(WiimoteRecordingConfigDialog,wxDialog)
  127. EVT_CLOSE(WiimoteRecordingConfigDialog::OnClose)
  128. EVT_BUTTON(ID_CLOSE, WiimoteRecordingConfigDialog::CloseClick)
  129. @@ -95,7 +97,8 @@
  130. switch(event.GetId())
  131. {
  132. case ID_CLOSE:
  133. - Close();
  134. + 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.....
  135. + //Problem lies mainly in Readwiimote(), closing here leaves the thread readWiimote thread, trying to access vars which aint there anymore.
  136. break;
  137. case ID_APPLY:
  138. SaveFile();
  139. @@ -141,4 +144,3 @@
  140. if(ControlsCreated) m_PageRecording->FindItem(i)->Enable(ActiveRecording);
  141. #endif
  142. }
  143. -
  144. Index: Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.h
  145. ===================================================================
  146. --- Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.h (revision 4793)
  147. +++ Plugins/Plugin_Wiimote/Src/ConfigRecordingDlg.h (working copy)
  148. @@ -28,6 +28,7 @@
  149. #include <wx/combobox.h>
  150. #include <wx/checkbox.h>
  151. #include <wx/panel.h>
  152. +#include "Thread.h"
  153.  
  154. class WiimoteRecordingConfigDialog : public wxDialog
  155. {
  156. @@ -40,7 +41,6 @@
  157. long style = wxDEFAULT_DIALOG_STYLE | wxWANTS_CHARS);
  158. virtual ~WiimoteRecordingConfigDialog(){;}
  159.  
  160. -
  161. void UpdateRecordingGUI(int Slot = 0);
  162. void LoadFile();
  163. void SaveFile();
  164. @@ -67,12 +67,16 @@
  165. wxGauge *m_GaugeBattery,
  166. *m_GaugeRoll[2],
  167. *m_GaugeGForce[3],
  168. - *m_GaugeAccel[3];
  169. + *m_GaugeAccel[3],
  170. + *m_GaugeAccelNunchuk[3],
  171. + *m_GaugeGForceNunchuk[3];
  172.  
  173. private:
  174. DECLARE_EVENT_TABLE();
  175.  
  176. bool ControlsCreated;
  177. + THREAD_RETURN SafeCloseReadWiimote_ThreadFunc2(void* arg);
  178. + Common::Thread* g_pReadThread2;
  179.  
  180. wxPanel *m_PageRecording;
  181. wxButton *m_Close,
  182. Index: Plugins/Plugin_Wiimote/Src/ReadWiimote.cpp
  183. ===================================================================
  184. --- Plugins/Plugin_Wiimote/Src/ReadWiimote.cpp (revision 4793)
  185. +++ Plugins/Plugin_Wiimote/Src/ReadWiimote.cpp (working copy)
  186. @@ -85,8 +85,23 @@
  187. //if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) g_Run = false;
  188. if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) DEBUG_LOG(WIIMOTE, "TWO pressed");
  189. if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) DEBUG_LOG(WIIMOTE, "HOME pressed");
  190. + // Create shortcut to the nunchuck
  191.  
  192. + struct nunchuk_t* nc = NULL;
  193.  
  194. + if (wm->exp.type == EXP_NUNCHUK) {
  195. +
  196. + nc = (nunchuk_t*)&wm->exp.nunchuk;
  197. + if (IS_PRESSED(nc, NUNCHUK_BUTTON_C))
  198. + DEBUG_LOG(WIIMOTE, "C pressed");
  199. + if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z))
  200. + DEBUG_LOG(WIIMOTE, "Z pressed");
  201. + }
  202. +
  203. +
  204. +
  205. +
  206. +
  207. // Pressing minus will tell the wiimote we are no longer interested in movement.
  208. // This is useful because it saves battery power.
  209. if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
  210. @@ -95,6 +110,7 @@
  211. wiiuse_set_ir(wm, 0);
  212. g_MotionSensing = false;
  213. }
  214. +
  215. // Turn aceelerometer and IR reporting on, there is some kind of bug that prevents us from turing these on
  216. // directly after each other, so we have to wait for another wiiuse_poll() this way
  217. if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
  218. @@ -106,25 +122,24 @@
  219. if (g_MotionSensing && !WIIUSE_USING_IR(wm))
  220. wiiuse_set_ir(wm, 1);
  221.  
  222. - // Print battery status
  223. + if (!m_RecordingConfigFrame) return;
  224. +
  225. + // Print battery status
  226. #if defined(HAVE_WX) && HAVE_WX
  227. if(m_RecordingConfigFrame && g_Config.bUpdateRealWiimote)
  228. m_RecordingConfigFrame->m_GaugeBattery->SetValue((int)floor((wm->battery_level * 100) + 0.5));
  229. #endif
  230. - // Create shortcut to the nunchuck
  231. - struct nunchuk_t* nc = NULL;
  232. - if (wm->exp.type == EXP_NUNCHUK)
  233. - nc = (nunchuk_t*)&wm->exp.nunchuk;
  234.  
  235. // If the accelerometer is turned on then print angles
  236. if (WIIUSE_USING_ACC(wm) && WIIUSE_USING_IR(wm))
  237. {
  238. + /*
  239. std::string Tmp;
  240. Tmp += StringFromFormat("Roll: %2.1f ", wm->orient.roll);
  241. Tmp += StringFromFormat("Pitch: %2.1f ", wm->orient.pitch);
  242. Tmp += StringFromFormat("Battery: %1.2f\n", wm->battery_level);
  243. Tmp += StringFromFormat("G-Force x, y, z: %1.2f %1.2f %1.2f\n", wm->gforce.x, wm->gforce.y, wm->gforce.z);
  244. - Tmp += StringFromFormat("Accel x, y, z: %03i %03i %03i\n", wm->accel.x, wm->accel.y, wm->accel.z);
  245. + Tmp += StringFromFormat("Accel x, y, z: %03i %03i %03i\n", wm->accel.x, wm->accel.y, wm->accel.z); */
  246.  
  247. // wm->event_buf is cleared at the end of all wiiuse_poll(), so wm->event_buf will always be zero
  248. // after that. To get the raw IR data we need to read the wiimote again. This seems to work most of the time,
  249. @@ -132,7 +147,7 @@
  250. if (wiiuse_io_read(wm))
  251. if (IRDataOK(wm))
  252. memcpy(g_EventBuffer, wm->event_buf, GetIRDataSize(wm));
  253. -
  254. +/*
  255. // Go through each of the 4 possible IR sources
  256. for (int i = 0; i < 4; ++i)
  257. {
  258. @@ -149,7 +164,7 @@
  259. {
  260. Tmp += "\n";
  261. Tmp += StringFromFormat("Nunchuck accel x, y, z: %03i %03i %03i\n", nc->accel.x, nc->accel.y, nc->accel.z);
  262. - }
  263. + } */
  264.  
  265. //Tmp += "\n";
  266. //std::string TmpData = ArrayToString(g_EventBuffer, ReportSize, 0, 30);
  267. @@ -158,7 +173,7 @@
  268. //DEBUG_LOG(WIIMOTE, "%s", Tmp.c_str());
  269.  
  270. #if defined(HAVE_WX) && HAVE_WX
  271. - if(m_RecordingConfigFrame)
  272. + if(m_RecordingConfigFrame && g_Config.bUpdateRealWiimote)
  273. {
  274. // Produce adjusted accelerometer values
  275. float _Gx = (float)(wm->accel.x - wm->accel_calib.cal_zero.x) / (float)wm->accel_calib.cal_g.x;
  276. @@ -170,18 +185,9 @@
  277. int Gy = (int)(_Gy * 100);
  278. int Gz = (int)(_Gz * 100);
  279.  
  280. - // And for the Nunchuck
  281. - u8 AccelNX = 0, AccelNY = 0, AccelNZ = 0;
  282. - if(wm->exp.type == EXP_NUNCHUK)
  283. - {
  284. - if((nc->accel.x + g_Config.iAccNunNeutralX) <= 255) AccelNX = nc->accel.x + g_Config.iAccNunNeutralX;
  285. - if((nc->accel.y + g_Config.iAccNunNeutralY) <= 255) AccelNY = nc->accel.y + g_Config.iAccNunNeutralY;
  286. - if((nc->accel.z + g_Config.iAccNunNeutralZ) <= 255) AccelNZ = nc->accel.z + g_Config.iAccNunNeutralZ;
  287. - }
  288. -
  289. - if(g_Config.bUpdateRealWiimote)
  290. - {
  291. - // Update gauges
  292. +
  293. + { //Updating Wiimote Gauges.
  294. +
  295. m_RecordingConfigFrame->m_GaugeRoll[0]->SetValue(wm->orient.roll + 180);
  296. m_RecordingConfigFrame->m_GaugeRoll[1]->SetValue(wm->orient.pitch + 180);
  297.  
  298. @@ -194,17 +200,47 @@
  299. m_RecordingConfigFrame->m_GaugeAccel[1]->SetValue(wm->accel.y);
  300. m_RecordingConfigFrame->m_GaugeAccel[2]->SetValue(wm->accel.z);
  301.  
  302. + if(wm->exp.type == EXP_NUNCHUK) // Updating Nunchuck Gauges
  303. + {
  304. +
  305. + m_RecordingConfigFrame->m_GaugeGForceNunchuk[0]->SetValue((int)floor((nc->gforce.x * 100) + 300.5));
  306. + m_RecordingConfigFrame->m_GaugeGForceNunchuk[1]->SetValue((int)floor((nc->gforce.y * 100) + 300.5));
  307. + m_RecordingConfigFrame->m_GaugeGForceNunchuk[2]->SetValue((int)floor((nc->gforce.z * 100) + 300.5));
  308. +
  309. + m_RecordingConfigFrame->m_GaugeAccelNunchuk[0]->SetValue(nc->accel.x);
  310. + m_RecordingConfigFrame->m_GaugeAccelNunchuk[1]->SetValue(nc->accel.y);
  311. + m_RecordingConfigFrame->m_GaugeAccelNunchuk[2]->SetValue(nc->accel.z);
  312. +
  313. + //Produce valid data for recording
  314. + float _GNCx = (float)(nc->accel.x - nc->accel_calib.cal_zero.x) / (float)nc->accel_calib.cal_g.x;
  315. + float _GNCy = (float)(nc->accel.y - nc->accel_calib.cal_zero.y) / (float)nc->accel_calib.cal_g.y;
  316. + float _GNCz = (float)(nc->accel.z - nc->accel_calib.cal_zero.z) / (float)nc->accel_calib.cal_g.z;
  317. +
  318. + // Conver the data to integers
  319. + int GNCx = (int)(_GNCx * 100);
  320. + int GNCy = (int)(_GNCy * 100);
  321. + int GNCz = (int)(_GNCz * 100);
  322. +
  323. + }
  324. +
  325. m_RecordingConfigFrame->m_TextIR->SetLabel(wxString::Format(
  326. wxT("Cursor: %03u %03u\nDistance:%4.0f"), wm->ir.x, wm->ir.y, wm->ir.z));
  327.  
  328. //m_RecordingConfigFrame->m_TextAccNeutralCurrent->SetLabel(wxString::Format(
  329. // wxT("Current: %03u %03u %03u"), Gx, Gy, Gz));
  330.  
  331. - if(m_RecordingConfigFrame->m_bRecording)
  332. - DEBUG_LOG(WIIMOTE, "Wiiuse Recorded accel x, y, z: %03i %03i %03i", Gx, Gy, Gz);
  333. + if(m_RecordingConfigFrame->m_bRecording) {
  334. + if(wm->exp.type == EXP_NUNCHUK) {
  335. + DEBUG_LOG(WIIMOTE, "Wiiuse Recorded accel x, y, z: %03i %03i %03i", Gx, Gy, Gz);
  336. + }
  337. + else {
  338. + DEBUG_LOG(WIIMOTE, "Wiiuse Recorded accel x, y, z: %03i %03i %03i; NCx, NCy, NCz: %03i %03i %03i", GNCx, GNCy, GNCz);
  339. + }
  340. + }
  341. }
  342.  
  343. - // Send the data to be saved
  344. +
  345. + // Send the data to be saved //todo: passing nunchuck x,y,z vars as well
  346. m_RecordingConfigFrame->DoRecordMovement(Gx, Gy, Gz, g_EventBuffer + 6, GetIRDataSize(wm));
  347.  
  348. // Turn recording on and off
  349. @@ -238,6 +274,7 @@
  350. #if defined(HAVE_WX) && HAVE_WX
  351. if (m_RecordingConfigFrame)
  352. {
  353. + NOTICE_LOG(BOOT, "readwiimote, reset bars to zero");
  354. m_RecordingConfigFrame->m_GaugeRoll[0]->SetValue(0);
  355. m_RecordingConfigFrame->m_GaugeRoll[1]->SetValue(0);
  356.  
  357. @@ -249,6 +286,14 @@
  358. m_RecordingConfigFrame->m_GaugeAccel[1]->SetValue(0);
  359. m_RecordingConfigFrame->m_GaugeAccel[2]->SetValue(0);
  360.  
  361. + m_RecordingConfigFrame->m_GaugeAccelNunchuk[0]->SetValue(0);
  362. + m_RecordingConfigFrame->m_GaugeAccelNunchuk[1]->SetValue(0);
  363. + m_RecordingConfigFrame->m_GaugeAccelNunchuk[2]->SetValue(0);
  364. +
  365. + m_RecordingConfigFrame->m_GaugeGForceNunchuk[0]->SetValue(0);
  366. + m_RecordingConfigFrame->m_GaugeGForceNunchuk[1]->SetValue(0);
  367. + m_RecordingConfigFrame->m_GaugeGForceNunchuk[2]->SetValue(0);
  368. +
  369. m_RecordingConfigFrame->m_TextIR->SetLabel(wxT("Cursor:\nDistance:"));
  370. }
  371. #endif
  372. @@ -266,7 +311,6 @@
  373. {
  374. handle_event(g_WiiMotesFromWiiUse[i]);
  375. }
  376. -
  377. // Declaration
  378. std::string Temp;
  379.  
  380. @@ -336,9 +380,8 @@
  381. * threshold values. By default they are the same
  382. * as the wiimote.
  383. */
  384. - //wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f);
  385. - //wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100);
  386. - DEBUG_LOG(WIIMOTE, "Nunchuk inserted.");
  387. + //wiiuse_set_nunchuk_orient_threshold(g_WiiMotesFromWiiUse[i], 90.0f);
  388. + //wiiuse_set_nunchuk_accel_threshold(g_WiiMotesFromWiiUse[i], 100);
  389. break;
  390.  
  391. case WIIUSE_CLASSIC_CTRL_INSERTED:
  392. @@ -352,6 +395,9 @@
  393. break;
  394.  
  395. case WIIUSE_NUNCHUK_REMOVED:
  396. + DEBUG_LOG(WIIMOTE, "Nunchuck was removed.");
  397. + break;
  398. +
  399. case WIIUSE_CLASSIC_CTRL_REMOVED:
  400. case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
  401. // some expansion was removed
  402. Index: Plugins/Plugin_Wiimote/Src/wiimote_real.cpp
  403. ===================================================================
  404. --- Plugins/Plugin_Wiimote/Src/wiimote_real.cpp (revision 4793)
  405. +++ Plugins/Plugin_Wiimote/Src/wiimote_real.cpp (working copy)
  406. @@ -34,6 +34,8 @@
  407. #include "EmuDefinitions.h"
  408. #define EXCLUDE_H // Avoid certain declarations in wiimote_real.h
  409. #include "wiimote_real.h"
  410. +#include "ConfigRecordingDlg.h"
  411. +
  412. #ifdef WIN32
  413. #include <bthdef.h>
  414. #include <BluetoothAPIs.h>
  415. @@ -50,6 +52,7 @@
  416. class CWiiMote;
  417.  
  418. THREAD_RETURN ReadWiimote_ThreadFunc(void* arg);
  419. +THREAD_RETURN SafeCloseReadWiimote_ThreadFunc(void* arg);
  420.  
  421. // Variable declarations
  422.  
  423. @@ -58,7 +61,8 @@
  424. int g_NumberOfWiiMotes;
  425. CWiiMote* g_WiiMotes[MAX_WIIMOTES];
  426. bool g_Shutdown = false;
  427. -bool g_ThreadGoing = false;
  428. +HANDLE g_StartThread = false;
  429. +HANDLE g_StopThreadTemporary;
  430. bool g_LocalThread = true;
  431. bool g_IRSensing = false;
  432. bool g_MotionSensing = false;
  433. @@ -472,12 +476,12 @@
  434. void Shutdown(void)
  435. {
  436. // Stop the loop in the thread
  437. - g_Shutdown = true;
  438. + g_Shutdown = true; // not safe .. might crash when still @ReadWiimote
  439.  
  440. // Stop the thread
  441. if (g_pReadThread != NULL)
  442. {
  443. - delete g_pReadThread;
  444. + delete g_pReadThread;
  445. g_pReadThread = NULL;
  446. }
  447.  
  448. @@ -526,25 +530,53 @@
  449. time to avoid a potential collision. */
  450. THREAD_RETURN ReadWiimote_ThreadFunc(void* arg)
  451. {
  452. + WiiMoteReal::g_StopThreadTemporary = CreateEvent(NULL, TRUE, FALSE, NULL);
  453. + WiiMoteReal::g_StartThread = CreateEvent(NULL, TRUE, FALSE, NULL);
  454. +
  455. while (!g_Shutdown)
  456. {
  457. - // We need g_ThreadGoing to do a manual WaitForSingleObject() from the configuration window
  458. - g_ThreadGoing = true;
  459. // There is at least one Real Wiimote in use
  460. +
  461. if (g_Config.bNumberRealWiimotes > 0 && !g_RunTemporary)
  462. {
  463. for (int i = 0; i < MAX_WIIMOTES; i++)
  464. if (g_WiimoteInUse[i])
  465. g_WiiMotes[i]->ReadData();
  466. }
  467. - else
  468. - ReadWiimote();
  469. - g_ThreadGoing = false;
  470. + else {
  471. +
  472. + switch (WaitForSingleObject(WiiMoteReal::g_StopThreadTemporary,0))
  473. + {
  474. + // Event object was signaled, exiting thread to close ConfigRecordingDlg
  475. + case WAIT_OBJECT_0:
  476. +
  477. + new Common::Thread(SafeCloseReadWiimote_ThreadFunc, NULL);
  478. + SetEvent(WiiMoteReal::g_StartThread); //tell the new thread to get going
  479. + return 0;
  480. +
  481. + default:
  482. + ReadWiimote();
  483. + }
  484. +
  485. +
  486. + }
  487. +
  488. }
  489. return 0;
  490. }
  491. -
  492. -
  493. +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;
  494. +{
  495. + WiiMoteReal::g_Shutdown = true;
  496. + WaitForSingleObject(WiiMoteReal::g_StartThread,INFINITE); //Ready to start cleaning
  497. +
  498. + if (g_RealWiiMoteInitialized)
  499. + WiiMoteReal::Shutdown();
  500. + m_RecordingConfigFrame->Close(true);
  501. + if (!g_RealWiiMoteInitialized)
  502. + WiiMoteReal::Initialize();
  503. +
  504. + return 0;
  505. +}
  506. // WiiMote Pair-Up
  507. #ifdef WIN32
  508. int WiimotePairUp(void)
  509. Index: Plugins/Plugin_Wiimote/Src/wiimote_real.h
  510. ===================================================================
  511. --- Plugins/Plugin_Wiimote/Src/wiimote_real.h (revision 4793)
  512. +++ Plugins/Plugin_Wiimote/Src/wiimote_real.h (working copy)
  513. @@ -48,7 +48,8 @@
  514. #ifndef EXCLUDE_H
  515. extern wiimote_t** g_WiiMotesFromWiiUse;
  516. extern bool g_Shutdown;
  517. - extern bool g_ThreadGoing;
  518. + extern HANDLE g_StopThreadTemporary;
  519. + extern HANDLE g_StartThread;
  520. extern int g_NumberOfWiiMotes;
  521. extern bool g_MotionSensing;
  522. extern bool g_IRSensing;
Add Comment
Please, Sign In to add comment