From 7b19632b4a1e0264f376d72e8f45ef95fd2d0b50 Mon Sep 17 00:00:00 2001 From: tmator Date: Sat, 1 Aug 2009 19:35:45 +0000 Subject: [PATCH] better wiimote code for osx with sonic fix, wiimote works better in wiiuse, but not in dolphin becau i think the read function in the wiimote plugin is in a separate thread and osx dont like this git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3924 8ced0084-cf51-0410-be5f-012b33b47a6e --- Externals/WiiUseSrc/Src/events.cpp | 26 +---------------------- Externals/WiiUseSrc/Src/io_osx.m | 33 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Externals/WiiUseSrc/Src/events.cpp b/Externals/WiiUseSrc/Src/events.cpp index bafd99d53c..e1fc099625 100644 --- a/Externals/WiiUseSrc/Src/events.cpp +++ b/Externals/WiiUseSrc/Src/events.cpp @@ -84,31 +84,8 @@ static int state_changed(struct wiimote_t* wm); int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { int evnt = 0; - #if defined(__APPLE__) - - int i; - - if (!wm) - return 0; - - for (i = 0; i < wiimotes; ++i) { - wm[i]->event = WIIUSE_NONE; - - if (wiiuse_io_read(wm[i])) { - /* propagate the event */ - propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); - evnt += (wm[i]->event != WIIUSE_NONE); - - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); - } else { - idle_cycle(wm[i]); - } - } - - #else /* - * Windows, Unix + * Windows, Unix and Apple */ int i; @@ -128,7 +105,6 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { idle_cycle(wm[i]); } } - #endif return evnt; } diff --git a/Externals/WiiUseSrc/Src/io_osx.m b/Externals/WiiUseSrc/Src/io_osx.m index 350771df25..a57fcffb8e 100644 --- a/Externals/WiiUseSrc/Src/io_osx.m +++ b/Externals/WiiUseSrc/Src/io_osx.m @@ -113,6 +113,12 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address); - (void) l2capChannelClosed:(IOBluetoothL2CAPChannel*) l2capChannel { //channel closed + printf("Bt channel closed\n"); + if (l2capChannel == _cchan) + _cchan = nil; + + if (l2capChannel == _ichan) + _ichan = nil; } #pragma mark - @@ -348,21 +354,38 @@ void wiiuse_disconnect(struct wiimote_t* wm) { } int wiiuse_io_read(struct wiimote_t* wm) { + + if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) + return 0; + + + /* if this wiimote is not connected, skip it */ + if (!WIIMOTE_IS_CONNECTED(wm)) + return 0; //run the main loop to get bt data CFRunLoopRun(); - for (int len=0; lenevent_buf[len] = DataFromWiimote[len]; - } + memcpy(wm->event_buf,DataFromWiimote,sizeof(wm->event_buf)); + memcpy(wm->event_buf, &wm->event_buf[1], sizeof(wm->event_buf) - 1); + return 1; - return 1; } int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { + + if(buf[0] != (WM_SET_REPORT | WM_BT_OUTPUT)) + { + // Linux and OSX need this, Windows strips it out + // Only packets from Dolphin don't have the start + // Wiiuse uses ifdefs to add the first byte without you ever knowing it + // Should find out a nice way of doing this, getting windows to stop stripping the packets would be nice + memcpy(buf + 1, buf, len - 1); + buf[0] = (WM_SET_REPORT | WM_BT_OUTPUT); + } + [cbt writeToWiimote:buf length:len]; return 1; }