diff --git a/Externals/WiiUse/Win32/wiiuse.dll b/Externals/WiiUse/Win32/wiiuse.dll index 83062f77ab..6a7d581c08 100644 Binary files a/Externals/WiiUse/Win32/wiiuse.dll and b/Externals/WiiUse/Win32/wiiuse.dll differ diff --git a/Externals/WiiUse/Win32/wiiuse.lib b/Externals/WiiUse/Win32/wiiuse.lib index b0c86b08ac..08b322dc03 100644 Binary files a/Externals/WiiUse/Win32/wiiuse.lib and b/Externals/WiiUse/Win32/wiiuse.lib differ diff --git a/Externals/WiiUse/X64/wiiuse.dll b/Externals/WiiUse/X64/wiiuse.dll index eaaef0f4cb..3eb2c29b98 100644 Binary files a/Externals/WiiUse/X64/wiiuse.dll and b/Externals/WiiUse/X64/wiiuse.dll differ diff --git a/Externals/WiiUse/X64/wiiuse.lib b/Externals/WiiUse/X64/wiiuse.lib index 6716f24c58..fe5e434aaa 100644 Binary files a/Externals/WiiUse/X64/wiiuse.lib and b/Externals/WiiUse/X64/wiiuse.lib differ diff --git a/Externals/WiiUseSrc/Src/io_win.c b/Externals/WiiUseSrc/Src/io_win.c index 29f261f02d..ab08183ba9 100644 --- a/Externals/WiiUseSrc/Src/io_win.c +++ b/Externals/WiiUseSrc/Src/io_win.c @@ -112,7 +112,10 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { /* try to set the output report to see if the device is actually connected */ if (!wiiuse_set_report_type(wm[found])) { + Sleep(10); WIIMOTE_DISABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED); + if (wm[found]->event == WIIUSE_UNEXPECTED_DISCONNECT) + break; continue; } @@ -181,6 +184,7 @@ int wiiuse_io_read(struct wiimote_t* wm) { if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) { /* remote disconnect */ wiiuse_disconnected(wm); + wm->event = WIIUSE_UNEXPECTED_DISCONNECT; return 0; } @@ -214,7 +218,7 @@ int wiiuse_io_read(struct wiimote_t* wm) { int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { - DWORD bytes; + DWORD bytes, dw; int i; if (!wm || !WIIMOTE_IS_CONNECTED(wm)) @@ -235,12 +239,42 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { return i; } - WIIUSE_ERROR("Unable to determine bluetooth stack type."); + /*-------------------------------------------------------------- + dw = GetLastError(); //checking for 121 = timeout on semaphore/device off/disconnected to avoid trouble with other stacks toshiba/widcomm + //995 = The I/O operation has been aborted because of either a thread exit or an application request. + + if ( (dw == 121) || (dw == 995) ) { + WIIUSE_INFO("wiiuse_io_write[WIIUSE_STACK_UNKNOWN]: WIIUSE_UNEXPECTED_DISCONNECT"); + wiiuse_disconnected(wm); + wm->event = WIIUSE_UNEXPECTED_DISCONNECT; + } + else WIIUSE_ERROR("wiiuse_io_write[WIIUSE_STACK_UNKNOWN]: WIIUSE_UNEXPECTED_DISCONNECT ERROR: %08x", dw); + --------------------------------------------------------------*/ + + //If the part below causes trouble on WIDCOMM/TOSHIBA stack uncomment the lines above, and comment out the 3 lines below instead. + + WIIUSE_INFO("wiiuse_io_write[WIIUSE_STACK_UNKNOWN]: WIIUSE_UNEXPECTED_DISCONNECT - time out"); + wiiuse_disconnected(wm); + wm->event = WIIUSE_UNEXPECTED_DISCONNECT; + + //WIIUSE_ERROR("wiiuse_io_write[WIIUSE_STACK_UNKNOWN]: Unable to determine bluetooth stack type || Wiimote timed out."); return 0; } case WIIUSE_STACK_MS: - return HidD_SetOutputReport(wm->dev_handle, buf + 1, len - 1); + i = HidD_SetOutputReport(wm->dev_handle, buf + 1, len - 1); + dw = GetLastError(); + + if (dw == 121) { // semaphore timeout + WIIUSE_INFO("wiiuse_io_write[WIIUSE_STACK_MS]: WIIUSE_UNEXPECTED_DISCONNECT"); + wiiuse_disconnected(wm); + wm->event = WIIUSE_UNEXPECTED_DISCONNECT; + return 0; + }/* else if (dw) + WIIUSE_ERROR("wiiuse_io_write[WIIUSE_STACK_MS]: WIIUSE_UNEXPECTED_DISCONNECT ERROR: %08x", dw); + */ + // it is not important to catch all errors here at this place, rest will be covered by io_reads. + return i; case WIIUSE_STACK_BLUESOLEIL: return WriteFile(wm->dev_handle, buf + 1, 22, &bytes, &wm->hid_overlap); diff --git a/Externals/WiiUseSrc/Src/wiiuse.c b/Externals/WiiUseSrc/Src/wiiuse.c index 186b71d1c4..de8006d6a4 100644 --- a/Externals/WiiUseSrc/Src/wiiuse.c +++ b/Externals/WiiUseSrc/Src/wiiuse.c @@ -172,13 +172,6 @@ void wiiuse_disconnected(struct wiimote_t* wm) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); /* reset a bunch of stuff */ - #ifndef WIN32 - wm->out_sock = -1; - wm->in_sock = -1; - #else - wm->dev_handle = 0; - #endif - wm->leds = 0; wm->state = WIIMOTE_INIT_STATES; wm->read_req = NULL; @@ -188,6 +181,14 @@ void wiiuse_disconnected(struct wiimote_t* wm) { wm->btns_released = 0; memset(wm->event_buf, 0, sizeof(wm->event_buf)); + #ifndef WIN32 + wm->out_sock = -1; + wm->in_sock = -1; + #else + CloseHandle(wm->dev_handle); + wm->dev_handle = 0; + #endif + wm->event = WIIUSE_DISCONNECT; } diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp index fd22e3562f..2ead6f15d7 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp @@ -140,7 +140,11 @@ void ReadData() //DEBUG_LOG(WIIMOTE, "Writing data to the Wiimote"); SEvent& rEvent = m_EventWriteQueue.front(); wiiuse_io_write(m_pWiiMote, (byte*)rEvent.m_PayLoad, rEvent._Size); - m_EventWriteQueue.pop(); + if (m_pWiiMote->event == WIIUSE_UNEXPECTED_DISCONNECT) + { + NOTICE_LOG(WIIMOTE, "wiiuse_io_write: unexpected disconnect. handle: %08x", m_pWiiMote->dev_handle); + } + m_EventWriteQueue.pop(); // InterruptDebugging(false, rEvent.m_PayLoad); } @@ -176,6 +180,10 @@ void ReadData() m_pCriticalSection->Leave(); } } + else if (m_pWiiMote->event == WIIUSE_UNEXPECTED_DISCONNECT) + { + NOTICE_LOG(WIIMOTE, "wiiuse_io_read: unexpected disconnect. handle: %08x", m_pWiiMote->dev_handle); + } }; @@ -339,6 +347,8 @@ int Initialize() // and also connecting in Linux/OSX. // Windows connects to Wiimote in the wiiuse_find function g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL); + // Don't run the Wiimote thread if no wiimotes were found + g_Shutdown = false; NeedsConnect.Set(); Connected.Wait(); } @@ -384,10 +394,6 @@ int Initialize() wiiuse_read_data(g_WiiMotesFromWiiUse[i], data, 0, sizeof(WiiMoteEmu::EepromData_0)); } - // Don't run the Wiimote thread if no wiimotes were found - if (g_NumberOfWiiMotes > 0) - g_Shutdown = false; - // Initialized, even if we didn't find a Wiimote g_RealWiiMoteInitialized = true;