sanchez's patch for real wiimote pair-up, unexpected disconnect, and wiiuse resource leakage.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5313 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2010-04-10 14:39:54 +00:00
parent 474363bc27
commit 4b5b074b81
7 changed files with 56 additions and 15 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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);

View File

@ -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;
}

View File

@ -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;