diff --git a/src/events.c b/src/events.c index 4ef796a..fc63a50 100644 --- a/src/events.c +++ b/src/events.c @@ -205,8 +205,8 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; - - if (wiiuse_io_read(wm[i])) { + + if (wiiuse_io_read(wm[i],wm[i]->event_buf,sizeof(wm[i]->event_buf))) { /* propagate the event, messages should be read as in linux, starting from the second element */ propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); evnt += (wm[i]->event != WIIUSE_NONE); @@ -214,6 +214,9 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { /* clear out the event buffer */ memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); } else { + /* send out any waiting writes */ + wiiuse_send_next_pending_write_request(wm[i]); + idle_cycle(wm[i]); } } diff --git a/src/io_mac.m b/src/io_mac.m index a586417..3846ae6 100755 --- a/src/io_mac.m +++ b/src/io_mac.m @@ -663,7 +663,7 @@ int wiiuse_load(struct wiimote_t** wm) } // Defined in io.h -int wiiuse_io_read(struct wiimote_t* wm) +int wiiuse_io_read(struct wiimote_t* wm, byte* buf, int len) { if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) return 0; @@ -723,12 +723,12 @@ int wiiuse_io_read(struct wiimote_t* wm) return 0; } - // Forward to WiiC - if(length < sizeof(wm->event_buf)) - memcpy(wm->event_buf,buffer,length); + // Forward to the parameter buffer + if(length <= len) + memcpy(buf,buffer,length); else { WIIUSE_DEBUG("Received data are more than the buffer.... strange! (id %i)", wm->unid); - memcpy(wm->event_buf,buffer,sizeof(wm->event_buf)); + memcpy(buf,buffer,len); } // Release the consumed message