From b54bd057fe6b258d6e0a99047f839891ab3bc2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomas=20R=C3=A4s=C3=A4nen?= Date: Sun, 8 Nov 2009 02:15:49 +0200 Subject: [PATCH] Fixed an issue of incorrectly interpreting Balance Board as MotionPlus. Previous extension identifiers were only one byte long (just considering the byte 0xA400FE) and that byte of Balance Board and MotionPlus happens to be identical (0x04). In reality, extension identifier is six byte long, but as long as GHWT Drums are not supported, checking the last two bytes is enough. See http://wiibrew.org/wiki/Wiimote#The_New_Way for more information on identifying extensions. --- libcwiid/cwiid_internal.h | 12 ++++++------ libcwiid/process.c | 1 + libcwiid/thread.c | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libcwiid/cwiid_internal.h b/libcwiid/cwiid_internal.h index 180a870..4805166 100644 --- a/libcwiid/cwiid_internal.h +++ b/libcwiid/cwiid_internal.h @@ -88,12 +88,12 @@ #define NUNCHUK_BTN_MASK 0x03 /* Extension Values */ -#define EXT_NONE 0x2E -#define EXT_PARTIAL 0xFF -#define EXT_NUNCHUK 0x00 -#define EXT_CLASSIC 0x01 -#define EXT_BALANCE 0x2A -#define EXT_MOTIONPLUS 0x04 +#define EXT_NONE 0x2E2E +#define EXT_PARTIAL 0xFFFF +#define EXT_NUNCHUK 0x0000 +#define EXT_CLASSIC 0x0101 +#define EXT_BALANCE 0x0402 +#define EXT_MOTIONPLUS 0x0405 /* IR Enable blocks */ #define MARCAN_IR_BLOCK_1 "\x00\x00\x00\x00\x00\x00\x90\x00\xC0" diff --git a/libcwiid/process.c b/libcwiid/process.c index faea690..7f36e65 100644 --- a/libcwiid/process.c +++ b/libcwiid/process.c @@ -233,6 +233,7 @@ int process_ext(struct wiimote *wiimote, unsigned char *data, balance_mesg->left_bottom = ((uint16_t)data[6]<<8 | (uint16_t)data[7]); } + break; case CWIID_EXT_MOTIONPLUS: if (wiimote->state.rpt_mode & CWIID_RPT_MOTIONPLUS) { motionplus_mesg = &ma->array[ma->count++].motionplus_mesg; diff --git a/libcwiid/thread.c b/libcwiid/thread.c index c03e96d..11e17ee 100644 --- a/libcwiid/thread.c +++ b/libcwiid/thread.c @@ -161,13 +161,13 @@ void *status_thread(struct wiimote *wiimote) if (status_mesg->ext_type == CWIID_EXT_UNKNOWN) { /* Read extension ID */ - if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 1, &buf[0])) { + if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 2, &buf)) { cwiid_err(wiimote, "Read error (extension error)"); status_mesg->ext_type = CWIID_EXT_UNKNOWN; } /* If the extension didn't change, or if the extension is a * MotionPlus, no init necessary */ - switch (buf[0]) { + switch ((buf[0] << 8) | buf[1]) { case EXT_NONE: status_mesg->ext_type = CWIID_EXT_NONE; break; @@ -197,12 +197,12 @@ void *status_thread(struct wiimote *wiimote) status_mesg->ext_type = CWIID_EXT_UNKNOWN; } /* Read extension ID */ - else if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 1, &buf[0])) { + else if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 2, &buf)) { cwiid_err(wiimote, "Read error (extension error)"); status_mesg->ext_type = CWIID_EXT_UNKNOWN; } else { - switch (buf[0]) { + switch ((buf[0] << 8) | buf[1]) { case EXT_NONE: case EXT_PARTIAL: status_mesg->ext_type = CWIID_EXT_NONE; -- 1.7.10