From 25dcbfc009a7fbf95a4e2e8788a5cf68d2cdd7b1 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 22 Jul 2008 15:23:12 +0000 Subject: 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. svn path=/trunk/externals/io/; revision=10206 --- aka.wiiremote/aka.wiiremote.c | 32 +++++++------------------------- aka.wiiremote/akawiiremote-help.pd | 2 ++ aka.wiiremote/wiiremote.c | 31 ++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/aka.wiiremote/aka.wiiremote.c b/aka.wiiremote/aka.wiiremote.c index 0831f44..5834b63 100644 --- a/aka.wiiremote/aka.wiiremote.c +++ b/aka.wiiremote/aka.wiiremote.c @@ -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 @@ typedef struct _akawiiremote 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 @@ void akawiiremote_bang(t_akawiiremote *x) 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 @@ void akawiiremote_clock(t_akawiiremote *x) 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 @@ void *akawiiremote_new(t_symbol *s, short ac, t_atom *av) 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; diff --git a/aka.wiiremote/akawiiremote-help.pd b/aka.wiiremote/akawiiremote-help.pd index c3ae89a..b2e85ed 100644 --- a/aka.wiiremote/akawiiremote-help.pd +++ b/aka.wiiremote/akawiiremote-help.pd @@ -50,6 +50,7 @@ blinking once its connected; #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 @@ blinking once its connected; #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; diff --git a/aka.wiiremote/wiiremote.c b/aka.wiiremote/wiiremote.c index 481085e..92efeb0 100644 --- a/aka.wiiremote/wiiremote.c +++ b/aka.wiiremote/wiiremote.c @@ -19,6 +19,7 @@ typedef unsigned char darr[]; Boolean requestUpdates(WiiRemoteRef wiiremote); void myEventListener(IOBluetoothL2CAPChannelRef channel, void *refCon, IOBluetoothL2CAPChannelEvent *event); +#define DEBUG(x) //-------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------- @@ -73,6 +74,7 @@ void wiiremote_init(WiiRemoteRef wiiremote) Boolean openCChan(WiiRemoteRef wiiremote) { + DEBUG(post("openCChan");); short i; IOReturn ret; @@ -97,6 +99,7 @@ Boolean openCChan(WiiRemoteRef wiiremote) Boolean openIChan(WiiRemoteRef wiiremote) { + DEBUG(post("openCChan");); short i; IOReturn ret; @@ -208,7 +211,7 @@ Boolean readData(WiiRemoteRef wiiremote, unsigned long address, unsigned short l void checkDevice(WiiRemoteRef wiiremote, IOBluetoothDeviceRef device) { - post("checkDevice"); + DEBUG(post("checkDevice");); CFStringRef name; CFStringRef address; @@ -234,20 +237,21 @@ void checkDevice(WiiRemoteRef wiiremote, IOBluetoothDeviceRef device) 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 @@ void myCompleteFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOReturn 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_isconnected(WiiRemoteRef wiiremote) Boolean wiiremote_search(WiiRemoteRef wiiremote, char *address) { - post("wiiremote_search"); + DEBUG(post("wiiremote_search");); IOReturn ret; if (wiiremote->inquiry != nil) @@ -297,14 +308,14 @@ Boolean wiiremote_search(WiiRemoteRef wiiremote, char *address) 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 handleButtonReport(WiiRemoteRef wiiremote, unsigned char *dp, size_t dataLe 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 handleButtonReport(WiiRemoteRef wiiremote, unsigned char *dp, size_t dataLe void myEventListener(IOBluetoothL2CAPChannelRef channel, void *refCon, IOBluetoothL2CAPChannelEvent *event) { + DEBUG(post("myEventListener");); if (event->eventType == kIOBluetoothL2CAPChannelEventTypeData) { // In thise case: @@ -846,7 +859,7 @@ Boolean wiiremote_connect(WiiRemoteRef wiiremote) Boolean wiiremote_disconnect(WiiRemoteRef wiiremote) { - short i = 0; + short i; if (wiiremote->cchan) { -- cgit v1.2.1