Support for multiple wiimotes on OS X.
Fixes issue 3703. Note that HLE wiimote activation is currently a little broken, so to use multiple wiimotes you need to open the wiimote configuration window, refresh (connect to) the real wiimotes, start the emulation and then select Connect Wiimote 2/3/4 from the Tools menu or with hotkeys. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6648 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
e059587c1a
commit
edbc06bd18
|
@ -45,7 +45,7 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
maxWM = BT_DINF[0];
|
maxWM = BT_DINF[0];
|
||||||
bdaddr_t tmpBD;// = BDADDR_ANY;
|
bdaddr_t tmpBD = BDADDR_ANY;
|
||||||
u8 i = 0;
|
u8 i = 0;
|
||||||
while (i < maxWM)
|
while (i < maxWM)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,8 +36,7 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305* GetUsbPointer()
|
||||||
}
|
}
|
||||||
|
|
||||||
CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bdaddr_t _BD, bool ready)
|
CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bdaddr_t _BD, bool ready)
|
||||||
: m_BD(_BD)
|
: m_HIDControlChannel_Connected(false)
|
||||||
, m_HIDControlChannel_Connected(false)
|
|
||||||
, m_HIDControlChannel_ConnectedWait(false)
|
, m_HIDControlChannel_ConnectedWait(false)
|
||||||
, m_HIDControlChannel_Config(false)
|
, m_HIDControlChannel_Config(false)
|
||||||
, m_HIDControlChannel_ConfigWait(false)
|
, m_HIDControlChannel_ConfigWait(false)
|
||||||
|
@ -45,6 +44,7 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305*
|
||||||
, m_HIDInterruptChannel_ConnectedWait(false)
|
, m_HIDInterruptChannel_ConnectedWait(false)
|
||||||
, m_HIDInterruptChannel_Config(false)
|
, m_HIDInterruptChannel_Config(false)
|
||||||
, m_HIDInterruptChannel_ConfigWait(false)
|
, m_HIDInterruptChannel_ConfigWait(false)
|
||||||
|
, m_BD(_BD)
|
||||||
, m_Name("Nintendo RVL-CNT-01")
|
, m_Name("Nintendo RVL-CNT-01")
|
||||||
, m_pHost(_pHost)
|
, m_pHost(_pHost)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +56,6 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305*
|
||||||
m_ConnectionHandle = 0x100 + _Number;
|
m_ConnectionHandle = 0x100 + _Number;
|
||||||
memset(m_LinkKey, 0xA0 + _Number, 16);
|
memset(m_LinkKey, 0xA0 + _Number, 16);
|
||||||
|
|
||||||
|
|
||||||
bdaddr_t _nullBD = BDADDR_ANY;
|
bdaddr_t _nullBD = BDADDR_ANY;
|
||||||
if (memcmp(&m_BD, &_nullBD, sizeof(bdaddr_t))==0)
|
if (memcmp(&m_BD, &_nullBD, sizeof(bdaddr_t))==0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -112,7 +112,7 @@ typedef struct {
|
||||||
uint8_t b[BLUETOOTH_BDADDR_SIZE];
|
uint8_t b[BLUETOOTH_BDADDR_SIZE];
|
||||||
} bdaddr_t;
|
} bdaddr_t;
|
||||||
|
|
||||||
#define BDADDR_ANY {0, 0, 0, 0, 0, 0}
|
#define BDADDR_ANY { { 0, 0, 0, 0, 0, 0 } }
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
|
|
|
@ -37,20 +37,12 @@ extern "C" OSErr UpdateSystemActivity(UInt8 activity);
|
||||||
#import <IOBluetooth/IOBluetooth.h>
|
#import <IOBluetooth/IOBluetooth.h>
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include "HW/Wiimote.h"
|
||||||
#include "wiiuse_internal.h"
|
#include "wiiuse_internal.h"
|
||||||
|
|
||||||
static int wiiuse_connect_single(struct wiimote_t *wm, char *address);
|
static int wiiuse_connect_single(struct wiimote_t *wm, char *address);
|
||||||
|
|
||||||
IOBluetoothDevice *btd;
|
static struct wiimote_t *motes[MAX_WIIMOTES];
|
||||||
IOBluetoothL2CAPChannel *ichan;
|
|
||||||
IOBluetoothL2CAPChannel *cchan;
|
|
||||||
|
|
||||||
#define QUEUE_SIZE 64
|
|
||||||
struct buffer {
|
|
||||||
char data[MAX_PAYLOAD];
|
|
||||||
int len;
|
|
||||||
} queue[QUEUE_SIZE];
|
|
||||||
volatile int reader, writer, outstanding, watermark;
|
|
||||||
|
|
||||||
@interface SearchBT: NSObject {
|
@interface SearchBT: NSObject {
|
||||||
@public
|
@public
|
||||||
|
@ -86,29 +78,44 @@ volatile int reader, writer, outstanding, watermark;
|
||||||
data: (byte *) data
|
data: (byte *) data
|
||||||
length: (NSUInteger) length
|
length: (NSUInteger) length
|
||||||
{
|
{
|
||||||
// IOBluetoothDevice *device = [l2capChannel getDevice];
|
IOBluetoothDevice *device = [l2capChannel getDevice];
|
||||||
|
struct wiimote_t *wm = NULL;
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_WIIMOTES; i++) {
|
||||||
|
if (motes[i] == NULL)
|
||||||
|
continue;
|
||||||
|
if ([device isEqual: motes[i]->btd] == TRUE)
|
||||||
|
wm = motes[i];
|
||||||
|
if (i == MAX_WIIMOTES && wm == NULL) {
|
||||||
|
WARN_LOG(WIIMOTE, "Received packet for unknown wiimote");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (length > MAX_PAYLOAD) {
|
if (length > MAX_PAYLOAD) {
|
||||||
WARN_LOG(WIIMOTE, "Dropping wiimote packet - too large");
|
WARN_LOG(WIIMOTE, "Dropping wiimote packet, too large [id %i]",
|
||||||
|
wm->unid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue[writer].len != 0) {
|
if (wm->queue[wm->writer].len != 0) {
|
||||||
WARN_LOG(WIIMOTE, "Dropping wiimote packet - queue full");
|
WARN_LOG(WIIMOTE, "Dropping wiimote packet, queue full [id %i]",
|
||||||
|
wm->unid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(queue[writer].data, data, length);
|
memcpy(wm->queue[wm->writer].data, data, length);
|
||||||
queue[writer].len = length;
|
wm->queue[wm->writer].len = length;
|
||||||
|
|
||||||
writer++;
|
wm->writer++;
|
||||||
outstanding++;
|
wm->outstanding++;
|
||||||
if (writer == QUEUE_SIZE)
|
if (wm->writer == QUEUE_SIZE)
|
||||||
writer = 0;
|
wm->writer = 0;
|
||||||
|
|
||||||
if (outstanding > watermark) {
|
if (wm->outstanding > wm->watermark) {
|
||||||
watermark = outstanding;
|
wm->watermark = wm->outstanding;
|
||||||
WARN_LOG(WIIMOTE, "New wiimote queue watermark %d", watermark);
|
WARN_LOG(WIIMOTE, "New wiimote queue watermark %i [id %i]",
|
||||||
|
wm->watermark, wm->unid);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
CFRunLoopStop(CFRunLoopGetCurrent());
|
||||||
|
@ -118,15 +125,27 @@ volatile int reader, writer, outstanding, watermark;
|
||||||
|
|
||||||
- (void) l2capChannelClosed: (IOBluetoothL2CAPChannel *) l2capChannel
|
- (void) l2capChannelClosed: (IOBluetoothL2CAPChannel *) l2capChannel
|
||||||
{
|
{
|
||||||
// IOBluetoothDevice *device = [l2capChannel getDevice];
|
IOBluetoothDevice *device = [l2capChannel getDevice];
|
||||||
|
struct wiimote_t *wm = NULL;
|
||||||
|
|
||||||
WARN_LOG(WIIMOTE, "L2CAP channel was closed");
|
for (int i = 0; i < MAX_WIIMOTES; i++) {
|
||||||
|
if (motes[i] == NULL)
|
||||||
|
continue;
|
||||||
|
if ([device isEqual: motes[i]->btd] == TRUE)
|
||||||
|
wm = motes[i];
|
||||||
|
if (i == MAX_WIIMOTES && wm == NULL) {
|
||||||
|
WARN_LOG(WIIMOTE, "Received packet for unknown wiimote");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (l2capChannel == cchan)
|
WARN_LOG(WIIMOTE, "L2CAP channel was closed [id %i]", wm->unid);
|
||||||
cchan = nil;
|
|
||||||
|
|
||||||
if (l2capChannel == ichan)
|
if (l2capChannel == wm->cchan)
|
||||||
ichan = nil;
|
wm->cchan = nil;
|
||||||
|
|
||||||
|
if (l2capChannel == wm->ichan)
|
||||||
|
wm->ichan = nil;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -154,6 +173,9 @@ int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout)
|
||||||
NSEnumerator *en;
|
NSEnumerator *en;
|
||||||
int i, found_devices = 0;
|
int i, found_devices = 0;
|
||||||
|
|
||||||
|
if (max_wiimotes > MAX_WIIMOTES)
|
||||||
|
return 0;
|
||||||
|
|
||||||
bth = [[IOBluetoothHostController alloc] init];
|
bth = [[IOBluetoothHostController alloc] init];
|
||||||
if ([bth addressAsString] == nil)
|
if ([bth addressAsString] == nil)
|
||||||
{
|
{
|
||||||
|
@ -164,7 +186,6 @@ int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout)
|
||||||
|
|
||||||
sbt = [[SearchBT alloc] init];
|
sbt = [[SearchBT alloc] init];
|
||||||
sbt->maxDevices = max_wiimotes;
|
sbt->maxDevices = max_wiimotes;
|
||||||
/*XXX*/ sbt->maxDevices = 1;
|
|
||||||
bti = [[IOBluetoothDeviceInquiry alloc] init];
|
bti = [[IOBluetoothDeviceInquiry alloc] init];
|
||||||
[bti setDelegate: sbt];
|
[bti setDelegate: sbt];
|
||||||
[bti setInquiryLength: timeout];
|
[bti setInquiryLength: timeout];
|
||||||
|
@ -172,6 +193,7 @@ int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout)
|
||||||
majorDeviceClass: kBluetoothDeviceClassMajorPeripheral
|
majorDeviceClass: kBluetoothDeviceClassMajorPeripheral
|
||||||
minorDeviceClass: kBluetoothDeviceClassMinorPeripheral2Joystick
|
minorDeviceClass: kBluetoothDeviceClassMinorPeripheral2Joystick
|
||||||
];
|
];
|
||||||
|
[bti setUpdateNewDeviceNames: FALSE];
|
||||||
|
|
||||||
IOReturn ret = [bti start];
|
IOReturn ret = [bti start];
|
||||||
if (ret == kIOReturnSuccess)
|
if (ret == kIOReturnSuccess)
|
||||||
|
@ -184,13 +206,17 @@ int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout)
|
||||||
[bti stop];
|
[bti stop];
|
||||||
found_devices = [[bti foundDevices] count];
|
found_devices = [[bti foundDevices] count];
|
||||||
|
|
||||||
NOTICE_LOG(WIIMOTE, "Found %i bluetooth device(s).", found_devices);
|
NOTICE_LOG(WIIMOTE, "Found %i bluetooth device%c", found_devices,
|
||||||
|
found_devices == 1 ? '\0' : 's');
|
||||||
|
|
||||||
en = [[bti foundDevices] objectEnumerator];
|
en = [[bti foundDevices] objectEnumerator];
|
||||||
for (i = 0; i < found_devices; i++) {
|
for (i = 0; i < found_devices; i++) {
|
||||||
btd = [en nextObject];
|
wm[i]->btd = [en nextObject];
|
||||||
WIIMOTE_ENABLE_STATE(wm[i], WIIMOTE_STATE_DEV_FOUND);
|
WIIMOTE_ENABLE_STATE(wm[i], WIIMOTE_STATE_DEV_FOUND);
|
||||||
|
motes[i] = wm[i];
|
||||||
}
|
}
|
||||||
|
for (i = found_devices; i < MAX_WIIMOTES; i++)
|
||||||
|
motes[i] = NULL;
|
||||||
|
|
||||||
[bth release];
|
[bth release];
|
||||||
[bti release];
|
[bti release];
|
||||||
|
@ -247,16 +273,18 @@ static int wiiuse_connect_single(struct wiimote_t *wm, char *address)
|
||||||
if (wm == NULL || WIIMOTE_IS_CONNECTED(wm))
|
if (wm == NULL || WIIMOTE_IS_CONNECTED(wm))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
[btd openL2CAPChannelSync: &cchan
|
[wm->btd openL2CAPChannelSync: &wm->cchan
|
||||||
withPSM: kBluetoothL2CAPPSMHIDControl delegate: cbt];
|
withPSM: kBluetoothL2CAPPSMHIDControl delegate: cbt];
|
||||||
[btd openL2CAPChannelSync: &ichan
|
[wm->btd openL2CAPChannelSync: &wm->ichan
|
||||||
withPSM: kBluetoothL2CAPPSMHIDInterrupt delegate: cbt];
|
withPSM: kBluetoothL2CAPPSMHIDInterrupt delegate: cbt];
|
||||||
if (ichan == NULL || cchan == NULL) {
|
if (wm->ichan == NULL || wm->cchan == NULL) {
|
||||||
ERROR_LOG(WIIMOTE, "Unable to open L2CAP channels");
|
ERROR_LOG(WIIMOTE, "Unable to open L2CAP channels [id %i]",
|
||||||
|
wm->unid);
|
||||||
wiiuse_disconnect(wm);
|
wiiuse_disconnect(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
NOTICE_LOG(WIIMOTE, "Connected to wiimote [id %i].", wm->unid);
|
NOTICE_LOG(WIIMOTE, "Connected to wiimote at %s [id %i]",
|
||||||
|
[[wm->btd getAddressString] UTF8String], wm->unid);
|
||||||
|
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||||
wiiuse_set_report_type(wm);
|
wiiuse_set_report_type(wm);
|
||||||
|
@ -277,6 +305,7 @@ static int wiiuse_connect_single(struct wiimote_t *wm, char *address)
|
||||||
*/
|
*/
|
||||||
void wiiuse_disconnect(struct wiimote_t *wm)
|
void wiiuse_disconnect(struct wiimote_t *wm)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (wm == NULL)
|
if (wm == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -285,9 +314,9 @@ void wiiuse_disconnect(struct wiimote_t *wm)
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||||
|
|
||||||
[cchan closeChannel];
|
[wm->cchan closeChannel];
|
||||||
[ichan closeChannel];
|
[wm->ichan closeChannel];
|
||||||
[btd closeConnection];
|
[wm->btd closeConnection];
|
||||||
}
|
}
|
||||||
|
|
||||||
int wiiuse_io_read(struct wiimote_t *wm)
|
int wiiuse_io_read(struct wiimote_t *wm)
|
||||||
|
@ -297,20 +326,20 @@ int wiiuse_io_read(struct wiimote_t *wm)
|
||||||
if (!WIIMOTE_IS_CONNECTED(wm))
|
if (!WIIMOTE_IS_CONNECTED(wm))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (outstanding == 0)
|
if (wm->outstanding == 0)
|
||||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true);
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true);
|
||||||
|
|
||||||
if (queue[reader].len == 0)
|
if (wm->queue[wm->reader].len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bytes = queue[reader].len;
|
bytes = wm->queue[wm->reader].len;
|
||||||
memcpy(wm->event_buf, queue[reader].data, bytes);
|
memcpy(wm->event_buf, wm->queue[wm->reader].data, bytes);
|
||||||
queue[reader].len = 0;
|
wm->queue[wm->reader].len = 0;
|
||||||
|
|
||||||
reader++;
|
wm->reader++;
|
||||||
outstanding--;
|
wm->outstanding--;
|
||||||
if (reader == QUEUE_SIZE)
|
if (wm->reader == QUEUE_SIZE)
|
||||||
reader = 0;
|
wm->reader = 0;
|
||||||
|
|
||||||
if (wm->event_buf[0] == '\0')
|
if (wm->event_buf[0] == '\0')
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
|
@ -322,7 +351,7 @@ int wiiuse_io_write(struct wiimote_t *wm, byte *buf, int len)
|
||||||
{
|
{
|
||||||
IOReturn ret;
|
IOReturn ret;
|
||||||
|
|
||||||
ret = [cchan writeAsync: buf length: len refcon: nil];
|
ret = [wm->cchan writeAsync: buf length: len refcon: nil];
|
||||||
|
|
||||||
if (ret == kIOReturnSuccess)
|
if (ret == kIOReturnSuccess)
|
||||||
return len;
|
return len;
|
||||||
|
|
|
@ -155,6 +155,15 @@ typedef struct wiimote_t {
|
||||||
WCONST IOBluetoothDevice *btd;
|
WCONST IOBluetoothDevice *btd;
|
||||||
WCONST IOBluetoothL2CAPChannel *ichan;
|
WCONST IOBluetoothL2CAPChannel *ichan;
|
||||||
WCONST IOBluetoothL2CAPChannel *cchan;
|
WCONST IOBluetoothL2CAPChannel *cchan;
|
||||||
|
#define QUEUE_SIZE 64
|
||||||
|
WCONST struct buffer {
|
||||||
|
char data[MAX_PAYLOAD];
|
||||||
|
int len;
|
||||||
|
} queue[QUEUE_SIZE];
|
||||||
|
WCONST int reader;
|
||||||
|
WCONST int writer;
|
||||||
|
WCONST int outstanding;
|
||||||
|
WCONST int watermark;
|
||||||
#elif defined(__linux__) && HAVE_BLUEZ
|
#elif defined(__linux__) && HAVE_BLUEZ
|
||||||
WCONST bdaddr_t bdaddr; /**< bt address (linux) */
|
WCONST bdaddr_t bdaddr; /**< bt address (linux) */
|
||||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||||
|
|
Loading…
Reference in New Issue