From 7b13623d1295ab2217ce5bd5561bee07dafb9e0a Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Mon, 12 Nov 2012 01:45:32 +0100 Subject: [PATCH] use the interrupt (data) channel as output channel on mac --- src/os_mac/os_mac.m | 32 ++++++++++++++++---------------- src/wiiuse.c | 6 +++++- src/wiiuse_internal.h | 1 + 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 15c9e3b..517441a 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -100,10 +100,10 @@ } // open channels - if(![self connectChannel:&controlChannel PSM:WM_OUTPUT_CHANNEL]) { + if(![self connectChannel:&controlChannel PSM:kBluetoothL2CAPPSMHIDControl]) { [self disconnect]; return kIOReturnNotOpen; - } else if(![self connectChannel:&interruptChannel PSM:WM_INPUT_CHANNEL]) { + } else if(![self connectChannel:&interruptChannel PSM:kBluetoothL2CAPPSMHIDInterrupt]) { [self disconnect]; return kIOReturnNotOpen; } @@ -210,26 +210,26 @@ } - (int) writeBuffer: (byte*) buffer length: (NSUInteger) length { - if(controlChannel == nil) { - WIIUSE_ERROR("Attempted to write to nil control channel [id %i].", wm->unid); + if(interruptChannel == nil) { + WIIUSE_ERROR("Attempted to write to nil interrupt channel [id %i].", wm->unid); return 0; } - IOReturn error = [controlChannel writeSync:buffer length:length]; + IOReturn error = [interruptChannel writeSync:buffer length:length]; if (error != kIOReturnSuccess) { - WIIUSE_ERROR("Error writing to control channel [id %i].", wm->unid); + WIIUSE_ERROR("Error writing to interrupt channel [id %i].", wm->unid); - WIIUSE_DEBUG("Attempting to reopen the control channel [id %i].", wm->unid); - [self disconnectChannel:&controlChannel]; - [self connectChannel:&controlChannel PSM:WM_OUTPUT_CHANNEL]; - if(!controlChannel) { - WIIUSE_ERROR("Error reopening the control channel [id %i].", wm->unid); + WIIUSE_DEBUG("Attempting to reopen the interrupt channel [id %i].", wm->unid); + [self disconnectChannel:&interruptChannel]; + [self connectChannel:&interruptChannel PSM:kBluetoothL2CAPPSMHIDInterrupt]; + if(!interruptChannel) { + WIIUSE_ERROR("Error reopening the interrupt channel [id %i].", wm->unid); [self disconnect]; } else { - WIIUSE_DEBUG("Attempting to write again to the control channel [id %i].", wm->unid); - error = [controlChannel writeSync:buffer length:length]; + WIIUSE_DEBUG("Attempting to write again to the interrupt channel [id %i].", wm->unid); + error = [interruptChannel writeSync:buffer length:length]; if (error != kIOReturnSuccess) - WIIUSE_ERROR("Unable to write again to the control channel [id %i].", wm->unid); + WIIUSE_ERROR("Unable to write again to the interrupt channel [id %i].", wm->unid); } } @@ -242,8 +242,8 @@ byte* data = (byte*) data_; - // This is done in case the output channel woke up this handler - if(!data || ([channel PSM] == WM_OUTPUT_CHANNEL)) { + // This is done in case the control channel woke up this handler + if(!data || ([channel PSM] == kBluetoothL2CAPPSMHIDControl)) { return; } diff --git a/src/wiiuse.c b/src/wiiuse.c index 6d1ff5e..a3fd854 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -663,7 +663,11 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { #ifdef WIIUSE_WIN32 buf[0] = report_type; #else - buf[0] = WM_SET_REPORT | WM_BT_OUTPUT; + #ifdef WIIUSE_MAC + buf[0] = WM_SET_DATA | WM_BT_OUTPUT; + #else // *NIX + buf[0] = WM_SET_REPORT | WM_BT_OUTPUT; + #endif buf[1] = report_type; #endif diff --git a/src/wiiuse_internal.h b/src/wiiuse_internal.h index 7c02113..4ec921d 100644 --- a/src/wiiuse_internal.h +++ b/src/wiiuse_internal.h @@ -104,6 +104,7 @@ #define WM_INPUT_CHANNEL 0x13 #define WM_SET_REPORT 0x50 +#define WM_SET_DATA 0xA0 /* commands */ #define WM_CMD_LED 0x11