[PD-cvs] externals/io/wiiremote README.txt, NONE, 1.1 Makefile, 1.1, 1.2 aka.wiiremote.c, 1.3, 1.4 wiiremote.c, 1.2, 1.3 wiiremote.h, 1.1, 1.2

Hans-Christoph Steiner eighthave at users.sourceforge.net
Thu Dec 28 23:57:24 CET 2006


Update of /cvsroot/pure-data/externals/io/wiiremote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26587

Modified Files:
	Makefile aka.wiiremote.c wiiremote.c wiiremote.h 
Added Files:
	README.txt 
Log Message:
ported b3 from Masayuki Akamatsu, looks complete now

Index: wiiremote.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/wiiremote/wiiremote.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** wiiremote.c	16 Dec 2006 22:25:22 -0000	1.2
--- wiiremote.c	28 Dec 2006 22:57:22 -0000	1.3
***************
*** 4,8 ****
  
  #include "wiiremote.h"
- 
  #include <unistd.h>
  
--- 4,7 ----
***************
*** 54,77 ****
  
  	myString = IOBluetoothDeviceGetName(device);
! 	if (CFStringCompare(myString, CFSTR("Nintendo RVL-CNT-01"), 0) == kCFCompareEqualTo)
  	{
! 		gWiiRemote.device = IOBluetoothObjectRetain(device);
  	}
  }
  
! IOBluetoothDeviceInquiryDeviceFoundCallback myFoundFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device)
  {
  	checkDevice(device);
  }
  
! IOBluetoothDeviceInquiryDeviceNameUpdatedCallback	myUpdatedFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device, uint32_t devicesRemaining)
  {
  	checkDevice(device);
  }
  
! IOBluetoothDeviceInquiryCompleteCallback myCompleteFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOReturn error, Boolean aborted)
  {
- 	IOReturn				result;
- 	
  	if (aborted) return; // called by stop ;)
  	
--- 53,79 ----
  
  	myString = IOBluetoothDeviceGetName(device);
! 	if (myString != nil)
  	{
! 		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
! 		}
  	}
  }
  
! void myFoundFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device)
  {
  	checkDevice(device);
  }
  
! void myUpdatedFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device, uint32_t devicesRemaining)
  {
  	checkDevice(device);
  }
  
! void myCompleteFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOReturn error, Boolean aborted)
  {
  	if (aborted) return; // called by stop ;)
  	
***************
*** 79,83 ****
  	{
  		wiiremote_stopsearch();
- 		return;
  	}
  }
--- 81,84 ----
***************
*** 85,88 ****
--- 86,97 ----
  //--------------------------------------------------------------------------------------------
  
+ Boolean wiiremote_isconnected(void)
+ {
+ 	Boolean	result;
+ 	
+ 	result = gWiiRemote.device != nil && IOBluetoothDeviceIsConnected(gWiiRemote.device);
+ 	return result;
+ }
+ 	
  Boolean wiiremote_search(void)
  {
***************
*** 132,136 ****
  //--------------------------------------------------------------------------------------------
  
!  IOBluetoothL2CAPChannelIncomingDataListener myDataListener(IOBluetoothL2CAPChannelRef channel, void *data, UInt16 length, void *refCon)
  {
  	unsigned char *dp = (unsigned char*)data;
--- 141,145 ----
  //--------------------------------------------------------------------------------------------
  
!  void myDataListener(IOBluetoothL2CAPChannelRef channel, void *data, UInt16 length, void *refCon)
  {
  	unsigned char *dp = (unsigned char*)data;
***************
*** 249,274 ****
  }
  
! IOBluetoothL2CAPChannelIncomingEventListener myEventListener(IOBluetoothL2CAPChannelRef channel, void *refCon, IOBluetoothL2CAPChannelEvent *event)
  {
! 	switch (event->eventType)
  	{
! 		case kIOBluetoothL2CAPChannelEventTypeData:
! 			// In thise case:
! 			// event->u.newData.dataPtr  is a pointer to the block of data received.
! 			// event->u.newData.dataSize is the size of the block of data.
! 			myDataListener(channel, event->u.data.dataPtr, event->u.data.dataSize, refCon);
! 			break;
! 			
! 		case kIOBluetoothL2CAPChannelEventTypeClosed:
! 			// In this case:
! 			// event->u.terminatedChannel is the channel that was terminated. It can be converted in an IOBluetoothL2CAPChannel
! 			// object with [IOBluetoothL2CAPChannel withL2CAPChannelRef:]. (see below).
! 			break;
  	}
  }
  
! IOBluetoothUserNotificationCallback myDisconnectedFunc(void * refCon, IOBluetoothUserNotificationRef inRef, IOBluetoothObjectRef objectRef)
  {
! 	wiiremote_disconnect();
  }
  
--- 258,282 ----
  }
  
! void myEventListener(IOBluetoothL2CAPChannelRef channel, void *refCon, IOBluetoothL2CAPChannelEvent *event)
  {
! 	if (event->eventType == kIOBluetoothL2CAPChannelEventTypeData)
  	{
! 		// In thise case:
! 		// event->u.newData.dataPtr  is a pointer to the block of data received.
! 		// event->u.newData.dataSize is the size of the block of data.
! 		myDataListener(channel, event->u.data.dataPtr, event->u.data.dataSize, refCon);
! 	}
! 	else
! 	if (event->eventType == kIOBluetoothL2CAPChannelEventTypeClosed)
! 	{
! 		// In this case:
! 		// event->u.terminatedChannel is the channel that was terminated. It can be converted in an IOBluetoothL2CAPChannel
! 		// object with [IOBluetoothL2CAPChannel withL2CAPChannelRef:]. (see below).
  	}
  }
  
! void myDisconnectedFunc(void * refCon, IOBluetoothUserNotificationRef inRef, IOBluetoothObjectRef objectRef)
  {
! 	//wiiremote_disconnect();
  }
  
***************
*** 277,281 ****
  Boolean wiiremote_connect(void)
  {
- 	IOReturn	result;
  	short		i;
  	
--- 285,288 ----
***************
*** 290,294 ****
  		usleep(10000); //  wait 10ms
  	}
! 	if (i==kTrial)	return false;
  	
  	gWiiRemote.disconnectNotification = IOBluetoothDeviceRegisterForDisconnectNotification(gWiiRemote.device, myDisconnectedFunc, 0);
--- 297,302 ----
  		usleep(10000); //  wait 10ms
  	}
