From d3361494cec1b03523311fdda37d24a8382e0ed8 Mon Sep 17 00:00:00 2001 From: Andrew de los Reyes Date: Thu, 22 Mar 2012 20:55:41 -0700 Subject: [PATCH] WiiremoteReal for Mac: Find Wiimotes by name. The decided way to find Wii Remotes is by their bluetooth name, so this patch introduces common code to identify if a given string is a valid Wiimote name. On Mac, when scanning bluetooth, consult the function with all found bluetooth devices. --- Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm | 10 ++++------ .../Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp | 15 +++++++++++++++ Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h | 2 ++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm index 7dbb45e6f1..8e3586f7d9 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm @@ -127,11 +127,6 @@ int FindWiimotes(Wiimote **wm, int max_wiimotes) bti = [[IOBluetoothDeviceInquiry alloc] init]; [bti setDelegate: sbt]; [bti setInquiryLength: 5]; - [bti setSearchCriteria: kBluetoothServiceClassMajorAny - majorDeviceClass: kBluetoothDeviceClassMajorPeripheral - minorDeviceClass: kBluetoothDeviceClassMinorPeripheral2Joystick - ]; - [bti setUpdateNewDeviceNames: NO]; if ([bti start] == kIOReturnSuccess) [bti retain]; @@ -149,6 +144,9 @@ int FindWiimotes(Wiimote **wm, int max_wiimotes) en = [[bti foundDevices] objectEnumerator]; for (int i = 0; i < found_devices; i++) { + IOBluetoothDevice *dev = [en nextObject]; + if (!IsValidBluetoothName([[dev name] UTF8String])) + continue; // Find an unused slot for (int k = 0; k < MAX_WIIMOTES; k++) { if (wm[k] != NULL || @@ -156,7 +154,7 @@ int FindWiimotes(Wiimote **wm, int max_wiimotes) continue; wm[k] = new Wiimote(k); - wm[k]->btd = [en nextObject]; + wm[k]->btd = dev; found_wiimotes++; break; } diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index 8c7b01a72c..5e03e36e68 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -512,4 +512,19 @@ void StateChange(EMUSTATE_CHANGE newState) // TODO: disable/enable auto reporting, maybe } +#define ARRAYSIZE(_arr) (sizeof(_arr)/(sizeof(_arr[0]))) + +bool IsValidBluetoothName(const char* name) { + static const char* kValidWiiRemoteBluetoothNames[] = { + "Nintendo RVL-CNT-01", + "Nintendo RVL-CNT-01-TR", + "Nintendo RVL-WBC-01", + }; + for (size_t i = 0; i < ARRAYSIZE(kValidWiiRemoteBluetoothNames); i++) + if (strcmp(name, kValidWiiRemoteBluetoothNames[i]) == 0) + return true; + return false; +} + + }; // end of namespace diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h index f3c5b884f8..cd1080903f 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h @@ -113,6 +113,8 @@ void StateChange(EMUSTATE_CHANGE newState); int FindWiimotes(Wiimote** wm, int max_wiimotes); +bool IsValidBluetoothName(const char* name); + }; // WiimoteReal #endif