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;