From cda88a8c1ee3ac1b407b09e8e392262fd606f6ab Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 14 Feb 2013 18:41:31 -0600 Subject: [PATCH] Random improvements. --- .../Core/Core/Src/HW/WiimoteReal/IOdarwin.mm | 20 +++++++---- .../Core/Src/HW/WiimoteReal/WiimoteReal.cpp | 33 +++++++++++++++---- .../Core/Src/HW/WiimoteReal/WiimoteRealBase.h | 1 + 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm index 8c3a0f10b2..fda1d99462 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm @@ -216,19 +216,25 @@ bool Wiimote::Connect() // Disconnect a wiimote. void Wiimote::Disconnect() { + if (btd != NULL) + [btd closeConnection]; + + if (ichan != NULL) + [ichan release]; + + if (cchan != NULL) + [cchan release]; + + btd = NULL; + cchan = NULL; + ichan = NULL; + if (!IsConnected()) return; NOTICE_LOG(WIIMOTE, "Disconnecting wiimote %i", index + 1); m_connected = false; - - [btd closeConnection]; - [ichan release]; - [cchan release]; - btd = NULL; - cchan = NULL; - ichan = NULL; } bool Wiimote::IsConnected() const diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index ee685aae9b..311bf11de2 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -161,6 +161,18 @@ void Wiimote::InterruptChannel(const u16 channel, const void* const _data, const { rpt.first[0] = WM_SET_REPORT | WM_BT_OUTPUT; } + + // Disallow games from turning off all of the LEDs. + // It makes wiimote connection status confusing. + if (rpt.first[1] == WM_LEDS) + { + auto& leds_rpt = *reinterpret_cast(&rpt.first[2]); + if (0 == leds_rpt.leds) + { + // Turn on ALL of the LEDs. + leds_rpt.leds = 0xf; + } + } m_write_reports.Push(rpt); } @@ -265,12 +277,15 @@ bool Wiimote::Prepare(int _index) // Turn off rumble u8 rumble_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_CMD_RUMBLE, 0}; - - // TODO: request status and check for sane response? + + // Request status report + u8 const req_status_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_REQUEST_STATUS, 0}; + // TODO: check for sane response? return (IOWrite(mode_report, sizeof(mode_report)) && IOWrite(led_report, sizeof(led_report)) - && (SLEEP(200), IOWrite(rumble_report, sizeof(rumble_report)))); + && (SLEEP(200), IOWrite(rumble_report, sizeof(rumble_report))) + && IOWrite(req_status_report, sizeof(req_status_report))); } void Wiimote::EmuStart() @@ -382,9 +397,6 @@ void Wiimote::ThreadFunc() { Common::SetCurrentThreadName("Wiimote Device Thread"); - Host_ConnectWiimote(index, true); - NOTICE_LOG(WIIMOTE, "Connected to wiimote %i.", index + 1); - // main loop while (m_run_thread && IsConnected()) { @@ -485,6 +497,8 @@ void TryToConnectWiimote(Wiimote* wm) g_wiimotes[i] = wm; wm->StartThread(); wm = NULL; + + Host_ConnectWiimote(i, true); } break; } @@ -513,6 +527,8 @@ void DoneWithWiimote(int index) { std::swap(g_wiimotes[i], g_wiimotes[index]); g_wiimotes[i]->StartThread(); + + Host_ConnectWiimote(i, true); } break; } @@ -563,9 +579,12 @@ void Refresh() // Brief rumble for already connected wiimotes. for (int i = 0; i != MAX_WIIMOTES; ++i) { - // kinda sloppy if (g_wiimotes[i]) + { + g_wiimotes[i]->StopThread(); g_wiimotes[i]->Prepare(i); + g_wiimotes[i]->StartThread(); + } } HandleFoundWiimotes(found_wiimotes); diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteRealBase.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteRealBase.h index 15bbc2917f..1a1f6676cf 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteRealBase.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteRealBase.h @@ -41,6 +41,7 @@ #define WM_SET_REPORT 0xA0 #endif +// TODO: duplicated in WiimoteHid.h // Commands #define WM_CMD_RUMBLE 0x10 #define WM_CMD_LED 0x11