fromdos the source

This commit is contained in:
Ryan Pavlik
2010-11-12 10:24:00 -06:00
parent 2432d5c867
commit 304bf4fc64
8 changed files with 122 additions and 122 deletions

View File

@@ -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. * @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 classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) {
int i; int i;
int offset = 0; int offset = 0;
cc->btns = 0; cc->btns = 0;
@@ -69,30 +69,30 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
/* decrypt data */ /* decrypt data */
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17; data[i] = (data[i] ^ 0x17) + 0x17;
if (data[offset] == 0xFF) { if (data[offset] == 0xFF) {
/* /*
* Sometimes the data returned here is not correct. * Sometimes the data returned here is not correct.
* This might happen because the wiimote is lagging * This might happen because the wiimote is lagging
* behind our initialization sequence. * behind our initialization sequence.
* To fix this just request the handshake again. * To fix this just request the handshake again.
* *
* Other times it's just the first 16 bytes are 0xFF, * Other times it's just the first 16 bytes are 0xFF,
* but since the next 16 bytes are the same, just use * but since the next 16 bytes are the same, just use
* those. * those.
*/ */
if (data[offset + 16] == 0xFF) { if (data[offset + 16] == 0xFF) {
/* get the calibration data */ /* get the calibration data */
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
WIIUSE_DEBUG("Classic controller handshake appears invalid, trying again."); 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); wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
return 0; return 0;
} else } else
offset += 16; offset += 16;
} }
/* joystick stuff */ /* joystick stuff */
cc->ljs.max.x = data[0 + offset] / 4; cc->ljs.max.x = data[0 + offset] / 4;

View File

