Skip to content

Commit

Permalink
Fixed an issue of incorrectly interpreting Balance Board as MotionPlus.
Browse files Browse the repository at this point in the history
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 Feb 19, 2010
1 parent 89233ec commit b54bd05
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions libcwiid/cwiid_internal.h
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions libcwiid/process.c
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions libcwiid/thread.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b54bd05

Please sign in to comment.