From 9272d3c62839cab8be973c03aae0d44bed419ae1 Mon Sep 17 00:00:00 2001 From: Sonicadvance1 Date: Sat, 13 Feb 2010 20:54:05 +0000 Subject: [PATCH] Actually use the timeout requested in Wiiuse in OSX, and if there is no BT device or it's disabled, catch it so we don't get stuck in an infinite loop git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5049 8ced0084-cf51-0410-be5f-012b33b47a6e --- Externals/WiiUseSrc/Src/io_osx.m | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Externals/WiiUseSrc/Src/io_osx.m b/Externals/WiiUseSrc/Src/io_osx.m index e7e6fe8d9d..f465450a00 100644 --- a/Externals/WiiUseSrc/Src/io_osx.m +++ b/Externals/WiiUseSrc/Src/io_osx.m @@ -41,6 +41,7 @@ #import #import #import +#import IOBluetoothDeviceInquiry *bti; IOBluetoothDevice * btd; @@ -183,10 +184,10 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address); SearchBT *sbt; ConnectBT *cbt; -void detectWiimote() { +void detectWiimote(int timeout) { [bti setDelegate: sbt]; - [bti setInquiryLength:20]; + [bti setInquiryLength:timeout]; [bti setSearchCriteria:kBluetoothServiceClassMajorAny majorDeviceClass:0x05 minorDeviceClass:0x01]; [bti setUpdateNewDeviceNames:NO]; @@ -226,13 +227,22 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - sbt = [[SearchBT alloc] init]; - cbt = [[ConnectBT alloc] init]; - bti = [[IOBluetoothDeviceInquiry alloc] init]; + IOBluetoothHostController *bth = [[IOBluetoothHostController alloc] init]; + if([bth addressAsString] == nil) + { + // Method addressAsString will return nil since it can't find a device + WIIUSE_INFO("No BT device"); + [bth release]; + [pool release]; + return 0; // 0 Wiimotes found + } + sbt = [[SearchBT alloc] init]; + cbt = [[ConnectBT alloc] init]; + bti = [[IOBluetoothDeviceInquiry alloc] init]; - detectWiimote(); + detectWiimote(timeout); - CFRunLoopRun(); + CFRunLoopRun(); found_wiimotes = 0;