! 	if (i==kTrial)
! 		return false;
  	
  	gWiiRemote.disconnectNotification = IOBluetoothDeviceRegisterForDisconnectNotification(gWiiRemote.device, myDisconnectedFunc, 0);
***************
*** 301,305 ****
  		usleep(10000); //  wait 10ms
  	}
! 	if (i==kTrial)	return false;
  	
  	// open L2CAPChannel : BluetoothL2CAPPSM = 17
--- 309,314 ----
  		usleep(10000); //  wait 10ms
  	}
! 	if (i==kTrial)
! 		return false;
  	
  	// open L2CAPChannel : BluetoothL2CAPPSM = 17
***************
*** 314,317 ****
--- 323,327 ----
  		gWiiRemote.cchan = nil;
  		IOBluetoothDeviceCloseConnection(gWiiRemote.device);
+ 		gWiiRemote.device = nil;
  		return false;
  	}
***************
*** 329,332 ****
--- 339,343 ----
  		IOBluetoothL2CAPChannelCloseChannel(gWiiRemote.cchan);
  		IOBluetoothDeviceCloseConnection(gWiiRemote.device);
+ 		gWiiRemote.device = nil;
  		return false;
  	}
***************
*** 383,387 ****
  			if (IOBluetoothDeviceCloseConnection(gWiiRemote.device) == kIOReturnSuccess)
  			{
- 				gWiiRemote.device = nil;
  				break;
  			}
--- 394,397 ----
***************
*** 389,393 ****
  		if (i==kTrial)	return false;
  	}
! 		
  	return true;
  }
--- 399,409 ----
  		if (i==kTrial)	return false;
  	}
! 	
! 	if (gWiiRemote.device != nil)
! 	{
! 		IOBluetoothObjectRelease(gWiiRemote.device);
! 		gWiiRemote.device = nil;
! 	}
! 	
  	return true;
  }

Index: wiiremote.h
===================================================================
RCS file: /cvsroot/pure-data/externals/io/wiiremote/wiiremote.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** wiiremote.h	16 Dec 2006 22:03:43 -0000	1.1
--- wiiremote.h	28 Dec 2006 22:57:22 -0000	1.2
***************
*** 48,55 ****
  	Boolean			isLED4Illuminated;
  	
! 	IOBluetoothUserNotificationCallback	*disconnectNotification;
  }	WiiRemoteRec, *WiiRemoteRef;
  
  WiiRemoteRef	wiiremote_init(void);
  Boolean			wiiremote_search(void);
  Boolean			wiiremote_stopsearch(void);
--- 48,56 ----
  	Boolean			isLED4Illuminated;
  	
! 	IOBluetoothUserNotificationRef	disconnectNotification;
  }	WiiRemoteRec, *WiiRemoteRef;
  
  WiiRemoteRef	wiiremote_init(void);
+ Boolean			wiiremote_isconnected(void);
  Boolean			wiiremote_search(void);
  Boolean			wiiremote_stopsearch(void);

