From c9dfcf8cf7d500d58cd8f2b375be123f5b99bb52 Mon Sep 17 00:00:00 2001 From: Andrew de los Reyes Date: Fri, 3 Feb 2012 21:46:10 -0800 Subject: [PATCH] Add Support for Wii Motion Plus INSIDE Wii Remotes on Mac OS X. This patch makes a few changes necessary for support for the new Wii Remotes: - For all OSes: - Adds a new bool member variable m_motion_plus_inside to identify the new Wii Remotes. - If we have a new Wii Remote, use a head byte of 0xa2. We could just change this behavior for all Wii Remotes, but an existing comment suggests that would break 3rd party Wii Remotes. - On Mac OS X: - Expand the search criteria for the bluetooth scan. This is necessary because the new Wii Remote identifies with minor class kBluetoothDeviceClassMinorPeripheral2Gamepad, but the old Wii Remotes use minor class kBluetoothDeviceClassMinorPeripheral2Joystick (1). - Send commands on the interrupt channel, not the control channel. The new Wii Remotes require this; old ones are compatible with this. Note: 3rd party Wii Remots are untested with this change; the hope is they are still functional. - Get the name of the bluetooth device and see if it ends in "-TR". If so, set a member variable so we know it's the new kind of Wii Remote. This should fix issue 5011 for Mac OS X: http://code.google.com/p/dolphin-emu/issues/detail?id=5011 --- Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm | 8 ++++++-- Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp | 10 ++++++---- Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm index 0c2f742987..a899dac201 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm @@ -129,7 +129,7 @@ int FindWiimotes(Wiimote **wm, int max_wiimotes) [bti setInquiryLength: 5]; [bti setSearchCriteria: kBluetoothServiceClassMajorAny majorDeviceClass: kBluetoothDeviceClassMajorPeripheral - minorDeviceClass: kBluetoothDeviceClassMinorPeripheral2Joystick + minorDeviceClass: kBluetoothDeviceClassMinorAny ]; [bti setUpdateNewDeviceNames: NO]; @@ -177,6 +177,10 @@ bool Wiimote::Connect() if (IsConnected()) return false; + if ([btd remoteNameRequest:nil] == kIOReturnSuccess) + m_motion_plus_inside = + static_cast([[btd getName] hasSuffix:@"-TR"]); + [btd openL2CAPChannelSync: &cchan withPSM: kBluetoothL2CAPPSMHIDControl delegate: cbt]; [btd openL2CAPChannelSync: &ichan @@ -244,7 +248,7 @@ int Wiimote::IOWrite(unsigned char *buf, int len) if (!IsConnected()) return 0; - ret = [cchan writeAsync: buf length: len refcon: nil]; + ret = [ichan writeAsync: buf length: len refcon: nil]; if (ret == kIOReturnSuccess) return len; diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index f5ded4125d..1ac0823ebb 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -50,6 +50,7 @@ Wiimote::Wiimote(const unsigned int _index) #endif , leds(0), m_last_data_report(Report((u8 *)NULL, 0)) , m_channel(0), m_connected(false) + , m_motion_plus_inside(false) { #if defined(__linux__) && HAVE_BLUEZ bdaddr = (bdaddr_t){{0, 0, 0, 0, 0, 0}}; @@ -142,15 +143,16 @@ void Wiimote::InterruptChannel(const u16 channel, const void* const data, const rpt.second = (u8)size; memcpy(rpt.first, (u8*)data, size); - // Convert output DATA packets to SET_REPORT packets. - // Nintendo Wiimotes work without this translation, but 3rd + // Convert output DATA packets to SET_REPORT packets for non-TR + // Wiimotes. Nintendo Wiimotes work without this translation, but 3rd // party ones don't. + u8 head = m_motion_plus_inside ? 0xa2 : 0x52; if (rpt.first[0] == 0xa2) { - rpt.first[0] = 0x52; + rpt.first[0] = head; } - if (rpt.first[0] == 0x52 && rpt.first[1] == 0x18 && rpt.second == 23) + if (rpt.first[0] == head && rpt.first[1] == 0x18 && rpt.second == 23) { m_audio_reports.Push(rpt); return; diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h index f3c5b884f8..8229abee52 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h @@ -95,6 +95,7 @@ private: void ThreadFunc(); bool m_connected; + bool m_motion_plus_inside; std::thread m_wiimote_thread; Common::FifoQueue m_read_reports; Common::FifoQueue m_write_reports;