From f7b4fd44a072cfb34519d33fdb74ccf6d8af566f Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 00:52:05 +0100 Subject: [PATCH] fix mac expansion handshake by propagating the event on receive --- src/events.c | 1 + src/io_mac.m | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/events.c b/src/events.c index ba6cc3a..a6e82ec 100644 --- a/src/events.c +++ b/src/events.c @@ -801,6 +801,7 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { WIIUSE_DEBUG("no handshake data received from expansion"); return; } + wm->expansion_state = 0; id = from_big_endian_uint32_t(data + 220); switch(id) { case EXP_ID_CODE_NUNCHUK: diff --git a/src/io_mac.m b/src/io_mac.m index 7ad62d9..652cc4a 100755 --- a/src/io_mac.m +++ b/src/io_mac.m @@ -366,24 +366,38 @@ - (void) l2capChannelData:(IOBluetoothL2CAPChannel*) channel data:(byte *) data length:(NSUInteger) length { // This is done in case the output channel woke up this handler - if(!data) { - [self setReading:NO]; - length = 0; + if(!data || ([channel PSM] == WM_OUTPUT_CHANNEL)) { return; } + + // log the received data + #ifdef WITH_WIIUSE_DEBUG + { + printf("[DEBUG] (id %i) RECV: (%x) ", _wm->unid, data[0]); + int x; + for (x = 1; x < length; ++x) + printf("%.2x ", data[x]); + printf("\n"); + } + #endif /* * This is called if we are receiving data before completing * the handshaking, hence before calling wiiuse_poll */ + // wiimote handshake if(WIIMOTE_IS_SET(_wm, WIIMOTE_STATE_HANDSHAKE)) propagate_event(_wm, data[1], data+2); + + // expansion handshake + if(_wm->expansion_state != 0) + propagate_event(_wm, data[1], data+2); receivedMsg = [[NSData dataWithBytes:data length:length] retain]; msgLength = length; - // This is done when a message is successfully received. Stop the main loop after reading - [self setReading:NO]; + // This is done when a message is successfully received. Stop the main loop after reading + [self setReading:NO]; } - (unsigned int) getMsgLength