Permalink
Browse files

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.
  • Loading branch information...
tuomasjjrasanen authored and abstrakraft committed Nov 8, 2009
1 parent 89233ec commit b54bd057fe6b258d6e0a99047f839891ab3bc2df
Showing with 11 additions and 10 deletions.
  1. +6 −6 libcwiid/cwiid_internal.h
  2. +1 −0 libcwiid/process.c
  3. +4 −4 libcwiid/thread.c
@@ -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"
@@ -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;
@@ -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;

0 comments on commit b54bd05

Please sign in to comment.