From 304bf4fc64989c78e9e0bcdbc1832077a760eded Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Fri, 12 Nov 2010 10:24:00 -0600 Subject: [PATCH] fromdos the source --- src/classic.c | 50 +++++++++++++++++------------------ src/dynamics.c | 14 +++++----- src/events.h | 2 +- src/guitar_hero_3.c | 48 +++++++++++++++++----------------- src/io.c | 28 ++++++++++---------- src/io_win.c | 30 ++++++++++----------- src/nunchuk.c | 64 ++++++++++++++++++++++----------------------- src/os.h | 8 +++--- 8 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/classic.c b/src/classic.c index 1d2c3ab..1d3abaa 100644 --- a/src/classic.c +++ b/src/classic.c @@ -57,7 +57,7 @@ static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now); * @return Returns 1 if handshake was successful, 0 if not. */ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) { - int i; + int i; int offset = 0; cc->btns = 0; @@ -69,30 +69,30 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte /* 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 = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - - WIIUSE_DEBUG("Classic controller 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; - } - + + 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 = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); + + WIIUSE_DEBUG("Classic controller 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 */ cc->ljs.max.x = data[0 + offset] / 4; diff --git a/src/dynamics.c b/src/dynamics.c index 53612a6..b6baa72 100644 --- a/src/dynamics.c +++ b/src/dynamics.c @@ -107,12 +107,12 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori orient->pitch = y; orient->a_pitch = y; } - - /* smooth the angles if enabled */ - if (smooth) { - apply_smoothing(ac, orient, SMOOTH_ROLL); - apply_smoothing(ac, orient, SMOOTH_PITCH); - } + + /* smooth the angles if enabled */ + if (smooth) { + apply_smoothing(ac, orient, SMOOTH_ROLL); + apply_smoothing(ac, orient, SMOOTH_PITCH); + } } @@ -191,7 +191,7 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) { void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) { switch (type) { case SMOOTH_ROLL: - { + { /* it's possible last iteration was nan or inf, so set it to 0 if that happened */ if (isnan(ac->st_roll) || isinf(ac->st_roll)) ac->st_roll = 0.0f; diff --git a/src/events.h b/src/events.h index e720a34..5ebd3ad 100644 --- a/src/events.h +++ b/src/events.h @@ -45,7 +45,7 @@ extern "C" { void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg); void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len); -void disable_expansion(struct wiimote_t* wm); +void disable_expansion(struct wiimote_t* wm); #ifdef __cplusplus } diff --git a/src/guitar_hero_3.c b/src/guitar_hero_3.c index 5837dc0..29c58af 100644 --- a/src/guitar_hero_3.c +++ b/src/guitar_hero_3.c @@ -57,7 +57,7 @@ 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 i; int offset = 0; /* @@ -74,29 +74,29 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b /* 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 = 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; - } + + 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 = 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; diff --git a/src/io.c b/src/io.c index df23a4f..ee2826b 100644 --- a/src/io.c +++ b/src/io.c @@ -59,8 +59,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { case 0: { /* send request to wiimote for accelerometer calibration */ - byte* buf; - + byte* buf; + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); wiiuse_set_leds(wm, WIIMOTE_LED_NONE); @@ -68,8 +68,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7); wm->handshake_state++; - wiiuse_set_leds(wm, WIIMOTE_LED_NONE); - + wiiuse_set_leds(wm, WIIMOTE_LED_NONE); + break; } case 1: @@ -94,23 +94,23 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z, accel->cal_g.x, accel->cal_g.y, accel->cal_g.z); - - /* request the status of the wiimote to see if there is an expansion */ - wiiuse_status(wm); - + + /* request the status of the wiimote to see if there is an expansion */ + wiiuse_status(wm); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); - wm->handshake_state++; - - /* now enable IR if it was set before the handshake completed */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { + wm->handshake_state++; + + /* now enable IR if it was set before the handshake completed */ + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { WIIUSE_DEBUG("Handshake finished, enabling IR."); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); wiiuse_set_ir(wm, 1); - } + } break; - } + } default: { break; diff --git a/src/io_win.c b/src/io_win.c index 3b27c41..38b54ba 100644 --- a/src/io_win.c +++ b/src/io_win.c @@ -32,14 +32,14 @@ */ #ifdef WIN32 - + #include #include #include #include #include - + #include "definitions.h" #include "wiiuse_internal.h" #include "io.h" @@ -178,8 +178,8 @@ int wiiuse_io_read(struct wiimote_t* wm) { if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) { /* partial read */ - b = GetLastError(); - + b = GetLastError(); + if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) { /* remote disconnect */ wiiuse_disconnected(wm); @@ -188,11 +188,11 @@ int wiiuse_io_read(struct wiimote_t* wm) { r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout); if (r == WAIT_TIMEOUT) { - /* timeout - cancel and continue */ - - if (*wm->event_buf) - WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); - + /* timeout - cancel and continue */ + + if (*wm->event_buf) + WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); + CancelIo(wm->dev_handle); ResetEvent(wm->hid_overlap.hEvent); return 0; @@ -205,25 +205,25 @@ int wiiuse_io_read(struct wiimote_t* wm) { return 0; } - ResetEvent(wm->hid_overlap.hEvent); + ResetEvent(wm->hid_overlap.hEvent); return 1; } int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { DWORD bytes; - int i; - + int i; + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return 0; - + return 0; + switch (wm->stack) { case WIIUSE_STACK_UNKNOWN: { /* try to auto-detect the stack type */ if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) { /* bluesoleil will always return 1 here, even if it's not connected */ - wm->stack = WIIUSE_STACK_BLUESOLEIL; + wm->stack = WIIUSE_STACK_BLUESOLEIL; return i; } diff --git a/src/nunchuk.c b/src/nunchuk.c index 48dbe6a..fd763bc 100644 --- a/src/nunchuk.c +++ b/src/nunchuk.c @@ -53,9 +53,9 @@ static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now); * @return Returns 1 if handshake was successful, 0 if not. */ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) { - int i; - int offset = 0; - + int i; + int offset = 0; + nc->btns = 0; nc->btns_held = 0; nc->btns_released = 0; @@ -66,29 +66,29 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un /* 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 = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - - WIIUSE_DEBUG("Nunchuk 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; + 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 = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); + + WIIUSE_DEBUG("Nunchuk 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; } nc->accel_calib.cal_zero.x = data[offset + 0]; @@ -103,16 +103,16 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un nc->js.max.y = data[offset + 11]; nc->js.min.y = data[offset + 12]; nc->js.center.y = data[offset + 13]; - + /* default the thresholds to the same as the wiimote */ nc->orient_threshold = wm->orient_threshold; nc->accel_threshold = wm->accel_threshold; - /* handshake done */ - wm->exp.type = EXP_NUNCHUK; - - #ifdef WIN32 - wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; + /* handshake done */ + wm->exp.type = EXP_NUNCHUK; + + #ifdef WIN32 + wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; #endif return 1; diff --git a/src/os.h b/src/os.h index 53b80f5..79d4ce6 100644 --- a/src/os.h +++ b/src/os.h @@ -39,14 +39,14 @@ #ifndef OS_H_INCLUDED #define OS_H_INCLUDED -#ifdef WIN32 +#ifdef WIN32 /* windows */ #define isnan(x) _isnan(x) #define isinf(x) !_finite(x) - /* disable warnings I don't care about */ - #pragma warning(disable:4244) /* possible loss of data conversion */ - #pragma warning(disable:4273) /* inconsistent dll linkage */ + /* disable warnings I don't care about */ + #pragma warning(disable:4244) /* possible loss of data conversion */ + #pragma warning(disable:4273) /* inconsistent dll linkage */ #pragma warning(disable:4217) #else /* nix */