diff --git a/CHANGELOG.mkd b/CHANGELOG.mkd index bd0e229..1761513 100644 --- a/CHANGELOG.mkd +++ b/CHANGELOG.mkd @@ -29,6 +29,8 @@ Added: on it with fwiine and WiiC code as well as additional code. Try it out in the example by pressing 1 to start and 2 to stop. +- Full Mac support using Apple's native Bluetooth stack, based on [wiic](http://wiic.sourceforge.net/). + Fixed: - Properly disable rumbling when told to. Thanks to Jeff Baker from diff --git a/README.mkd b/README.mkd index 1e20e2b..665a6b4 100644 --- a/README.mkd +++ b/README.mkd @@ -194,11 +194,6 @@ If that happens open the Bluetooth Preferences, select the Nintendo device on th list and remove it (by clicking on the minus sign). Close the Preference Pane and try again. -If you get the following error on runtime when connecting to your wiimote: -`Unable to write over the output channel`, -you probably won't be able to read IR or accelerometer data, or make the wiimote vibrate. -Relaunching your application and connecting again should solve this issue. - Acknowledgements by Michael Laforest ------------------------------------ diff --git a/src/io_mac.m b/src/io_mac.m index a586417..80ab33d 100755 --- a/src/io_mac.m +++ b/src/io_mac.m @@ -755,8 +755,40 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) IOBluetoothL2CAPChannel* channel = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->outputCh]; IOReturn error = [channel writeSync:buf length:length]; - if (error != kIOReturnSuccess) - WIIUSE_ERROR("Unable to write over the output channel (id %i).", wm->unid); + + if (error != kIOReturnSuccess) + { + WIIUSE_ERROR("Unable to write over the output channel (id %i).", wm->unid); + WIIUSE_INFO("Attempting to reopen the output channel (id %i).", wm->unid); + + IOReturn error = [channel closeChannel]; + if (error != kIOReturnSuccess) + WIIUSE_ERROR("Unable to close the output channel (id %i).", wm->unid); + [channel setDelegate:nil]; + usleep(10000); + [channel release]; + wm->outputCh = 0; + + WiiConnect* connect = (WiiConnect*)(wm->connectionHandler); + + IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device]; + channel = [connect openL2CAPChannelWithPSM:WM_OUTPUT_CHANNEL device:device delegate:connect]; + if (!channel) { + WIIUSE_ERROR("Unable to open L2CAP output channel (id %i).", wm->unid); + [device closeConnection]; + return kIOReturnNotOpen; + } + wm->outputCh = [[channel retain] getL2CAPChannelRef]; + usleep(20000); + + WIIUSE_INFO("Attempting to write again through the output channel (id %i).", wm->unid); + error = [channel writeSync:buf length:length]; + if (error != kIOReturnSuccess) + { + WIIUSE_ERROR("Unable to write again over the output channel (id %i).", wm->unid); + } + } + usleep(10000); [pool drain];