@@ -107,12 +107,12 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori
orient->pitch = y; orient->pitch = y;
orient->a_pitch = y; orient->a_pitch = y;
} }
/* smooth the angles if enabled */ /* smooth the angles if enabled */
if (smooth) { if (smooth) {
apply_smoothing(ac, orient, SMOOTH_ROLL); apply_smoothing(ac, orient, SMOOTH_ROLL);
apply_smoothing(ac, orient, SMOOTH_PITCH); 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) { void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
switch (type) { switch (type) {
case SMOOTH_ROLL: case SMOOTH_ROLL:
{ {
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */ /* 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)) if (isnan(ac->st_roll) || isinf(ac->st_roll))
ac->st_roll = 0.0f; ac->st_roll = 0.0f;

View File

@@ -45,7 +45,7 @@ extern "C" {
void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg); void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg);
void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len); 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 #ifdef __cplusplus
} }

View File

@@ -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. * @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 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; 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 */ /* decrypt data */
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17; data[i] = (data[i] ^ 0x17) + 0x17;
if (data[offset] == 0xFF) { if (data[offset] == 0xFF) {
/* /*
* Sometimes the data returned here is not correct. * Sometimes the data returned here is not correct.
* This might happen because the wiimote is lagging * This might happen because the wiimote is lagging
* behind our initialization sequence. * behind our initialization sequence.
* To fix this just request the handshake again. * To fix this just request the handshake again.
* *
* Other times it's just the first 16 bytes are 0xFF, * Other times it's just the first 16 bytes are 0xFF,
* but since the next 16 bytes are the same, just use * but since the next 16 bytes are the same, just use
* those. * those.
*/ */
if (data[offset + 16] == 0xFF) { if (data[offset + 16] == 0xFF) {
/* get the calibration data */ /* get the calibration data */
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again."); 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); wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
return 0; return 0;
} else } else
offset += 16; offset += 16;
} }
/* joystick stuff */ /* joystick stuff */
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X; gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;

View File

@@ -59,8 +59,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
case 0: case 0:
{ {
/* send request to wiimote for accelerometer calibration */ /* send request to wiimote for accelerometer calibration */
byte* buf; byte* buf;
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
wiiuse_set_leds(wm, WIIMOTE_LED_NONE); 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); wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
wm->handshake_state++; wm->handshake_state++;
wiiuse_set_leds(wm, WIIMOTE_LED_NONE); wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
break; break;
} }
case 1: 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_zero.x, accel->cal_zero.y, accel->cal_zero.z,
accel->cal_g.x, accel->cal_g.y, accel->cal_g.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 */ /* request the status of the wiimote to see if there is an expansion */
wiiuse_status(wm); wiiuse_status(wm);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
wm->handshake_state++; wm->handshake_state++;
/* now enable IR if it was set before the handshake completed */ /* now enable IR if it was set before the handshake completed */
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
WIIUSE_DEBUG("Handshake finished, enabling IR."); WIIUSE_DEBUG("Handshake finished, enabling IR.");
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1); wiiuse_set_ir(wm, 1);
} }
break; break;
} }
default: default:
{ {
break; break;

View File

@@ -32,14 +32,14 @@
*/ */
#ifdef WIN32 #ifdef WIN32
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <windows.h> #include <windows.h>
#include <hidsdi.h> #include <hidsdi.h>
#include <setupapi.h> #include <setupapi.h>
#include "definitions.h" #include "definitions.h"
#include "wiiuse_internal.h" #include "wiiuse_internal.h"
#include "io.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)) { if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) {
/* partial read */ /* partial read */
b = GetLastError(); b = GetLastError();
if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) { if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) {
/* remote disconnect */ /* remote disconnect */
wiiuse_disconnected(wm); wiiuse_disconnected(wm);
@@ -188,11 +188,11 @@ int wiiuse_io_read(struct wiimote_t* wm) {
r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout); r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout);
if (r == WAIT_TIMEOUT) { if (r == WAIT_TIMEOUT) {
/* timeout - cancel and continue */ /* timeout - cancel and continue */
if (*wm->event_buf) if (*wm->event_buf)
WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
CancelIo(wm->dev_handle); CancelIo(wm->dev_handle);
ResetEvent(wm->hid_overlap.hEvent); ResetEvent(wm->hid_overlap.hEvent);
return 0; return 0;
@@ -205,25 +205,25 @@ int wiiuse_io_read(struct wiimote_t* wm) {
return 0; return 0;
} }
ResetEvent(wm->hid_overlap.hEvent); ResetEvent(wm->hid_overlap.hEvent);
return 1; return 1;
} }
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
DWORD bytes; DWORD bytes;
int i; int i;
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) if (!wm || !WIIMOTE_IS_CONNECTED(wm))
return 0; return 0;
switch (wm->stack) { switch (wm->stack) {
case WIIUSE_STACK_UNKNOWN: case WIIUSE_STACK_UNKNOWN:
{ {
/* try to auto-detect the stack type */ /* try to auto-detect the stack type */
if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) { if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) {
/* bluesoleil will always return 1 here, even if it's not connected */ /* bluesoleil will always return 1 here, even if it's not connected */
wm->stack = WIIUSE_STACK_BLUESOLEIL; wm->stack = WIIUSE_STACK_BLUESOLEIL;
return i; return i;
} }

View File

@@ -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. * @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 nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) {
int i; int i;
int offset = 0; int offset = 0;
nc->btns = 0; nc->btns = 0;
nc->btns_held = 0; nc->btns_held = 0;
nc->btns_released = 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 */ /* decrypt data */
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17; data[i] = (data[i] ^ 0x17) + 0x17;
if (data[offset] == 0xFF) { if (data[offset] == 0xFF) {
/* /*
* Sometimes the data returned here is not correct. * Sometimes the data returned here is not correct.
* This might happen because the wiimote is lagging * This might happen because the wiimote is lagging
* behind our initialization sequence. * behind our initialization sequence.
* To fix this just request the handshake again. * To fix this just request the handshake again.
* *
* Other times it's just the first 16 bytes are 0xFF, * Other times it's just the first 16 bytes are 0xFF,
* but since the next 16 bytes are the same, just use * but since the next 16 bytes are the same, just use
* those. * those.
*/ */
if (data[offset + 16] == 0xFF) { if (data[offset + 16] == 0xFF) {
/* get the calibration data */ /* get the calibration data */
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again."); WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again.");
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
return 0; return 0;
} else } else
offset += 16; offset += 16;
} }
nc->accel_calib.cal_zero.x = data[offset + 0]; 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.max.y = data[offset + 11];
nc->js.min.y = data[offset + 12]; nc->js.min.y = data[offset + 12];
nc->js.center.y = data[offset + 13]; nc->js.center.y = data[offset + 13];
/* default the thresholds to the same as the wiimote */ /* default the thresholds to the same as the wiimote */
nc->orient_threshold = wm->orient_threshold; nc->orient_threshold = wm->orient_threshold;
nc->accel_threshold = wm->accel_threshold; nc->accel_threshold = wm->accel_threshold;
/* handshake done */ /* handshake done */
wm->exp.type = EXP_NUNCHUK; wm->exp.type = EXP_NUNCHUK;
#ifdef WIN32 #ifdef WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif #endif
return 1; return 1;

View File

@@ -39,14 +39,14 @@
#ifndef OS_H_INCLUDED #ifndef OS_H_INCLUDED
#define OS_H_INCLUDED #define OS_H_INCLUDED
#ifdef WIN32 #ifdef WIN32
/* windows */ /* windows */
#define isnan(x) _isnan(x) #define isnan(x) _isnan(x)
#define isinf(x) !_finite(x) #define isinf(x) !_finite(x)
/* disable warnings I don't care about */ /* disable warnings I don't care about */
#pragma warning(disable:4244) /* possible loss of data conversion */ #pragma warning(disable:4244) /* possible loss of data conversion */
#pragma warning(disable:4273) /* inconsistent dll linkage */ #pragma warning(disable:4273) /* inconsistent dll linkage */
#pragma warning(disable:4217) #pragma warning(disable:4217)
#else #else
/* nix */ /* nix */