Index: Makefile
===================================================================
RCS file: /cvsroot/pure-data/externals/io/wiiremote/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile	16 Dec 2006 22:03:43 -0000	1.1
--- Makefile	28 Dec 2006 22:57:22 -0000	1.2
***************
*** 16,27 ****
  # for emacs
  etags:
! 	etags ../../../pd/src/*.h *.[ch] linux/input.h 
  	make etags_`uname -s`
  
  etags_Darwin:
! 	etags -a HID\ Utilities\ Source/*.[ch] \
  		/System/Library/Frameworks/ForceFeedback.framework/Headers/*.h \
  		/System/Library/Frameworks/Carbon.framework/Headers/*.h  \
! 		/System/Library/Frameworks/IOKit.framework/Headers/hid*/*.[ch]
  
  etags_Linux:
--- 16,28 ----
  # for emacs
  etags:
! 	etags ../../../pd/src/*.h *.[ch]
  	make etags_`uname -s`
  
  etags_Darwin:
! 	etags -a \
  		/System/Library/Frameworks/ForceFeedback.framework/Headers/*.h \
+ 		/System/Library/Frameworks/CoreFoundation.framework/Headers/*.h \
  		/System/Library/Frameworks/Carbon.framework/Headers/*.h  \
! 		/System/Library/Frameworks/IOBluetooth.framework/Headers/*.[ch]
  
  etags_Linux:

Index: aka.wiiremote.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/wiiremote/aka.wiiremote.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** aka.wiiremote.c	17 Dec 2006 16:56:21 -0000	1.3
--- aka.wiiremote.c	28 Dec 2006 22:57:22 -0000	1.4
***************
*** 1,6 ****
  // aka.wiiremote.c
  // Copyright by Masayuki Akamatsu
! // port to Pd by Hans-Christoph Steiner <hans at at.or.at>
! 
  
  #ifdef PD
--- 1,7 ----
  // aka.wiiremote.c
  // Copyright by Masayuki Akamatsu
! // 1.0B1 : 2006.12.12
! // 1.0B2 : 2006.12.15
! // 1.0B3 : 2006.12.20
  
  #ifdef PD
***************
*** 10,20 ****
  #else /* Max */
  #include "ext.h"
! #endif
  #include "wiiremote.h"
  
  #define kInterval	100
  #define	kMaxTrial	100
  
- 
  typedef struct _akawiiremote
  {
--- 11,23 ----
  #else /* Max */
  #include "ext.h"
! #endif /* PD */
! 
  #include "wiiremote.h"
  
+ #include <stdio.h>
+ 
  #define kInterval	100
  #define	kMaxTrial	100
  
  typedef struct _akawiiremote
  {
***************
*** 30,34 ****
  	long			interval;
  	long			trial;
! 
  	void			*statusOut;
  	void			*buttonsOut;
--- 33,37 ----
  	long			interval;
  	long			trial;
! 	
  	void			*statusOut;
  	void			*buttonsOut;
***************
*** 60,64 ****
--- 63,92 ----
  #ifdef PD
  void wiiremote_setup()
+ #else /* Max */
+ void main()
+ #endif /* PD */
  {
+ 	NumVersion				outSoftwareVersion;
+ 	BluetoothHCIVersionInfo	outHardwareVersion;
+ 	
+ 	if (IOBluetoothGetVersion(&outSoftwareVersion, &outHardwareVersion)==kIOReturnSuccess)
+ 	{
+ 		if (outSoftwareVersion.majorRev < 1 || outSoftwareVersion.minorAndBugRev < 0x63)
+ 		{
+ 			error("requires Blutooth version 1.6.3 or later.");
+ 			return;
+ 		}
+ 	}
+ 	else
+ 	{
+ 		error("can't get Bluetooth version.");
+ 		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, 
***************
*** 81,93 ****
  	
  	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);
  
--- 109,113 ----
***************
*** 105,114 ****
  	
  	addmess((method)akawiiremote_assist,"assist",A_CANT,0);
! 	
! 	post("aka.wiiremote 1.0B2-UB by Masayuki Akamatsu");
  	
  	akawiiremote_count = 0;
  }
! #endif /* PD */
  //--------------------------------------------------------------------------------------------
  
--- 125,133 ----
  	
  	addmess((method)akawiiremote_assist,"assist",A_CANT,0);
! #endif /* PD */
  	
  	akawiiremote_count = 0;
  }
! 
  //--------------------------------------------------------------------------------------------
  
***************
*** 116,148 ****
  {
  	t_atom list[4]; 
! 
! 	if (x->wiiremote->device == nil) 
! 	{
! 		post("warning: your WiiRemote is not connected");
  		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)
--- 135,147 ----
  {
  	t_atom list[4]; 
! 	
! 	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)
***************
*** 152,156 ****
  		SETFLOAT(list + 2, x->wiiremote->angle);
  		SETLONG (list + 3, x->wiiremote->tracking);
! 		outlet_list(x->irOut, 0L, 4, &list); 
  	}
  
--- 151,155 ----
  		SETFLOAT(list + 2, x->wiiremote->angle);
  		SETLONG (list + 3, x->wiiremote->tracking);
! 		outlet_list(x->irOut, 0L, 4, list); 
  	}
  
