Update of /cvsroot/pure-data/externals/io/wiiremote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1020
Modified Files:
aka.wiiremote.c wiiremote.c wiiremote.h
Added Files:
aka.wiiremote_b2_pd-port.patch aka.wiiremote_b3_pd-port.patch
aka.wiiremote_b4_pd-port.patch
Log Message:
ported b4 from Masayuki Akamatsu, fixed one minor warning
Index: wiiremote.h
===================================================================
RCS file: /cvsroot/pure-data/externals/io/wiiremote/wiiremote.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** wiiremote.h 28 Dec 2006 22:57:22 -0000 1.2
--- wiiremote.h 28 Dec 2006 23:16:03 -0000 1.3
***************
*** 6,10 ****
#include <IOBluetooth/Bluetooth.h>
#include <IOBluetooth/IOBluetoothUserLib.h>
-
#include <stdio.h>
#include <string.h>
--- 6,9 ----
***************
*** 51,63 ****
} WiiRemoteRec, *WiiRemoteRef;
! WiiRemoteRef wiiremote_init(void);
! Boolean wiiremote_isconnected(void);
! Boolean wiiremote_search(void);
! Boolean wiiremote_stopsearch(void);
! Boolean wiiremote_connect(void);
! Boolean wiiremote_disconnect(void);
! Boolean wiiremote_motionsensor(Boolean enabled);
! Boolean wiiremote_irsensor(Boolean enabled);
! Boolean wiiremote_vibration(Boolean enabled);
! Boolean wiiremote_led(Boolean enabled1, Boolean enabled2, Boolean enabled3, Boolean enabled4);
! void wiiremote_getstatus(void);
--- 50,62 ----
} WiiRemoteRec, *WiiRemoteRef;
! void wiiremote_init(WiiRemoteRef wiiremote);
! Boolean wiiremote_isconnected(WiiRemoteRef wiiremote);
! Boolean wiiremote_search(WiiRemoteRef wiiremote);
! Boolean wiiremote_stopsearch(WiiRemoteRef wiiremote);
! Boolean wiiremote_connect(WiiRemoteRef wiiremote);
! Boolean wiiremote_disconnect(WiiRemoteRef wiiremote);
! Boolean wiiremote_motionsensor(WiiRemoteRef wiiremote, Boolean enabled);
! Boolean wiiremote_irsensor(WiiRemoteRef wiiremote, Boolean enabled);
! Boolean wiiremote_vibration(WiiRemoteRef wiiremote, Boolean enabled);
! Boolean wiiremote_led(WiiRemoteRef wiiremote, Boolean enabled1, Boolean enabled2, Boolean enabled3, Boolean enabled4);
! Boolean wiiremote_getstatus(WiiRemoteRef wiiremote);
Index: wiiremote.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/wiiremote/wiiremote.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** wiiremote.c 28 Dec 2006 22:57:22 -0000 1.3
--- wiiremote.c 28 Dec 2006 23:16:03 -0000 1.4
***************
*** 11,46 ****
#define kTrial 10
! static WiiRemoteRec gWiiRemote;
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
! WiiRemoteRef wiiremote_init(void)
{
! gWiiRemote.inquiry = nil;
! gWiiRemote.device = nil;
! gWiiRemote.ichan = nil;
! gWiiRemote.cchan = nil;
!
! gWiiRemote.accX = 0x10;
! gWiiRemote.accY = 0x10;
! gWiiRemote.accZ = 0x10;
! gWiiRemote.buttonData = 0;
! gWiiRemote.leftPoint = -1;
! gWiiRemote.tracking = false;
! gWiiRemote.batteryLevel = 0;
! gWiiRemote.isIRSensorEnabled = false;
! gWiiRemote.isMotionSensorEnabled = false;
! gWiiRemote.isVibrationEnabled = false;
! gWiiRemote.isExpansionPortUsed = false;
! gWiiRemote.isLED1Illuminated = false;
! gWiiRemote.isLED2Illuminated = false;
! gWiiRemote.isLED3Illuminated = false;
! gWiiRemote.isLED4Illuminated = false;
! return &gWiiRemote;
}
--- 11,44 ----
#define kTrial 10
! //static WiiRemoteRec gWiiRemote; // remove in 1.0B4
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
! void wiiremote_init(WiiRemoteRef wiiremote)
{
! wiiremote->inquiry = nil;
! wiiremote->device = nil;
! wiiremote->ichan = nil;
! wiiremote->cchan = nil;
! wiiremote->accX = 0x10;
! wiiremote->accY = 0x10;
! wiiremote->accZ = 0x10;
! wiiremote->buttonData = 0;
! wiiremote->leftPoint = -1;
! wiiremote->tracking = false;
! wiiremote->batteryLevel = 0;
! wiiremote->isIRSensorEnabled = false;
! wiiremote->isMotionSensorEnabled = false;
! wiiremote->isVibrationEnabled = false;
! wiiremote->isExpansionPortUsed = false;
! wiiremote->isLED1Illuminated = false;
! wiiremote->isLED2Illuminated = false;
! wiiremote->isLED3Illuminated = false;
! wiiremote->isLED4Illuminated = false;
}
***************
*** 48,52 ****
//--------------------------------------------------------------------------------------------
! void checkDevice(IOBluetoothDeviceRef device)
{
CFStringRef myString;
--- 46,50 ----
//--------------------------------------------------------------------------------------------
! void checkDevice(WiiRemoteRef wiiremote, IOBluetoothDeviceRef device)
{
CFStringRef myString;
***************
*** 57,63 ****
if (CFStringCompare(myString, CFSTR("Nintendo RVL-CNT-01"), 0) == kCFCompareEqualTo)
{
! gWiiRemote.device = IOBluetoothObjectRetain(device);
! if ( !wiiremote_connect()) // add in B3
! wiiremote_disconnect(); // add in B3
}
}
--- 55,61 ----
if (CFStringCompare(myString, CFSTR("Nintendo RVL-CNT-01"), 0) == kCFCompareEqualTo)
{
! wiiremote->device = IOBluetoothObjectRetain(device);
! if ( !wiiremote_connect(wiiremote)) // add in B3
! wiiremote_disconnect(wiiremote); // add in B3
}
}
***************
*** 66,75 ****
void myFoundFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device)
{
! checkDevice(device);
}
void myUpdatedFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device, uint32_t devicesRemaining)
{
! checkDevice(device);
}
--- 64,73 ----
void myFoundFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device)
{
! checkDevice((WiiRemoteRef)refCon, device);
}
void myUpdatedFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device, uint32_t devicesRemaining)
{
! checkDevice((WiiRemoteRef)refCon, device);
}
***************
*** 80,84 ****
if (error != kIOReturnSuccess)
{
! wiiremote_stopsearch();
}
}
--- 78,82 ----
if (error != kIOReturnSuccess)
{
! wiiremote_stopsearch((WiiRemoteRef)refCon);
}
}
***************
*** 86,114 ****
//--------------------------------------------------------------------------------------------
! Boolean wiiremote_isconnected(void)
{
Boolean result;
! result = gWiiRemote.device != nil && IOBluetoothDeviceIsConnected(gWiiRemote.device);
return result;
}
! Boolean wiiremote_search(void)
{
IOReturn ret;
! if (gWiiRemote.inquiry != nil)
return true;
! gWiiRemote.inquiry = IOBluetoothDeviceInquiryCreateWithCallbackRefCon(nil);
! IOBluetoothDeviceInquirySetDeviceFoundCallback(gWiiRemote.inquiry, myFoundFunc);
! IOBluetoothDeviceInquirySetDeviceNameUpdatedCallback(gWiiRemote.inquiry, myUpdatedFunc);
! IOBluetoothDeviceInquirySetCompleteCallback(gWiiRemote.inquiry, myCompleteFunc);
! ret = IOBluetoothDeviceInquiryStart(gWiiRemote.inquiry);
if (ret != kIOReturnSuccess)
{
! IOBluetoothDeviceInquiryDelete(gWiiRemote.inquiry);
! gWiiRemote.inquiry = nil;
return false;
}
--- 84,112 ----
//--------------------------------------------------------------------------------------------
! Boolean wiiremote_isconnected(WiiRemoteRef wiiremote)
{
Boolean result;
! result = wiiremote->device != nil && IOBluetoothDeviceIsConnected(wiiremote->device);
return result;
}
! Boolean wiiremote_search(WiiRemoteRef wiiremote)
{
IOReturn ret;
! if (wiiremote->inquiry != nil)
return true;
! wiiremote->inquiry = IOBluetoothDeviceInquiryCreateWithCallbackRefCon((void *)wiiremote);
! IOBluetoothDeviceInquirySetDeviceFoundCallback(wiiremote->inquiry, myFoundFunc);
! IOBluetoothDeviceInquirySetDeviceNameUpdatedCallback(wiiremote->inquiry, myUpdatedFunc);
! IOBluetoothDeviceInquirySetCompleteCallback(wiiremote->inquiry, myCompleteFunc);
! ret = IOBluetoothDeviceInquiryStart(wiiremote->inquiry);
if (ret != kIOReturnSuccess)
{
! IOBluetoothDeviceInquiryDelete(wiiremote->inquiry);
! wiiremote->inquiry = nil;
return false;
}
***************
*** 116,129 ****
}
! Boolean wiiremote_stopsearch(void)
{
IOReturn ret;
! if (gWiiRemote.inquiry == nil)
{
return true; // already stopped
}
! ret = IOBluetoothDeviceInquiryStop(gWiiRemote.inquiry);
if (ret != kIOReturnSuccess && ret != kIOReturnNotPermitted)
--- 114,127 ----
}
! Boolean wiiremote_stopsearch(WiiRemoteRef wiiremote)
{
IOReturn ret;
! if (wiiremote->inquiry == nil)
{
return true; // already stopped
}
! ret = IOBluetoothDeviceInquiryStop(wiiremote->inquiry);
if (ret != kIOReturnSuccess && ret != kIOReturnNotPermitted)
***************
*** 132,137 ****
}
! IOBluetoothDeviceInquiryDelete(gWiiRemote.inquiry);
! gWiiRemote.inquiry = nil;
return (ret==kIOReturnSuccess);
--- 130,135 ----
}
! IOBluetoothDeviceInquiryDelete(wiiremote->inquiry);
! wiiremote->inquiry = nil;
return (ret==kIOReturnSuccess);
***************
*** 143,191 ****
void myDataListener(IOBluetoothL2CAPChannelRef channel, void *data, UInt16 length, void *refCon)
{
! unsigned char *dp = (unsigned char*)data;
! if (dp[1] == 0x20 && length >= 8)
! {
! gWiiRemote.batteryLevel = (double)dp[7];
! gWiiRemote.batteryLevel /= (double)0xC0;
! gWiiRemote.isExpansionPortUsed = (dp[4] & 0x02) != 0;
! gWiiRemote.isLED1Illuminated = (dp[4] & 0x10) != 0;
! gWiiRemote.isLED2Illuminated = (dp[4] & 0x20) != 0;
! gWiiRemote.isLED3Illuminated = (dp[4] & 0x40) != 0;
! gWiiRemote.isLED4Illuminated = (dp[4] & 0x80) != 0;
! //have to reset settings (vibration, motion, IR and so on...)
! wiiremote_irsensor(gWiiRemote.isIRSensorEnabled);
! }
if ((dp[1]&0xF0) == 0x30)
{
! gWiiRemote.buttonData = ((short)dp[2] << 8) + dp[3];
if (dp[1] & 0x01)
{
! gWiiRemote.accX = dp[4];
! gWiiRemote.accY = dp[5];
! gWiiRemote.accZ = dp[6];
! gWiiRemote.lowZ = gWiiRemote.lowZ * .9 + gWiiRemote.accZ * .1;
! gWiiRemote.lowX = gWiiRemote.lowX * .9 + gWiiRemote.accX * .1;
! float absx = abs(gWiiRemote.lowX - 128);
! float absz = abs(gWiiRemote.lowZ - 128);
! if (gWiiRemote.orientation == 0 || gWiiRemote.orientation == 2) absx -= 5;
! if (gWiiRemote.orientation == 1 || gWiiRemote.orientation == 3) absz -= 5;
if (absz >= absx)
{
if (absz > 5)
! gWiiRemote.orientation = (gWiiRemote.lowZ > 128) ? 0 : 2;
}
else
{
if (absx > 5)
! gWiiRemote.orientation = (gWiiRemote.lowX > 128) ? 3 : 1;
}
//printf("orientation: %d\n", orientation);
--- 141,190 ----
void myDataListener(IOBluetoothL2CAPChannelRef channel, void *data, UInt16 length, void *refCon)
{
! WiiRemoteRef wiiremote = (WiiRemoteRef)refCon;
! unsigned char *dp = (unsigned char*)data;
! if (dp[1] == 0x20 && length >= 8)
! {
! wiiremote->batteryLevel = (double)dp[7];
! wiiremote->batteryLevel /= (double)0xC0;
! wiiremote->isExpansionPortUsed = (dp[4] & 0x02) != 0;
! wiiremote->isLED1Illuminated = (dp[4] & 0x10) != 0;
! wiiremote->isLED2Illuminated = (dp[4] & 0x20) != 0;
! wiiremote->isLED3Illuminated = (dp[4] & 0x40) != 0;
! wiiremote->isLED4Illuminated = (dp[4] & 0x80) != 0;
! //have to reset settings (vibration, motion, IR and so on...)
! wiiremote_irsensor(wiiremote, wiiremote->isIRSensorEnabled);
! }
if ((dp[1]&0xF0) == 0x30)
{
! wiiremote->buttonData = ((short)dp[2] << 8) + dp[3];
if (dp[1] & 0x01)
{
! wiiremote->accX = dp[4];
! wiiremote->accY = dp[5];
! wiiremote->accZ = dp[6];
! wiiremote->lowZ = wiiremote->lowZ * .9 + wiiremote->accZ * .1;
! wiiremote->lowX = wiiremote->lowX * .9 + wiiremote->accX * .1;
! float absx = abs(wiiremote->lowX - 128);
! float absz = abs(wiiremote->lowZ - 128);
! if (wiiremote->orientation == 0 || wiiremote->orientation == 2) absx -= 5;
! if (wiiremote->orientation == 1 || wiiremote->orientation == 3) absz -= 5;
if (absz >= absx)
{
if (absz > 5)
! wiiremote->orientation = (wiiremote->lowZ > 128) ? 0 : 2;
}
else
{
if (absx > 5)
! wiiremote->orientation = (wiiremote->lowX > 128) ? 3 : 1;
}
//printf("orientation: %d\n", orientation);
***************
*** 197,206 ****
for(i=0 ; i<4 ; i++)
{
! gWiiRemote.irData[i].x = dp[7 + 3*i];
! gWiiRemote.irData[i].y = dp[8 + 3*i];
! gWiiRemote.irData[i].s = dp[9 + 3*i];
! gWiiRemote.irData[i].x += (gWiiRemote.irData[i].s & 0x30) << 4;
! gWiiRemote.irData[i].y += (gWiiRemote.irData[i].s & 0xC0) << 2;
! gWiiRemote.irData[i].s &= 0x0F;
}
}
--- 196,205 ----
for(i=0 ; i<4 ; i++)
{
! wiiremote->irData[i].x = dp[7 + 3*i];
! wiiremote->irData[i].y = dp[8 + 3*i];
! wiiremote->irData[i].s = dp[9 + 3*i];
! wiiremote->irData[i].x += (wiiremote->irData[i].s & 0x30) << 4;
! wiiremote->irData[i].y += (wiiremote->irData[i].s & 0xC0) << 2;
! wiiremote->irData[i].s &= 0x0F;
}
}
***************
*** 209,232 ****
float ox, oy;
! if (gWiiRemote.irData[0].s < 0x0F && gWiiRemote.irData[1].s < 0x0F)
{
! int l = gWiiRemote.leftPoint, r;
! if (gWiiRemote.leftPoint == -1)
{
// printf("Tracking.\n");
! switch (gWiiRemote.orientation)
{
! case 0: l = (gWiiRemote.irData[0].x < gWiiRemote.irData[1].x) ? 0 : 1; break;
! case 1: l = (gWiiRemote.irData[0].y > gWiiRemote.irData[1].y) ? 0 : 1; break;
! case 2: l = (gWiiRemote.irData[0].x > gWiiRemote.irData[1].x) ? 0 : 1; break;
! case 3: l = (gWiiRemote.irData[0].y < gWiiRemote.irData[1].y) ? 0 : 1; break;
}
! gWiiRemote.leftPoint = l;
}
r = 1-l;
! float dx = gWiiRemote.irData[r].x - gWiiRemote.irData[l].x;
! float dy = gWiiRemote.irData[r].y - gWiiRemote.irData[l].y;
float d = sqrt(dx*dx+dy*dy);
--- 208,231 ----
float ox, oy;
! if (wiiremote->irData[0].s < 0x0F && wiiremote->irData[1].s < 0x0F)
{
! int l = wiiremote->leftPoint, r;
! if (wiiremote->leftPoint == -1)
{
// printf("Tracking.\n");
! switch (wiiremote->orientation)
{
! case 0: l = (wiiremote->irData[0].x < wiiremote->irData[1].x) ? 0 : 1; break;
! case 1: l = (wiiremote->irData[0].y > wiiremote->irData[1].y) ? 0 : 1; break;
! case 2: l = (wiiremote->irData[0].x > wiiremote->irData[1].x) ? 0 : 1; break;
! case 3: l = (wiiremote->irData[0].y < wiiremote->irData[1].y) ? 0 : 1; break;
}
! wiiremote->leftPoint = l;
}
r = 1-l;
! float dx = wiiremote->irData[r].x - wiiremote->irData[l].x;
! float dy = wiiremote->irData[r].y - wiiremote->irData[l].y;
float d = sqrt(dx*dx+dy*dy);
***************
*** 235,242 ****
dy /= d;
! float cx = (gWiiRemote.irData[l].x+gWiiRemote.irData[r].x)/1024.0 - 1;
! float cy = (gWiiRemote.irData[l].y+gWiiRemote.irData[r].y)/1024.0 - .75;
! gWiiRemote.angle = atan2(dy, dx);
ox = -dy*cy-dx*cx;
--- 234,241 ----
dy /= d;
! float cx = (wiiremote->irData[l].x+wiiremote->irData[r].x)/1024.0 - 1;
! float cy = (wiiremote->irData[l].y+wiiremote->irData[r].y)/1024.0 - .75;
! wiiremote->angle = atan2(dy, dx);
ox = -dy*cy-dx*cx;
***************
*** 244,248 ****
//printf("x:%5.2f; y: %5.2f; angle: %5.1f\n", ox, oy, angle*180/M_PI);
! gWiiRemote.tracking = true;
}
else
--- 243,247 ----
//printf("x:%5.2f; y: %5.2f; angle: %5.1f\n", ox, oy, angle*180/M_PI);
! wiiremote->tracking = true;
}
else
***************
*** 250,259 ****
// printf("Not tracking.\n");
ox = oy = -100;
! gWiiRemote.leftPoint = -1;
! gWiiRemote.tracking = false;
}
! gWiiRemote.posX = ox;
! gWiiRemote.posY = oy;
}
--- 249,259 ----
// printf("Not tracking.\n");
ox = oy = -100;
! wiiremote->angle = -100;
! wiiremote->leftPoint = -1;
! wiiremote->tracking = false;
}
! wiiremote->posX = ox;
! wiiremote->posY = oy;
}
***************
*** 283,291 ****
//--------------------------------------------------------------------------------------------
! Boolean wiiremote_connect(void)
{
short i;
! if (gWiiRemote.device == nil)
return false;
--- 283,292 ----
//--------------------------------------------------------------------------------------------
! Boolean wiiremote_connect(WiiRemoteRef wiiremote)
{
+ IOReturn ret;
short i;
! if (wiiremote->device == nil)
return false;
***************
*** 293,297 ****
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothDeviceOpenConnection(gWiiRemote.device, nil, nil) == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
--- 294,299 ----
for (i=0; i<kTrial; i++)
{
! ret = IOBluetoothDeviceOpenConnection(wiiremote->device, nil, nil);
! if ( ret == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
***************
*** 300,309 ****
return false;
! gWiiRemote.disconnectNotification = IOBluetoothDeviceRegisterForDisconnectNotification(gWiiRemote.device, myDisconnectedFunc, 0);
// performs an SDP query
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothDevicePerformSDPQuery(gWiiRemote.device, nil, nil) == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
--- 302,312 ----
return false;
! wiiremote->disconnectNotification = IOBluetoothDeviceRegisterForDisconnectNotification(wiiremote->device, myDisconnectedFunc, 0);
// performs an SDP query
for (i=0; i<kTrial; i++)
{
! ret = IOBluetoothDevicePerformSDPQuery(wiiremote->device, nil, nil);
! if ( ret == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
***************
*** 315,319 ****
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothDeviceOpenL2CAPChannelSync(gWiiRemote.device, &(gWiiRemote.cchan), 17, myEventListener, nil) == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
--- 318,323 ----
for (i=0; i<kTrial; i++)
{
! ret = IOBluetoothDeviceOpenL2CAPChannelSync(wiiremote->device, &(wiiremote->cchan), 17, myEventListener, (void *)wiiremote);
! if ( ret == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
***************
*** 321,327 ****
if (i==kTrial)
{
! gWiiRemote.cchan = nil;
! IOBluetoothDeviceCloseConnection(gWiiRemote.device);
! gWiiRemote.device = nil;
return false;
}
--- 325,331 ----
if (i==kTrial)
{
! wiiremote->cchan = nil;
! IOBluetoothDeviceCloseConnection(wiiremote->device);
! wiiremote->device = nil;
return false;
}
***************
*** 330,334 ****
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothDeviceOpenL2CAPChannelSync(gWiiRemote.device, &(gWiiRemote.ichan), 19, myEventListener, nil) == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
--- 334,339 ----
for (i=0; i<kTrial; i++)
{
! ret = IOBluetoothDeviceOpenL2CAPChannelSync(wiiremote->device, &(wiiremote->ichan), 19, myEventListener, (void *)wiiremote);
! if ( ret == kIOReturnSuccess)
break;
usleep(10000); // wait 10ms
***************
*** 336,350 ****
if (i==kTrial)
{
! gWiiRemote.ichan = nil;
! IOBluetoothL2CAPChannelCloseChannel(gWiiRemote.cchan);
! IOBluetoothDeviceCloseConnection(gWiiRemote.device);
! gWiiRemote.device = nil;
return false;
}
! wiiremote_motionsensor(true);
! wiiremote_irsensor(false);
! wiiremote_vibration(false);
! wiiremote_led(false, false, false, false);
return true;
--- 341,355 ----
if (i==kTrial)
{
! wiiremote->ichan = nil;
! IOBluetoothL2CAPChannelCloseChannel(wiiremote->cchan);
! IOBluetoothDeviceCloseConnection(wiiremote->device);
! wiiremote->device = nil;
return false;
}
! wiiremote_motionsensor(wiiremote, true);
! wiiremote_irsensor(wiiremote, false);
! wiiremote_vibration(wiiremote, false);
! wiiremote_led(wiiremote, false, false, false, false);
return true;
***************
*** 352,372 ****
! Boolean wiiremote_disconnect(void)
{
short i;
! if (gWiiRemote.disconnectNotification != nil)
{
! IOBluetoothUserNotificationUnregister(gWiiRemote.disconnectNotification);
! gWiiRemote.disconnectNotification = nil;
}
! if (gWiiRemote.cchan && IOBluetoothDeviceIsConnected(gWiiRemote.device))
{
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothL2CAPChannelCloseChannel(gWiiRemote.cchan) == kIOReturnSuccess)
{
! gWiiRemote.cchan = nil;
break;
}
--- 357,377 ----
! Boolean wiiremote_disconnect(WiiRemoteRef wiiremote)
{
short i;
! if (wiiremote->disconnectNotification != nil)
{
! IOBluetoothUserNotificationUnregister(wiiremote->disconnectNotification);
! wiiremote->disconnectNotification = nil;
}
! if (wiiremote->cchan && IOBluetoothDeviceIsConnected(wiiremote->device))
{
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothL2CAPChannelCloseChannel(wiiremote->cchan) == kIOReturnSuccess)
{
! wiiremote->cchan = nil;
break;
}
***************
*** 375,385 ****
}
! if (gWiiRemote.ichan && IOBluetoothDeviceIsConnected(gWiiRemote.device))
{
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothL2CAPChannelCloseChannel(gWiiRemote.ichan) == kIOReturnSuccess)
{
! gWiiRemote.ichan = nil;
break;
}
--- 380,390 ----
}
! if (wiiremote->ichan && IOBluetoothDeviceIsConnected(wiiremote->device))
{
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothL2CAPChannelCloseChannel(wiiremote->ichan) == kIOReturnSuccess)
{
! wiiremote->ichan = nil;
break;
}
***************
*** 388,396 ****
}
! if (gWiiRemote.device && IOBluetoothDeviceIsConnected(gWiiRemote.device))
{
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothDeviceCloseConnection(gWiiRemote.device) == kIOReturnSuccess)
{
break;
--- 393,401 ----
}
! if (wiiremote->device && IOBluetoothDeviceIsConnected(wiiremote->device))
{
for (i=0; i<kTrial; i++)
{
! if (IOBluetoothDeviceCloseConnection(wiiremote->device) == kIOReturnSuccess)
{
break;
***************
*** 400,407 ****
}
! if (gWiiRemote.device != nil)
{
! IOBluetoothObjectRelease(gWiiRemote.device);
! gWiiRemote.device = nil;
}
--- 405,412 ----
}
! if (wiiremote->device != nil)
{
! IOBluetoothObjectRelease(wiiremote->device);
! wiiremote->device = nil;
}
***************
*** 412,416 ****
//--------------------------------------------------------------------------------------------
! Boolean sendCommand(unsigned char *data, size_t length)
{
unsigned char buf[40];
--- 417,421 ----
//--------------------------------------------------------------------------------------------
! Boolean sendCommand(WiiRemoteRef wiiremote, unsigned char *data, size_t length)
{
unsigned char buf[40];
***************
*** 428,432 ****
for (i = 0; i<kTrial; i++)
{
! ret = IOBluetoothL2CAPChannelWriteSync(gWiiRemote.cchan, buf, length);
if (ret == kIOReturnSuccess)
break;
--- 433,437 ----
for (i = 0; i<kTrial; i++)
{
! ret = IOBluetoothL2CAPChannelWriteSync(wiiremote->cchan, buf, length);
if (ret == kIOReturnSuccess)
break;
***************
*** 437,444 ****
}
! Boolean writeData(const unsigned char *data, unsigned long address, size_t length)
{
unsigned char cmd[22];
! int i;
for(i=0 ; i<length ; i++) cmd[i+6] = data[i];
--- 442,449 ----
}
! Boolean writeData(WiiRemoteRef wiiremote, const unsigned char *data, unsigned long address, size_t length)
{
unsigned char cmd[22];
! unsigned int i;
for(i=0 ; i<length ; i++) cmd[i+6] = data[i];
***************
*** 454,494 ****
// and of course the vibration flag, as usual
! if (gWiiRemote.isVibrationEnabled) cmd[1] |= 0x01;
data = cmd;
! return sendCommand(cmd, 22);
}
//--------------------------------------------------------------------------------------------
! Boolean wiiremote_motionsensor(Boolean enabled)
{
! gWiiRemote.isMotionSensorEnabled = enabled;
unsigned char cmd[] = {0x12, 0x00, 0x30};
! if (gWiiRemote.isVibrationEnabled) cmd[1] |= 0x01;
! if (gWiiRemote.isMotionSensorEnabled) cmd[2] |= 0x01;
! if (gWiiRemote.isIRSensorEnabled) cmd[2] |= 0x02;
! return sendCommand(cmd, 3);
}
! Boolean wiiremote_irsensor(Boolean enabled)
{
IOReturn ret;
! gWiiRemote.isIRSensorEnabled = enabled;
// set register 0x12 (report type)
! if (ret = wiiremote_motionsensor(gWiiRemote.isMotionSensorEnabled)) return ret;
// set register 0x13 (ir enable/vibe)
! if (ret = wiiremote_vibration(gWiiRemote.isVibrationEnabled)) return ret;
// set register 0x1a (ir enable 2)
unsigned char cmd[] = {0x1a, 0x00};
if (enabled) cmd[1] |= 0x04;
! if (ret = sendCommand(cmd, 2)) return ret;
if(enabled){
--- 459,499 ----
// and of course the vibration flag, as usual
! if (wiiremote->isVibrationEnabled) cmd[1] |= 0x01;
data = cmd;
! return sendCommand(wiiremote, cmd, 22);
}
//--------------------------------------------------------------------------------------------
! Boolean wiiremote_motionsensor(WiiRemoteRef wiiremote, Boolean enabled)
{
! wiiremote->isMotionSensorEnabled = enabled;
unsigned char cmd[] = {0x12, 0x00, 0x30};
! if (wiiremote->isVibrationEnabled) cmd[1] |= 0x01;
! if (wiiremote->isMotionSensorEnabled) cmd[2] |= 0x01;
! if (wiiremote->isIRSensorEnabled) cmd[2] |= 0x02;
! return sendCommand(wiiremote, cmd, 3);
}
! Boolean wiiremote_irsensor(WiiRemoteRef wiiremote, Boolean enabled)
{
IOReturn ret;
! wiiremote->isIRSensorEnabled = enabled;
// set register 0x12 (report type)
! if (ret = wiiremote_motionsensor(wiiremote, wiiremote->isMotionSensorEnabled) == false) return ret;
// set register 0x13 (ir enable/vibe)
! if (ret = wiiremote_vibration(wiiremote, wiiremote->isVibrationEnabled) == false) return ret;
// set register 0x1a (ir enable 2)
unsigned char cmd[] = {0x1a, 0x00};
if (enabled) cmd[1] |= 0x04;
! if (ret = sendCommand(wiiremote, cmd, 2) == false) return ret;
if(enabled){
***************
*** 498,514 ****
// the sleeps help it it seems
usleep(10000);
! if (ret = writeData((darr){0x01}, 0x04B00030, 1)) return ret;
usleep(10000);
! if (ret = writeData((darr){0x08}, 0x04B00030, 1)) return ret;
usleep(10000);
! if (ret = writeData((darr){0x90}, 0x04B00006, 1)) return ret;
usleep(10000);
! if (ret = writeData((darr){0xC0}, 0x04B00008, 1)) return ret;
usleep(10000);
! if (ret = writeData((darr){0x40}, 0x04B0001A, 1)) return ret;
usleep(10000);
! if (ret = writeData((darr){0x33}, 0x04B00033, 1)) return ret;
usleep(10000);
! if (ret = writeData((darr){0x08}, 0x04B00030, 1)) return ret;
}else{
--- 503,519 ----
// the sleeps help it it seems
usleep(10000);
! if (ret = writeData(wiiremote, (darr){0x01}, 0x04B00030, 1) == false) return ret;
usleep(10000);
! if (ret = writeData(wiiremote, (darr){0x08}, 0x04B00030, 1) == false) return ret;
usleep(10000);
! if (ret = writeData(wiiremote, (darr){0x90}, 0x04B00006, 1) == false) return ret;
usleep(10000);
! if (ret = writeData(wiiremote, (darr){0xC0}, 0x04B00008, 1) == false) return ret;
usleep(10000);
! if (ret = writeData(wiiremote, (darr){0x40}, 0x04B0001A, 1) == false) return ret;
usleep(10000);
! if (ret = writeData(wiiremote, (darr){0x33}, 0x04B00033, 1) == false) return ret;
usleep(10000);
! if (ret = writeData(wiiremote, (darr){0x08}, 0x04B00030, 1) == false) return ret;
}else{
***************
*** 517,522 ****
//bug fix #1614587
! wiiremote_motionsensor(gWiiRemote.isMotionSensorEnabled);
! wiiremote_vibration(gWiiRemote.isVibrationEnabled);
}
--- 522,527 ----
//bug fix #1614587
! wiiremote_motionsensor(wiiremote, wiiremote->isMotionSensorEnabled);
! wiiremote_vibration(wiiremote, wiiremote->isVibrationEnabled);
}
***************
*** 524,543 ****
}
! Boolean wiiremote_vibration(Boolean enabled)
{
! gWiiRemote.isVibrationEnabled = enabled;
unsigned char cmd[] = {0x13, 0x00};
! if (gWiiRemote.isVibrationEnabled) cmd[1] |= 0x01;
! if (gWiiRemote.isIRSensorEnabled) cmd[1] |= 0x04;
! return sendCommand(cmd, 2);;
}
! Boolean wiiremote_led(Boolean enabled1, Boolean enabled2, Boolean enabled3, Boolean enabled4)
{
unsigned char cmd[] = {0x11, 0x00};
! if (gWiiRemote.isVibrationEnabled) cmd[1] |= 0x01;
if (enabled1) cmd[1] |= 0x10;
if (enabled2) cmd[1] |= 0x20;
--- 529,548 ----
}
! Boolean wiiremote_vibration(WiiRemoteRef wiiremote, Boolean enabled)
{
! wiiremote->isVibrationEnabled = enabled;
unsigned char cmd[] = {0x13, 0x00};
! if (wiiremote->isVibrationEnabled) cmd[1] |= 0x01;
! if (wiiremote->isIRSensorEnabled) cmd[1] |= 0x04;
! return sendCommand(wiiremote, cmd, 2);;
}
! Boolean wiiremote_led(WiiRemoteRef wiiremote, Boolean enabled1, Boolean enabled2, Boolean enabled3, Boolean enabled4)
{
unsigned char cmd[] = {0x11, 0x00};
! if (wiiremote->isVibrationEnabled) cmd[1] |= 0x01;
if (enabled1) cmd[1] |= 0x10;
if (enabled2) cmd[1] |= 0x20;
***************
*** 545,560 ****
if (enabled4) cmd[1] |= 0x80;
! gWiiRemote.isLED1Illuminated = enabled1;
! gWiiRemote.isLED2Illuminated = enabled2;
! gWiiRemote.isLED3Illuminated = enabled3;
! gWiiRemote.isLED4Illuminated = enabled4;
! return sendCommand(cmd, 2);
}
! void wiiremote_getstatus(void)
{
unsigned char cmd[] = {0x15, 0x00};
! sendCommand(cmd, 2);
}
--- 550,565 ----
if (enabled4) cmd[1] |= 0x80;
! wiiremote->isLED1Illuminated = enabled1;
! wiiremote->isLED2Illuminated = enabled2;
! wiiremote->isLED3Illuminated = enabled3;
! wiiremote->isLED4Illuminated = enabled4;
! return sendCommand(wiiremote, cmd, 2);
}
! Boolean wiiremote_getstatus(WiiRemoteRef wiiremote)
{
unsigned char cmd[] = {0x15, 0x00};
! return sendCommand(wiiremote, cmd, 2);
}
--- NEW FILE: aka.wiiremote_b3_pd-port.patch ---
--- /Users/hans/Documents/Research/HID/wiiremote/aka.wiiremote-b3-src/wiiremote.h 2006-12-20 05:29:31.000000000 -0500
+++ wiiremote.h 2006-12-28 01:36:00.000000000 -0500
@@ -2,8 +2,13 @@
// Copyright by Masayuki Akamatsu
// Based on "DarwiinRemote" by Hiroaki Kimura
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOBluetooth/Bluetooth.h>
#include <IOBluetooth/IOBluetoothUserLib.h>
+#include <stdio.h>
+#include <string.h>
+
typedef struct {
int x, y, s;
} IRData;
--- /Users/hans/Documents/Research/HID/wiiremote/aka.wiiremote-b3-src/aka.wiiremote.c 2006-12-20 06:09:10.000000000 -0500
+++ aka.wiiremote.c 2006-12-28 17:47:08.000000000 -0500
@@ -4,15 +4,28 @@
// 1.0B2 : 2006.12.15
// 1.0B3 : 2006.12.20
+#ifdef PD
+#include "m_pd.h"
+#define SETLONG SETFLOAT
+static t_class *wiiremote_class;
+#else /* Max */
#include "ext.h"
+#endif /* PD */
+
#include "wiiremote.h"
+#include <stdio.h>
+
#define kInterval 100
#define kMaxTrial 100
typedef struct _akawiiremote
{
+#ifdef PD
+ t_object x_obj;
+#else /* Max */
struct object obj;
+#endif
WiiRemoteRef wiiremote;
@@ -47,7 +60,11 @@
void *akawiiremote_new(t_symbol *s, short ac, t_atom *av);
void akawiiremote_free(t_akawiiremote *x);
+#ifdef PD
+void wiiremote_setup()
+#else /* Max */
void main()
+#endif /* PD */
{
NumVersion outSoftwareVersion;
BluetoothHCIVersionInfo outHardwareVersion;
@@ -66,6 +83,32 @@
return;
}
+ post("aka.wiiremote 1.0B3-UB by Masayuki Akamatsu");
+
+#ifdef PD
+ post("\tPd port by Hans-Christoph Steiner");
+
+ wiiremote_class = class_new(gensym("wiiremote"),
+ (t_newmethod)akawiiremote_new,
+ (t_method)akawiiremote_free,
+ sizeof(t_akawiiremote),
+ CLASS_DEFAULT,
+ A_GIMME,0);
+
+ class_addbang(wiiremote_class,(t_method)akawiiremote_bang);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_connect,gensym("connect"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_disconnect,gensym("disconnect"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_motionsensor,gensym("motionsensor"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_irsensor,gensym("irsensor"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_vibration,gensym("vibration"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_led,gensym("led"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getbatterylevel,gensym("getbatterylevel"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getexpansionstatus,gensym("getexpansionstatus"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getledstatus,gensym("getledstatus"),0);
+
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_assist,gensym("assist"),A_CANT,0);
+#else /* Max */
setup((t_messlist **)&akawiiremote_class, (method)akawiiremote_new, (method)akawiiremote_free, (short)sizeof(t_akawiiremote), 0L, A_GIMME, 0);
addbang((method)akawiiremote_bang);
@@ -81,8 +124,7 @@
addmess((method)akawiiremote_getledstatus,"getledstatus",0);
addmess((method)akawiiremote_assist,"assist",A_CANT,0);
-
- post("aka.wiiremote 1.0B3-UB by Masayuki Akamatsu");
+#endif /* PD */
akawiiremote_count = 0;
}
@@ -96,7 +138,11 @@
if (x->wiiremote->device == nil)
return; // do nothing
+#ifdef PD
+ outlet_float(x->buttonsOut, (t_float) x->wiiremote->buttonData);
+#else /* Max */
outlet_int(x->buttonsOut, x->wiiremote->buttonData);
+#endif /* PD */
if (x->wiiremote->isIRSensorEnabled)
{
@@ -244,11 +290,13 @@
void akawiiremote_assist(t_akawiiremote *x, void *b, long m, long a, char *s)
{
+#ifndef PD /* Max */
if (m==ASSIST_INLET)
{
sprintf(s,"connect, bang, disconnect....");
}
else
+#endif /* NOT PD */
{
switch(a)
{
@@ -264,6 +312,19 @@
void *akawiiremote_new(t_symbol *s, short ac, t_atom *av)
{
+#ifdef PD
+ t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class);
+
+ x->wiiremote = wiiremote_init();
+
+ x->clock = clock_new(x, (t_method)akawiiremote_clock);
+
+ /* create anything outlet used for HID data */
+ x->statusOut = outlet_new(&x->x_obj, 0);
+ x->buttonsOut = outlet_new(&x->x_obj, &s_float);
+ x->irOut = outlet_new(&x->x_obj, &s_list);
+ x->accOut = outlet_new(&x->x_obj, &s_list);
+#else /* Max */
t_akawiiremote *x;
x = (t_akawiiremote *)newobject(akawiiremote_class);
@@ -271,13 +332,14 @@
x->wiiremote = wiiremote_init();
x->clock = clock_new(x, (method)akawiiremote_clock);
- x->trial = 0;
- x->interval = kInterval;
x->statusOut = outlet_new(x, 0);
x->buttonsOut = intout(x);
x->irOut = listout(x);
x->accOut = listout(x);
+#endif /* PD */
+ x->trial = 0;
+ x->interval = kInterval;
akawiiremote_count++;
return x;
@@ -290,6 +352,10 @@
wiiremote_disconnect();
clock_unset(x->clock);
+#ifdef PD
+ clock_free(x->clock);
+#else /* Max */
freeobject((t_object *)x->clock);
+#endif /* PD */
}
--- NEW FILE: aka.wiiremote_b2_pd-port.patch ---
--- /Users/hans/Desktop/aka.wiiremote-b2-src/aka.wiiremote.c 2006-12-15 08:36:06.000000000 -0500
+++ aka.wiiremote.c 2006-12-16 17:05:31.000000000 -0500
@@ -1,15 +1,28 @@
// aka.wiiremote.c
// Copyright by Masayuki Akamatsu
+// port to Pd by Hans-Christoph Steiner <hans(a)at.or.at>
+
+#ifdef PD
+#include "m_pd.h"
+#define SETLONG SETFLOAT
+static t_class *wiiremote_class;
+#else /* Max */
#include "ext.h"
+#endif
#include "wiiremote.h"
#define kInterval 100
#define kMaxTrial 100
+
typedef struct _akawiiremote
{
+#ifdef PD
+ t_object x_obj;
+#else /* Max */
struct object obj;
+#endif
WiiRemoteRef wiiremote;
@@ -44,6 +57,36 @@
void *akawiiremote_new(t_symbol *s, short ac, t_atom *av);
void akawiiremote_free(t_akawiiremote *x);
+#ifdef PD
+void wiiremote_setup()
+{
+ wiiremote_class = class_new(gensym("wiiremote"),
+ (t_newmethod)akawiiremote_new,
+ (t_method)akawiiremote_free,
+ sizeof(t_akawiiremote),
+ CLASS_DEFAULT,
+ A_GIMME,0);
+
+ class_addbang(wiiremote_class,(t_method)akawiiremote_bang);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_connect,gensym("connect"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_disconnect,gensym("disconnect"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_motionsensor,gensym("motionsensor"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_irsensor,gensym("irsensor"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_vibration,gensym("vibration"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_led,gensym("led"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getbatterylevel,gensym("getbatterylevel"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getexpansionstatus,gensym("getexpansionstatus"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getledstatus,gensym("getledstatus"),0);
+
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_assist,gensym("assist"),A_CANT,0);
+
+ post("aka.wiiremote 1.0B2-UB by Masayuki Akamatsu");
+ post("\tPd port by Hans-Christoph Steiner");
+
+ akawiiremote_count = 0;
+}
+#else /* Max */
void main()
{
setup((t_messlist **)&akawiiremote_class, (method)akawiiremote_new, (method)akawiiremote_free, (short)sizeof(t_akawiiremote), 0L, A_GIMME, 0);
@@ -66,7 +109,7 @@
akawiiremote_count = 0;
}
-
+#endif /* PD */
//--------------------------------------------------------------------------------------------
void akawiiremote_bang(t_akawiiremote *x)
@@ -76,6 +119,27 @@
if (x->wiiremote->device == nil)
return; // do nothing
+#ifdef PD
+ outlet_float(x->buttonsOut, (t_float) x->wiiremote->buttonData);
+
+ if (x->wiiremote->isIRSensorEnabled)
+ {
+ SETFLOAT(list, x->wiiremote->posX);
+ SETFLOAT(list + 1, x->wiiremote->posY);
+ SETFLOAT(list + 2, x->wiiremote->angle);
+ SETFLOAT (list + 3, x->wiiremote->tracking);
+ outlet_list(x->irOut, &s_list, 4, list);
+ }
+
+ if (x->wiiremote->isMotionSensorEnabled)
+ {
+ SETFLOAT(list, x->wiiremote->accX);
+ SETFLOAT(list + 1, x->wiiremote->accY);
+ SETFLOAT(list + 2, x->wiiremote->accZ);
+ SETFLOAT(list + 3, x->wiiremote->orientation);
+ outlet_list(x->accOut, &s_list, 4, list);
+ }
+#else /* Max */
outlet_int(x->buttonsOut, x->wiiremote->buttonData);
if (x->wiiremote->isIRSensorEnabled)
@@ -95,6 +159,7 @@
SETLONG(list + 3, x->wiiremote->orientation);
outlet_list(x->accOut, 0L, 4, &list);
}
+#endif /* PD */
wiiremote_getstatus();
}
@@ -173,11 +238,19 @@
{
t_atom list[4];
+#ifdef PD
+ SETFLOAT(list, x->wiiremote->isLED1Illuminated);
+ SETFLOAT(list + 1, x->wiiremote->isLED2Illuminated);
+ SETFLOAT(list + 2, x->wiiremote->isLED3Illuminated);
+ SETFLOAT(list + 3, x->wiiremote->isLED4Illuminated);
+ outlet_anything(x->statusOut, gensym("ledstatus"), 4, list);
+#else /* Max */
SETLONG(list, x->wiiremote->isLED1Illuminated);
SETLONG(list + 1, x->wiiremote->isLED2Illuminated);
SETLONG(list + 2, x->wiiremote->isLED3Illuminated);
SETLONG(list + 3, x->wiiremote->isLED4Illuminated);
outlet_anything(x->statusOut, gensym("ledstatus"), 4, &list);
+#endif
}
//--------------------------------------------------------------------------------------------
@@ -222,11 +295,13 @@
void akawiiremote_assist(t_akawiiremote *x, void *b, long m, long a, char *s)
{
+#ifndef PD /* Max */
if (m==ASSIST_INLET)
{
sprintf(s,"connect, bang, disconnect....");
}
else
+#endif /* NOT PD */
{
switch(a)
{
@@ -242,6 +317,17 @@
void *akawiiremote_new(t_symbol *s, short ac, t_atom *av)
{
+#ifdef PD
+ t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class);
+
+ x->clock = clock_new(x, (t_method)akawiiremote_clock);
+
+ /* create anything outlet used for HID data */
+ x->statusOut = outlet_new(&x->x_obj, 0);
+ x->buttonsOut = outlet_new(&x->x_obj, &s_float);
+ x->irOut = outlet_new(&x->x_obj, &s_list);
+ x->accOut = outlet_new(&x->x_obj, &s_list);
+#else /* Max */
t_akawiiremote *x;
x = (t_akawiiremote *)newobject(akawiiremote_class);
@@ -249,13 +335,15 @@
x->wiiremote = wiiremote_init();
x->clock = clock_new(x, (method)akawiiremote_clock);
- x->trial = 0;
- x->interval = kInterval;
x->statusOut = outlet_new(x, 0);
x->buttonsOut = intout(x);
x->irOut = listout(x);
x->accOut = listout(x);
+#endif /* PD */
+ x->trial = 0;
+ x->interval = kInterval;
+
akawiiremote_count++;
return x;
@@ -267,6 +355,12 @@
if (akawiiremote_count == 0)
wiiremote_disconnect();
+#ifdef PD
+ if (x->clock)
+ clock_unset(x->clock);
+ clock_free(x->clock);
+#else /* Max */
freeobject(x->clock);
+#endif
}
--- /Users/hans/Desktop/aka.wiiremote-b2-src/wiiremote.h 2006-12-14 10:21:42.000000000 -0500
+++ wiiremote.h 2006-12-16 16:48:38.000000000 -0500
@@ -2,9 +2,13 @@
// Copyright by Masayuki Akamatsu
// Based on "DarwiinRemote" by Hiroaki Kimura
+#include <CoreFoundation/CoreFoundation.h>
#include <IOBluetooth/Bluetooth.h>
#include <IOBluetooth/IOBluetoothUserLib.h>
+#include <stdio.h>
+#include <string.h>
+
typedef struct {
int x, y, s;
} IRData;
--- /Users/hans/Desktop/aka.wiiremote-b2-src/wiiremote.c 2006-12-15 08:31:05.000000000 -0500
+++ wiiremote.c 2006-12-16 17:12:14.000000000 -0500
@@ -4,6 +4,8 @@
#include "wiiremote.h"
+#include <unistd.h>
+
// this type is used a lot (data array):
typedef unsigned char darr[];
Index: aka.wiiremote.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/wiiremote/aka.wiiremote.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** aka.wiiremote.c 28 Dec 2006 22:57:22 -0000 1.4
--- aka.wiiremote.c 28 Dec 2006 23:16:03 -0000 1.5
***************
*** 14,18 ****
#include "wiiremote.h"
-
#include <stdio.h>
--- 14,17 ----
***************
*** 42,47 ****
void *akawiiremote_class; // the number of instance of this object
- short akawiiremote_count;
-
void akawiiremote_bang(t_akawiiremote *x);
void akawiiremote_connect(t_akawiiremote *x);
--- 41,44 ----
***************
*** 84,88 ****
}
! post("aka.wiiremote 1.0B3-UB by Masayuki Akamatsu");
#ifdef PD
--- 81,85 ----
}
! post("aka.wiiremote 1.0B4-UB by Masayuki Akamatsu");
#ifdef PD
***************
*** 126,131 ****
addmess((method)akawiiremote_assist,"assist",A_CANT,0);
#endif /* PD */
-
- akawiiremote_count = 0;
}
--- 123,126 ----
***************
*** 171,175 ****
Boolean result;
! if (wiiremote_isconnected())
{
SETLONG(&status, -1);
--- 166,170 ----
Boolean result;
! if (wiiremote_isconnected(x->wiiremote))
{
SETLONG(&status, -1);
***************
*** 178,182 ****
else
{
! result = wiiremote_search(); // start searching the device
x->trial = 0;
clock_unset(x->clock); // stop clock
--- 173,177 ----
else
{
! result = wiiremote_search(x->wiiremote); // start searching the device
x->trial = 0;
clock_unset(x->clock); // stop clock
***************
*** 194,198 ****
t_atom status;
! result = wiiremote_disconnect();
SETLONG(&status, result);
outlet_anything(x->statusOut, gensym("disconnect"), 1, &status);
--- 189,193 ----
t_atom status;
! result = wiiremote_disconnect(x->wiiremote);
SETLONG(&status, result);
outlet_anything(x->statusOut, gensym("disconnect"), 1, &status);
***************
*** 201,220 ****
void akawiiremote_motionsensor(t_akawiiremote *x, long enable)
{
! wiiremote_motionsensor(enable);
}
void akawiiremote_irsensor(t_akawiiremote *x, long enable)
{
! wiiremote_irsensor(enable);
}
void akawiiremote_vibration(t_akawiiremote *x, long enable)
{
! wiiremote_vibration(enable);
}
void akawiiremote_led(t_akawiiremote *x, long enable1, long enable2, long enable3, long enable4)
{
! wiiremote_led(enable1, enable2, enable3, enable4);
}
--- 196,215 ----
void akawiiremote_motionsensor(t_akawiiremote *x, long enable)
{
! wiiremote_motionsensor(x->wiiremote, enable);
}
void akawiiremote_irsensor(t_akawiiremote *x, long enable)
{
! wiiremote_irsensor(x->wiiremote, enable);
}
void akawiiremote_vibration(t_akawiiremote *x, long enable)
{
! wiiremote_vibration(x->wiiremote, enable);
}
void akawiiremote_led(t_akawiiremote *x, long enable1, long enable2, long enable3, long enable4)
{
! wiiremote_led(x->wiiremote, enable1, enable2, enable3, enable4);
}
***************
*** 252,265 ****
void akawiiremote_clock(t_akawiiremote *x)
{
! Boolean result;
t_atom status;
! if (wiiremote_isconnected()) // if the device is connected...
{
clock_unset(x->clock); // stop clock
! wiiremote_stopsearch();
//result = wiiremote_connect(); // remove in B3
! wiiremote_getstatus(); // add in B3
SETLONG(&status, 1);
outlet_anything(x->statusOut, gensym("connect"), 1, &status);
--- 247,260 ----
void akawiiremote_clock(t_akawiiremote *x)
{
! //Boolean result;
t_atom status;
! if (wiiremote_isconnected(x->wiiremote)) // if the device is connected...
{
clock_unset(x->clock); // stop clock
! wiiremote_stopsearch(x->wiiremote);
//result = wiiremote_connect(); // remove in B3
! wiiremote_getstatus(x->wiiremote); // add in B3
SETLONG(&status, 1);
outlet_anything(x->statusOut, gensym("connect"), 1, &status);
***************
*** 275,279 ****
clock_unset(x->clock); // stop clock
! wiiremote_stopsearch();
SETLONG(&status, 0);
outlet_anything(x->statusOut, gensym("connect"), 1, &status);
--- 270,274 ----
clock_unset(x->clock); // stop clock
! wiiremote_stopsearch(x->wiiremote);
SETLONG(&status, 0);
outlet_anything(x->statusOut, gensym("connect"), 1, &status);
***************
*** 316,320 ****
t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class);
! x->wiiremote = wiiremote_init();
x->clock = clock_new(x, (t_method)akawiiremote_clock);
--- 311,316 ----
t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class);
! if (x->wiiremote != nil)
! wiiremote_init(x->wiiremote);
x->clock = clock_new(x, (t_method)akawiiremote_clock);
***************
*** 330,334 ****
x = (t_akawiiremote *)newobject(akawiiremote_class);
! x->wiiremote = wiiremote_init();
x->clock = clock_new(x, (method)akawiiremote_clock);
--- 326,332 ----
x = (t_akawiiremote *)newobject(akawiiremote_class);
! x->wiiremote = (WiiRemoteRef)getbytes(sizeof(WiiRemoteRec)); // add in 1.0B4
! if (x->wiiremote != nil)
! wiiremote_init(x->wiiremote);
x->clock = clock_new(x, (method)akawiiremote_clock);
***************
*** 342,346 ****
x->interval = kInterval;
- akawiiremote_count++;
return x;
}
--- 340,343 ----
***************
*** 348,354 ****
void akawiiremote_free(t_akawiiremote *x)
{
! akawiiremote_count--;
! if (akawiiremote_count == 0)
! wiiremote_disconnect();
clock_unset(x->clock);
--- 345,353 ----
void akawiiremote_free(t_akawiiremote *x)
{
! if (x->wiiremote != nil) // add in 1.0B4
! {
! wiiremote_disconnect(x->wiiremote);
! freebytes(x->wiiremote, sizeof(WiiRemoteRec)); // add in 1.0B4
! }
clock_unset(x->clock);
--- NEW FILE: aka.wiiremote_b4_pd-port.patch ---
--- /Users/hans/Documents/Research/HID/wiiremote/aka.wiiremote-b4-src/wiiremote.c 2006-12-23 09:52:07.000000000 -0500
+++ wiiremote.c 2006-12-28 18:11:52.000000000 -0500
@@ -444,7 +444,7 @@
Boolean writeData(WiiRemoteRef wiiremote, const unsigned char *data, unsigned long address, size_t length)
{
unsigned char cmd[22];
- int i;
+ unsigned int i;
for(i=0 ; i<length ; i++) cmd[i+6] = data[i];
--- /Users/hans/Documents/Research/HID/wiiremote/aka.wiiremote-b4-src/wiiremote.h 2006-12-22 10:39:45.000000000 -0500
+++ wiiremote.h 2006-12-28 18:10:04.000000000 -0500
@@ -2,7 +2,11 @@
// Copyright by Masayuki Akamatsu
// Based on "DarwiinRemote" by Hiroaki Kimura
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOBluetooth/Bluetooth.h>
#include <IOBluetooth/IOBluetoothUserLib.h>
+#include <stdio.h>
+#include <string.h>
typedef struct {
int x, y, s;
--- /Users/hans/Documents/Research/HID/wiiremote/aka.wiiremote-b4-src/aka.wiiremote.c 2006-12-22 19:18:31.000000000 -0500
+++ aka.wiiremote.c 2006-12-28 18:09:23.000000000 -0500
@@ -4,15 +4,27 @@
// 1.0B2 : 2006.12.15
// 1.0B3 : 2006.12.20
+#ifdef PD
+#include "m_pd.h"
+#define SETLONG SETFLOAT
+static t_class *wiiremote_class;
+#else /* Max */
#include "ext.h"
+#endif /* PD */
+
#include "wiiremote.h"
+#include <stdio.h>
#define kInterval 100
#define kMaxTrial 100
typedef struct _akawiiremote
{
+#ifdef PD
+ t_object x_obj;
+#else /* Max */
struct object obj;
+#endif
WiiRemoteRef wiiremote;
@@ -45,7 +57,11 @@
void *akawiiremote_new(t_symbol *s, short ac, t_atom *av);
void akawiiremote_free(t_akawiiremote *x);
+#ifdef PD
+void wiiremote_setup()
+#else /* Max */
void main()
+#endif /* PD */
{
NumVersion outSoftwareVersion;
BluetoothHCIVersionInfo outHardwareVersion;
@@ -64,6 +80,32 @@
return;
}
+ post("aka.wiiremote 1.0B4-UB by Masayuki Akamatsu");
+
+#ifdef PD
+ post("\tPd port by Hans-Christoph Steiner");
+
+ wiiremote_class = class_new(gensym("wiiremote"),
+ (t_newmethod)akawiiremote_new,
+ (t_method)akawiiremote_free,
+ sizeof(t_akawiiremote),
+ CLASS_DEFAULT,
+ A_GIMME,0);
+
+ class_addbang(wiiremote_class,(t_method)akawiiremote_bang);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_connect,gensym("connect"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_disconnect,gensym("disconnect"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_motionsensor,gensym("motionsensor"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_irsensor,gensym("irsensor"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_vibration,gensym("vibration"), A_DEFFLOAT, 0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_led,gensym("led"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getbatterylevel,gensym("getbatterylevel"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getexpansionstatus,gensym("getexpansionstatus"),0);
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_getledstatus,gensym("getledstatus"),0);
+
+ class_addmethod(wiiremote_class,(t_method)akawiiremote_assist,gensym("assist"),A_CANT,0);
+#else /* Max */
setup((t_messlist **)&akawiiremote_class, (method)akawiiremote_new, (method)akawiiremote_free, (short)sizeof(t_akawiiremote), 0L, A_GIMME, 0);
addbang((method)akawiiremote_bang);
@@ -79,9 +121,7 @@
addmess((method)akawiiremote_getledstatus,"getledstatus",0);
addmess((method)akawiiremote_assist,"assist",A_CANT,0);
-
- post("aka.wiiremote 1.0B4-UB by Masayuki Akamatsu");
-
+#endif /* PD */
}
//--------------------------------------------------------------------------------------------
@@ -93,7 +133,11 @@
if (x->wiiremote->device == nil)
return; // do nothing
+#ifdef PD
+ outlet_float(x->buttonsOut, (t_float) x->wiiremote->buttonData);
+#else /* Max */
outlet_int(x->buttonsOut, x->wiiremote->buttonData);
+#endif /* PD */
if (x->wiiremote->isIRSensorEnabled)
{
@@ -241,11 +285,13 @@
void akawiiremote_assist(t_akawiiremote *x, void *b, long m, long a, char *s)
{
+#ifndef PD /* Max */
if (m==ASSIST_INLET)
{
sprintf(s,"connect, bang, disconnect....");
}
else
+#endif /* NOT PD */
{
switch(a)
{
@@ -261,6 +307,20 @@
void *akawiiremote_new(t_symbol *s, short ac, t_atom *av)
{
+#ifdef PD
+ t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class);
+
+ if (x->wiiremote != nil)
+ wiiremote_init(x->wiiremote);
+
+ x->clock = clock_new(x, (t_method)akawiiremote_clock);
+
+ /* create anything outlet used for HID data */
+ x->statusOut = outlet_new(&x->x_obj, 0);
+ x->buttonsOut = outlet_new(&x->x_obj, &s_float);
+ x->irOut = outlet_new(&x->x_obj, &s_list);
+ x->accOut = outlet_new(&x->x_obj, &s_list);
+#else /* Max */
t_akawiiremote *x;
x = (t_akawiiremote *)newobject(akawiiremote_class);
@@ -270,13 +330,14 @@
wiiremote_init(x->wiiremote);
x->clock = clock_new(x, (method)akawiiremote_clock);
- x->trial = 0;
- x->interval = kInterval;
x->statusOut = outlet_new(x, 0);
x->buttonsOut = intout(x);
x->irOut = listout(x);
x->accOut = listout(x);
+#endif /* PD */
+ x->trial = 0;
+ x->interval = kInterval;
return x;
}
@@ -290,6 +351,10 @@
}
clock_unset(x->clock);
+#ifdef PD
+ clock_free(x->clock);
+#else /* Max */
freeobject((t_object *)x->clock);
+#endif /* PD */
}