diff --git a/Externals/WiiUseSrc/Src/guitar_hero_3.c b/Externals/WiiUseSrc/Src/guitar_hero_3.c index 51ff40a365..7b88438141 100644 --- a/Externals/WiiUseSrc/Src/guitar_hero_3.c +++ b/Externals/WiiUseSrc/Src/guitar_hero_3.c @@ -57,7 +57,6 @@ static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now * @return Returns 1 if handshake was successful, 0 if not. */ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len) { - int i; int offset = 0; /* @@ -74,33 +73,6 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b gh3->tb_raw = 0; gh3->touch_bar = -1; - /* decrypt data */ - for (i = 0; i < len; ++i) - data[i] = (data[i] ^ 0x17) + 0x17; - - if (data[offset] == 0xFF) { - /* - * Sometimes the data returned here is not correct. - * This might happen because the wiimote is lagging - * behind our initialization sequence. - * To fix this just request the handshake again. - * - * Other times it's just the first 16 bytes are 0xFF, - * but since the next 16 bytes are the same, just use - * those. - */ - if (data[offset + 16] == 0xFF) { - /* get the calibration data */ - byte* handshake_buf = (byte *)malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - - WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again."); - wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); - - return 0; - } else - offset += 16; - } - /* joystick stuff */ gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X; gh3->js.min.x = GUITAR_HERO_3_JS_MIN_X; @@ -179,7 +151,7 @@ void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg) { gh3->whammy_bar = (msg[3] - GUITAR_HERO_3_WHAMMY_BAR_MIN) / (float)(GUITAR_HERO_3_WHAMMY_BAR_MAX - GUITAR_HERO_3_WHAMMY_BAR_MIN); /* joy stick */ - calc_joystick_state(&gh3->js, msg[0], msg[1]); + calc_joystick_state(&gh3->js, gh3->js.pos.x, gh3->js.pos.y); } diff --git a/Externals/WiiUseSrc/Src/nunchuk.c b/Externals/WiiUseSrc/Src/nunchuk.c index f1d371a5ad..97f83a7984 100644 --- a/Externals/WiiUseSrc/Src/nunchuk.c +++ b/Externals/WiiUseSrc/Src/nunchuk.c @@ -113,12 +113,12 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un /* if min and max are reported as 0, initialize them to usable values based on center, and fine tune in nunchuck_event() */ if (nc->js.center.x) { - if (nc->js.min.x == 0) nc->js.min.y = nc->js.center.y - 80; - if (nc->js.max.x == 0) nc->js.max.x = nc->js.center.y + 80; + if (nc->js.min.x == 0) nc->js.min.x = nc->js.center.x - 80; + if (nc->js.max.x == 0) nc->js.max.x = nc->js.center.x + 80; } if (nc->js.center.y) { - if (nc->js.min.y == 0) nc->js.min.x = nc->js.center.x - 80; - if (nc->js.max.y == 0) nc->js.max.x = nc->js.center.x + 80; + if (nc->js.min.y == 0) nc->js.min.y = nc->js.center.y - 80; + if (nc->js.max.y == 0) nc->js.max.y = nc->js.center.y + 80; } #ifdef WIN32 @@ -156,19 +156,22 @@ void nunchuk_event(struct nunchuk_t* nc, byte* msg) { /* get button states */ nunchuk_pressed_buttons(nc, msg[5]); - /* calculate joystick state */ - calc_joystick_state(&nc->js, msg[0], msg[1]); + nc->js.pos.x = msg[0]; + nc->js.pos.y = msg[1]; - /* if min and max are reported as 0, initialize them to usable values based on center, and fine tune in nunchuck_event() */ + /* extend min and max values to physical range of motion */ if (nc->js.center.x) { - if (nc->js.min.x == 0) nc->js.min.y = nc->js.center.y - 80; - if (nc->js.max.x == 0) nc->js.max.x = nc->js.center.y + 80; + if (nc->js.min.x > nc->js.pos.x) nc->js.min.x = nc->js.pos.x; + if (nc->js.max.x < nc->js.pos.x) nc->js.max.x = nc->js.pos.x; } if (nc->js.center.y) { - if (nc->js.min.y == 0) nc->js.min.x = nc->js.center.x - 80; - if (nc->js.max.y == 0) nc->js.max.x = nc->js.center.x + 80; + if (nc->js.min.y > nc->js.pos.y) nc->js.min.y = nc->js.pos.y; + if (nc->js.max.y < nc->js.pos.y) nc->js.max.y = nc->js.pos.y; } + /* calculate joystick state */ + calc_joystick_state(&nc->js, nc->js.pos.x, nc->js.pos.y); + /* calculate orientation */ nc->accel.x = msg[2]; nc->accel.y = msg[3];