***************
*** 161,193 ****
  		SETLONG(list + 2, x->wiiremote->accZ);
  		SETLONG(list + 3, x->wiiremote->orientation);
! 		outlet_list(x->accOut, 0L, 4, &list); 
  	}
- #endif /* PD */
  	
! 	wiiremote_getstatus();
  }
  
  void akawiiremote_connect(t_akawiiremote *x)
  {
! 	if (x->wiiremote->device == nil)	// if not connected
! 	{
! 		if (x->wiiremote->inquiry == nil)	// if not seatching
! 		{
! 			Boolean	result;
  
! 			result = wiiremote_search();	// start searching the device
! 			x->trial = 0;
! 			clock_delay(x->clock, 0); // start clock to check the device found
! 		}
  	}
! 	else	// if already connected
  	{
! 		t_atom	status;
! 
! 		SETLONG(&status, 1);
! 		outlet_anything(x->statusOut, gensym("connect"), 1, &status);
  	}
  }
  
  void akawiiremote_disconnect(t_akawiiremote *x)
  {
--- 160,192 ----
  		SETLONG(list + 2, x->wiiremote->accZ);
  		SETLONG(list + 3, x->wiiremote->orientation);
! 		outlet_list(x->accOut, 0L, 4, list); 
  	}
  	
! 	//wiiremote_getstatus();	// stopped in B3
  }
  
  void akawiiremote_connect(t_akawiiremote *x)
  {
! 	t_atom	status;
! 	Boolean	result;
  
! 	if (wiiremote_isconnected())
! 	{
! 		SETLONG(&status, -1);
! 		outlet_anything(x->statusOut, gensym("connect"), 1, &status);		
  	}
! 	else
  	{
! 		result = wiiremote_search();	// start searching the device
! 		x->trial = 0;
! 		clock_unset(x->clock);			// stop clock
! 		clock_delay(x->clock, 0);		// start clock to check the device found
  	}
  }
  
+ void akawiiremote_foundFunc(t_akawiiremote *x)
+ {
+ }
+ 
  void akawiiremote_disconnect(t_akawiiremote *x)
  {
***************
*** 242,258 ****
  	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
  }
  
--- 241,249 ----
  	t_atom list[4]; 
  	
  	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);		
  }
  
***************
*** 264,277 ****
  	t_atom	status;
  	
! 	if (x->wiiremote->device != nil)	// if the device is found...
  	{
  		clock_unset(x->clock);			// stop clock
  
  		wiiremote_stopsearch();
! 		result = wiiremote_connect();	// connect to it
! 		SETLONG(&status, result);
  		outlet_anything(x->statusOut, gensym("connect"), 1, &status);
  	}
! 	else	// if the device is not found...
  	{
  		x->trial++;
--- 255,269 ----
  	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);
  	}
! 	else	// if the device is not connected...
  	{
  		x->trial++;
***************
*** 335,339 ****
  #else /* Max */	
  	t_akawiiremote *x;
! 
  	x = (t_akawiiremote *)newobject(akawiiremote_class);
  	
--- 327,331 ----
  #else /* Max */	
  	t_akawiiremote *x;
! 	
  	x = (t_akawiiremote *)newobject(akawiiremote_class);
  	
***************
*** 341,345 ****
  	
  	x->clock = clock_new(x, (method)akawiiremote_clock);
! 
  	x->statusOut = outlet_new(x, 0);
  	x->buttonsOut = intout(x);
--- 333,337 ----
  	
  	x->clock = clock_new(x, (method)akawiiremote_clock);
! 	
  	x->statusOut = outlet_new(x, 0);
  	x->buttonsOut = intout(x);
***************
*** 349,353 ****
  	x->trial = 0;
  	x->interval	= kInterval;
- 	
  
  	akawiiremote_count++;
--- 341,344 ----
***************
*** 360,371 ****
  	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
  }
  
--- 351,361 ----
  	if (akawiiremote_count == 0)
  		wiiremote_disconnect();
! 	
! 	clock_unset(x->clock);
  #ifdef PD
  	clock_free(x->clock);
  #else /* Max */	
! 	freeobject((t_object *)x->clock); 
! #endif /* PD */
  }
  

--- NEW FILE: README.txt ---

This is a port of the Max class aka.wiiremote by Masayuki Akamatsu.  Its
available here:

http://www.iamas.ac.jp/~aka/max/#aka_wiiremote






More information about the Pd-cvs mailing list