[PD-cvs] SF.net SVN: pure-data:[10206] trunk/externals/io/aka.wiiremote

eighthave at users.sourceforge.net eighthave at users.sourceforge.net
Tue Jul 22 17:23:12 CEST 2008


Revision: 10206
          http://pure-data.svn.sourceforge.net/pure-data/?rev=10206&view=rev
Author:   eighthave
Date:     2008-07-22 15:23:12 +0000 (Tue, 22 Jul 2008)

Log Message:
-----------
first working version, bangs now get udpated data properly, but the various
other messages don't work, like [motion $1(, [ir $1(, etc.

To get it working, I used CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true),
which runs the CFRunLoop until just one event has been processed.

Modified Paths:
--------------
    trunk/externals/io/aka.wiiremote/aka.wiiremote.c
    trunk/externals/io/aka.wiiremote/akawiiremote-help.pd
    trunk/externals/io/aka.wiiremote/wiiremote.c

Modified: trunk/externals/io/aka.wiiremote/aka.wiiremote.c
===================================================================
--- trunk/externals/io/aka.wiiremote/aka.wiiremote.c	2008-07-22 15:04:33 UTC (rev 10205)
+++ trunk/externals/io/aka.wiiremote/aka.wiiremote.c	2008-07-22 15:23:12 UTC (rev 10206)
@@ -10,6 +10,7 @@
 
 #ifdef PD
 #include "m_pd.h"
+#include "m_imp.h"
 #define SETSYM SETSYMBOL
 #define SETLONG SETFLOAT
 #define method t_method
@@ -48,12 +49,6 @@
 	void			*dataOut;
 } t_akawiiremote;
 
-#ifdef PD
-static IONotificationPortRef  gNotifyPort;
-static io_iterator_t          gAddedIter;
-static CFRunLoopRef           gRunLoop;
-#endif
-
 void akawiiremote_bang(t_akawiiremote *x);
 void akawiiremote_address(t_akawiiremote *x, t_symbol *s);
 void akawiiremote_connect(t_akawiiremote *x);
@@ -165,7 +160,9 @@
 	
 	if (x->wiiremote->device == nil)
 		return;	// do nothing
