From 866b124d3517a36d21bbbc2f16b0839976fe89e2 Mon Sep 17 00:00:00 2001 From: Lysann Kessler Date: Sat, 8 Dec 2012 18:58:30 +0100 Subject: [PATCH] fix Windows compilation, wiiuse_wait_report and wiiuse_probe_motion_plus --- src/io.c | 12 +++++++++--- src/motion_plus.c | 8 ++++++-- src/os_win.c | 13 ++++++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/io.c b/src/io.c index e7bb83d..c3171ce 100644 --- a/src/io.c +++ b/src/io.c @@ -122,13 +122,19 @@ void wiiuse_disconnect(struct wiimote_t* wm) { */ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) { + byte readReport; for(;;) { if(wiiuse_os_read(wm, buffer, bufferLength) > 0) { - if(buffer[1] == report) { +#ifdef WIIUSE_WIN32 + readReport = buffer[0]; +#else + readReport = buffer[1]; +#endif + if(readReport == report) { break; } else { - WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[1], report); + WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, readReport, report); } } } @@ -154,7 +160,7 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor unsigned n_full_reports; unsigned last_report; byte *output; - int i; + unsigned int i; /* * address in big endian first, the leading byte will diff --git a/src/motion_plus.c b/src/motion_plus.c index 5aed3f4..711f541 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -47,11 +47,15 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm) { byte buf[MAX_PAYLOAD]; unsigned id; + unsigned short offset = 0; +#ifdef WIIUSE_WIN32 + offset = 1; +#endif wiiuse_read(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); /* check error code */ - if(buf[4] & 0x0f) + if(buf[4-offset] & 0x0f) { WIIUSE_DEBUG("No Motion+ available, stopping probe."); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); @@ -59,7 +63,7 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm) } /* decode the id*/ - id = from_big_endian_uint32_t(buf + 2); + id = from_big_endian_uint32_t(buf + 2 - offset); if(id != EXP_ID_CODE_INACTIVE_MOTION_PLUS && id != EXP_ID_CODE_NLA_MOTION_PLUS && diff --git a/src/os_win.c b/src/os_win.c index 08d945b..aede1fb 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -225,7 +225,7 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { if (r == WAIT_TIMEOUT) { /* timeout - cancel and continue */ - if (*wm->event_buf) + if (*buf) WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); CancelIo(wm->dev_handle); @@ -238,6 +238,17 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) return 0; + +#ifdef WITH_WIIUSE_DEBUG + { + int i; + printf("[DEBUG] (id %i) RECV: (%x) ", wm->unid, buf[0]); + for(i = 1; i < b; i++) { + printf("%x ", buf[i]); + } + printf("\n"); + } +#endif } ResetEvent(wm->hid_overlap.hEvent);