diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2008-03-07 18:47:45 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 15:08:25 +0200 |
commit | 71d377c64cf05eb5726e4ec803dc8288bf4c8357 (patch) | |
tree | 24ded34ecaba61bc527365bffa23ffe86f297707 /wiiremote/wiiremote.c | |
parent | 2e3417388d79966bed87965155b3f5f485728a4a (diff) |
A first step of success, I got the wiiremote successfully connecting and getting one data event into Pd with the first bang. Now I have to figure out how to run the Carbon CFRunLoop into Pd land.
- cleaned up some unused variables
- fixed some warnings
- folded in the b7 version
- cleaned up the port a bit
This code directly compiles and works fine on Max/MSP.
svn path=/trunk/externals/io/; revision=9543
Diffstat (limited to 'wiiremote/wiiremote.c')
-rw-r--r-- | wiiremote/wiiremote.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/wiiremote/wiiremote.c b/wiiremote/wiiremote.c index 2caffb7..481085e 100644 --- a/wiiremote/wiiremote.c +++ b/wiiremote/wiiremote.c @@ -208,15 +208,16 @@ Boolean readData(WiiRemoteRef wiiremote, unsigned long address, unsigned short l void checkDevice(WiiRemoteRef wiiremote, IOBluetoothDeviceRef device) { + post("checkDevice"); CFStringRef name; CFStringRef address; - + if (wiiremote_isconnected(wiiremote)) return; name = IOBluetoothDeviceGetName(device); address = IOBluetoothDeviceGetAddressString(device); - if (name != nil && address != nil) + if (name != nil && address != nil) { if (CFStringCompare(name, CFSTR("Nintendo RVL-CNT-01"), 0) == kCFCompareEqualTo) { @@ -233,17 +234,20 @@ void checkDevice(WiiRemoteRef wiiremote, IOBluetoothDeviceRef device) void myFoundFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device) { + post("myFoundFunc"); checkDevice((WiiRemoteRef)refCon, device); } void myUpdatedFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOBluetoothDeviceRef device, uint32_t devicesRemaining) { + post("myUpdatedFunc"); + checkDevice((WiiRemoteRef)refCon, device); } void myCompleteFunc(void *refCon, IOBluetoothDeviceInquiryRef inquiry, IOReturn error, Boolean aborted) { - IOReturn ret; + post("myCompleteFunc"); if (aborted) return; // called by stop ;) @@ -252,14 +256,10 @@ 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 + CFRunLoopStop( CFRunLoopGetCurrent() ); +#endif } //-------------------------------------------------------------------------------------------- @@ -274,11 +274,12 @@ Boolean wiiremote_isconnected(WiiRemoteRef wiiremote) Boolean wiiremote_search(WiiRemoteRef wiiremote, char *address) { + post("wiiremote_search"); IOReturn ret; if (wiiremote->inquiry != nil) return true; - + wiiremote->inquiry = IOBluetoothDeviceInquiryCreateWithCallbackRefCon((void *)wiiremote); IOBluetoothDeviceInquirySetDeviceFoundCallback(wiiremote->inquiry, myFoundFunc); IOBluetoothDeviceInquirySetDeviceNameUpdatedCallback(wiiremote->inquiry, myUpdatedFunc); @@ -295,11 +296,15 @@ Boolean wiiremote_search(WiiRemoteRef wiiremote, char *address) wiiremote->inquiry = nil; return false; } +#ifdef PD + CFRunLoopRun(); // PD doesn't use the Carbon loop, so we have to manually control it +#endif return true; } Boolean wiiremote_stopsearch(WiiRemoteRef wiiremote) { + post("wiiremote_stopsearch"); IOReturn ret; if (wiiremote->inquiry == nil) @@ -841,7 +846,7 @@ Boolean wiiremote_connect(WiiRemoteRef wiiremote) Boolean wiiremote_disconnect(WiiRemoteRef wiiremote) { - short i; + short i = 0; if (wiiremote->cchan) { |