-
+#ifdef PD
+    CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
+#endif
 	if (x->wiiremote->isExpansionPortAttached && x->wiiremote->isExpansionPortEnabled)
 	{
 		// Classic Controller
@@ -544,6 +541,9 @@
 	
 	if (x->connected == false && connection == true)	// if the device is connected...
 	{
+#ifdef PD
+		CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
+#endif
 		wiiremote_getstatus(x->wiiremote);
 		x->connected = true;
 		SETLONG(&status, 1);
@@ -595,24 +595,6 @@
     first_argument = atom_getsymbolarg(0, ac, av);
     if(first_argument != &s_) 
         atom_string(av, x->address, MAXPDSTRING-1);
-
-    IOReturn result = kIOReturnSuccess;
-    mach_port_t masterPort = (mach_port_t) NULL;
-    result = IOMasterPort (bootstrap_port, &masterPort);
-    if (kIOReturnSuccess != result)
-        pd_error(x, "[akawiiremote] IOMasterPort error with bootstrap_port, error %d", result);
-    else
-    {
-		// Create a notification port and add its run loop event source to our run loop
-		// This is how async notifications get set up.
-        CFRunLoopSourceRef		runLoopSource;
-        
-        gNotifyPort = IONotificationPortCreate(masterPort);
-        runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort);
-
-        gRunLoop = CFRunLoopGetCurrent();
-        CFRunLoopAddSource(gRunLoop, runLoopSource, kCFRunLoopDefaultMode);
-    }
 #else /* Max */	
 	t_akawiiremote *x;
 	

Modified: trunk/externals/io/aka.wiiremote/akawiiremote-help.pd
===================================================================
--- trunk/externals/io/aka.wiiremote/akawiiremote-help.pd	2008-07-22 15:04:33 UTC (rev 10205)
+++ trunk/externals/io/aka.wiiremote/akawiiremote-help.pd	2008-07-22 15:23:12 UTC (rev 10206)
@@ -50,6 +50,7 @@
 #X obj 632 408 pddp/dsp;
 #X obj 640 500 osc~ 100;
 #X obj 303 388 akawiiremote;
+#X obj 334 589 print;
 #X connect 0 0 34 0;
 #X connect 1 0 34 0;
 #X connect 2 0 22 0;
@@ -63,6 +64,7 @@
 #X connect 15 0 34 0;
 #X connect 16 0 34 0;
 #X connect 19 0 12 0;
+#X connect 19 0 35 0;
 #X connect 19 1 11 0;
 #X connect 19 2 20 0;
 #X connect 21 0 34 0;

Modified: trunk/externals/io/aka.wiiremote/wiiremote.c
===================================================================
--- trunk/externals/io/aka.wiiremote/wiiremote.c	2008-07-22 15:04:33 UTC (rev 10205)
+++ trunk/externals/io/aka.wiiremote/wiiremote.c	2008-07-22 15:23:12 UTC (rev 10206)
@@ -19,6 +19,7 @@
 Boolean	requestUpdates(WiiRemoteRef wiiremote);
 void myEventListener(IOBluetoothL2CAPChannelRef channel, void *refCon, IOBluetoothL2CAPChannelEvent *event);
 
+#define DEBUG(x)
 
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
@@ -73,6 +74,7 @@
 
 Boolean	openCChan(WiiRemoteRef wiiremote)
 {
+    DEBUG(post("openCChan"););
 	short		i;
 	IOReturn	ret;
 	
@@ -97,6 +99,7 @@
 
 Boolean	openIChan(WiiRemoteRef wiiremote)
 {
+    DEBUG(post("openCChan"););
 	short		i;
 	IOReturn	ret;
 	
@@ -208,7 +211,7 @@
 
 void checkDevice(WiiRemoteRef wiiremote, IOBluetoothDeviceRef device)
 {
-    post("checkDevice");
+    DEBUG(post("checkDevice"););
 	CFStringRef	name;
 	CFStringRef	address;
 
@@ -234,20 +237,21 @@
 
 void myFoundFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device)
 {
-    post("myFoundFunc");
+    DEBUG(post("myFoundFunc"););
 	checkDevice((WiiRemoteRef)refCon, device);
 }
 
 void myUpdatedFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device, uint32_t devicesRemaining)
 {
-    post("myUpdatedFunc");
+    DEBUG(post("myUpdatedFunc"););
 
 	checkDevice((WiiRemoteRef)refCon, device);
 }
 
 void myCompleteFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOReturn error, Boolean aborted)
 {
-    post("myCompleteFunc");
+    IOReturn        ret;
+    DEBUG(post("myCompleteFunc"););
 
 	if (aborted) return; // called by stop ;)
 	
@@ -256,8 +260,15 @@
 		wiiremote_stopsearch((WiiRemoteRef)refCon);
 		return;
 	}
+/*  
+    ret = IOBluetoothDeviceInquiryStart(((WiiRemoteRef)refCon)->inquiry);
+    if (ret != kIOReturnSuccess)
+    {
+        wiiremote_stopsearch((WiiRemoteRef)refCon);
+    }
+*/
 #ifdef PD
-    // PD doesn't use the Carbon loop, so we have to manually control it
+    // PD doesn't use a CFRunLoop, so we have to manually control it
     CFRunLoopStop( CFRunLoopGetCurrent() );
 #endif
 }
@@ -274,7 +285,7 @@
 	
 Boolean wiiremote_search(WiiRemoteRef wiiremote, char *address)
 {
-    post("wiiremote_search");
+    DEBUG(post("wiiremote_search"););
 	IOReturn	ret;
 	
 	if (wiiremote->inquiry != nil)
@@ -297,14 +308,14 @@
 		return false;
 	}
 #ifdef PD
-    CFRunLoopRun(); // PD doesn't use the Carbon loop, so we have to manually control it
+    // PD doesn't use a CFRunLoop, so we have to manually control it
+    CFRunLoopRun();
 #endif
 	return true;
 }
 
 Boolean wiiremote_stopsearch(WiiRemoteRef wiiremote)
 {
-    post("wiiremote_stopsearch");
 	IOReturn	ret;
 
 	if (wiiremote->inquiry == nil)
@@ -703,6 +714,7 @@
 
  void myDataListener(IOBluetoothL2CAPChannelRef channel, void *dataPointer, UInt16 dataLength, void *refCon)
 {
+    DEBUG(post("myDataListener"););
 	WiiRemoteRef	wiiremote = (WiiRemoteRef)refCon;
 	unsigned char* dp = (unsigned char*)dataPointer;
 
@@ -738,6 +750,7 @@
 
 void myEventListener(IOBluetoothL2CAPChannelRef channel, void *refCon, IOBluetoothL2CAPChannelEvent *event)
 {
+    DEBUG(post("myEventListener"););
 	if (event->eventType == kIOBluetoothL2CAPChannelEventTypeData)
 	{
 		// In thise case:
@@ -846,7 +859,7 @@
 
 Boolean wiiremote_disconnect(WiiRemoteRef wiiremote)
 {
-	short	i = 0;	
+	short	i;	
 
 	if (wiiremote->cchan)
 	{


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Pd-cvs mailing list