diff --git a/Externals/WiiUseSrc/Src/events.c b/Externals/WiiUseSrc/Src/events.c index 3db4ea6f9f..87bed002d5 100644 --- a/Externals/WiiUseSrc/Src/events.c +++ b/Externals/WiiUseSrc/Src/events.c @@ -84,6 +84,29 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { int evnt = 0; #ifndef WIN32 + #if defined(__APPLE__) + + int i; + + if (!wm) + return 0; + + for (i = 0; i < wiimotes; ++i) { + wm[i]->event = WIIUSE_NONE; + + if (wiiuse_io_read(wm[i])) { + /* propagate the event */ + propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); + evnt += (wm[i]->event != WIIUSE_NONE); + + /* clear out the event buffer */ + memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); + } else { + idle_cycle(wm[i]); + } + } + + #else /* * *nix */ @@ -167,6 +190,7 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { idle_cycle(wm[i]); } } + #endif #else /* * Windows diff --git a/Externals/WiiUseSrc/Src/io_osx.c b/Externals/WiiUseSrc/Src/io_osx.c index b2f829a715..350771df25 100644 --- a/Externals/WiiUseSrc/Src/io_osx.c +++ b/Externals/WiiUseSrc/Src/io_osx.c @@ -52,6 +52,8 @@ IOBluetoothL2CAPChannel * _cchan; #include "wiiuse_internal.h" #include "io.h" +byte DataFromWiimote[MAX_PAYLOAD]; + static int wiiuse_connect_single(struct wiimote_t* wm, char* address); @interface SearchBT: NSObject {} @@ -72,6 +74,18 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address); @implementation ConnectBT +-(void)writeToWiimote: (void *)data length:(UInt16)length +{ + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + [_cchan writeSync:data length:length]; + usleep(10000); + [pool release]; + +} + + #pragma mark - #pragma mark Bluetooth @@ -82,10 +96,16 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address); } -- (void)l2capChannelData:(IOBluetoothL2CAPChannel *) l2capChannel data:(unsigned char *)buffer length:(NSUInteger)length { - //data ? +- (void)l2capChannelData:(IOBluetoothL2CAPChannel *) l2capChannel data:(byte *)BtData length:(NSUInteger)length { + //here we got data from wiimote - printf("data %d\n",length); + for (int o=0; ounid); - //run the main loop to get bt data - CFRunLoopRun(); /* do the handshake */ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); wiiuse_handshake(wm, NULL, 0); wiiuse_set_report_type(wm); + + [pool release]; return 1; @@ -315,21 +347,23 @@ void wiiuse_disconnect(struct wiimote_t* wm) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); } - int wiiuse_io_read(struct wiimote_t* wm) { - //TODO + //run the main loop to get bt data + CFRunLoopRun(); + + for (int len=0; lenevent_buf[len] = DataFromWiimote[len]; + } + return 1; } int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [_cchan writeSync:buf length:len]; - - usleep (10000); - [pool release]; + [cbt writeToWiimote:buf length:len]; return 1; }