Updated to latest wiiuse fork + allowed the RVL-CNT-01-TR to connect and respond to buttons on Linux (but no accelerometer support yet)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12849 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
c532c9d175
commit
5d184d863a
@ -78,8 +78,8 @@ extern FILE* logtarget[];
|
||||
#endif
|
||||
|
||||
/* Convert between radians and degrees */
|
||||
#define WIIUSE_RAD_TO_DEGREE(r) ((r * 180.0f) / WIIMOTE_PI)
|
||||
#define WIIUSE_DEGREE_TO_RAD(d) (d * (WIIMOTE_PI / 180.0f))
|
||||
#define RAD_TO_DEGREE(r) ((r * 180.0f) / WIIMOTE_PI)
|
||||
#define DEGREE_TO_RAD(d) (d * (WIIMOTE_PI / 180.0f))
|
||||
|
||||
#define absf(x) ((x >= 0) ? (x) : (x * -1.0f))
|
||||
#define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x)))
|
||||
|
@ -42,9 +42,7 @@
|
||||
#ifdef _MSC_VER
|
||||
#include <float.h>
|
||||
/* windows with visual c */
|
||||
# ifndef isnan
|
||||
#define isnan(x) (_isnan(x))
|
||||
# endif
|
||||
#define isnan(x) (_isnan(x))
|
||||
#define isinf(x) (!_finite(x))
|
||||
/* disable warnings I don't care about */
|
||||
/*#pragma warning(disable:4273) */ /* inconsistent dll linkage */
|
||||
|
@ -96,7 +96,7 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori
|
||||
/* if it is over 1g then it is probably accelerating and not reliable */
|
||||
if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) {
|
||||
/* roll */
|
||||
x = WIIUSE_RAD_TO_DEGREE(atan2f(x, z));
|
||||
x = RAD_TO_DEGREE(atan2f(x, z));
|
||||
|
||||
orient->roll = x;
|
||||
orient->a_roll = x;
|
||||
@ -104,7 +104,7 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori
|
||||
|
||||
if (abs(accel->y - ac->cal_zero.y) <= ac->cal_g.y) {
|
||||
/* pitch */
|
||||
y = WIIUSE_RAD_TO_DEGREE(atan2f(y, z));
|
||||
y = RAD_TO_DEGREE(atan2f(y, z));
|
||||
|
||||
orient->pitch = y;
|
||||
orient->a_pitch = y;
|
||||
@ -181,7 +181,7 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) {
|
||||
rx = applyCalibration(x, js->min.x, js->max.x, js->center.x);
|
||||
ry = applyCalibration(y, js->min.y, js->max.y, js->center.y);
|
||||
/* calculate the joystick angle and magnitude */
|
||||
ang = WIIUSE_RAD_TO_DEGREE(atan2f(ry, rx));
|
||||
ang = RAD_TO_DEGREE(atan2f(ry, rx));
|
||||
js->ang = ang + 180.0f;
|
||||
js->mag = sqrtf((rx * rx) + (ry * ry));
|
||||
}
|
||||
|
@ -661,7 +661,7 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
disable_expansion(wm);
|
||||
}
|
||||
handshake_buf = (byte*)malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||
handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||
/* tell the wiimote to send expansion data */
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
@ -80,7 +80,7 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b
|
||||
*/
|
||||
if (data[16] == 0xFF) {
|
||||
/* get the calibration data */
|
||||
byte* handshake_buf = (byte*)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_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
@ -225,6 +225,7 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
}
|
||||
|
||||
/* step 1 - calibration of accelerometers */
|
||||
if(wm->type != WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE) // MotionPlus Inside wiimotes don't answer to that
|
||||
{
|
||||
struct accel_t* accel = &wm->accel_calib;
|
||||
|
||||
|
@ -598,8 +598,8 @@ static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang) {
|
||||
return;
|
||||
}
|
||||
|
||||
s = sinf(WIIUSE_DEGREE_TO_RAD(ang));
|
||||
c = cosf(WIIUSE_DEGREE_TO_RAD(ang));
|
||||
s = sinf(DEGREE_TO_RAD(ang));
|
||||
c = cosf(DEGREE_TO_RAD(ang));
|
||||
|
||||
/*
|
||||
* [ cos(theta) -sin(theta) ][ ir->rx ]
|
||||
@ -709,7 +709,7 @@ static float ir_distance(struct ir_dot_t* dot) {
|
||||
xd = dot[i2].x - dot[i1].x;
|
||||
yd = dot[i2].y - dot[i1].y;
|
||||
|
||||
return sqrtf((float)(xd * xd + yd * yd));
|
||||
return sqrtf(xd * xd + yd * yd);
|
||||
}
|
||||
|
||||
|
||||
@ -789,5 +789,5 @@ float calc_yaw(struct ir_t* ir) {
|
||||
x = (float)(ir->ax - 512);
|
||||
x = x * (ir->z / 1024.0f);
|
||||
|
||||
return WIIUSE_RAD_TO_DEGREE(atanf(x / ir->z));
|
||||
return RAD_TO_DEGREE(atanf(x / ir->z));
|
||||
}
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include <sys/time.h> /* for struct timeval */
|
||||
#include <unistd.h> /* for close, write */
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address);
|
||||
|
||||
@ -99,13 +100,30 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
|
||||
/* display discovered devices */
|
||||
for (i = 0; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) {
|
||||
if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2)) {
|
||||
bool is_wiimote_regular = (scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2);
|
||||
|
||||
bool is_wiimote_plus = (scan_info[i].dev_class[0] == WM_PLUS_DEV_CLASS_0) &&
|
||||
(scan_info[i].dev_class[1] == WM_PLUS_DEV_CLASS_1) &&
|
||||
(scan_info[i].dev_class[2] == WM_PLUS_DEV_CLASS_2);
|
||||
if (is_wiimote_regular || is_wiimote_plus) {
|
||||
/* found a device */
|
||||
ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str);
|
||||
|
||||
const char* str_type;
|
||||
if(is_wiimote_regular)
|
||||
{
|
||||
wm[found_wiimotes]->type = WIIUSE_WIIMOTE_REGULAR;
|
||||
str_type = " (regular wiimote)";
|
||||
}
|
||||
else if(is_wiimote_plus)
|
||||
{
|
||||
wm[found_wiimotes]->type = WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE;
|
||||
str_type = " (motion plus inside)";
|
||||
}
|
||||
|
||||
WIIUSE_INFO("Found wiimote (%s) [id %i].", wm[found_wiimotes]->bdaddr_str, wm[found_wiimotes]->unid);
|
||||
WIIUSE_INFO("Found wiimote (type: %s) (%s) [id %i].", str_type, wm[found_wiimotes]->bdaddr_str, wm[found_wiimotes]->unid);
|
||||
|
||||
wm[found_wiimotes]->bdaddr = scan_info[i].bdaddr;
|
||||
WIIMOTE_ENABLE_STATE(wm[found_wiimotes], WIIMOTE_STATE_DEV_FOUND);
|
||||
|
@ -90,7 +90,7 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
|
||||
/* get the size of the data block required */
|
||||
i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL);
|
||||
detail_data = (SP_DEVICE_INTERFACE_DETAIL_DATA*)malloc(len);
|
||||
detail_data = (SP_DEVICE_INTERFACE_DETAIL_DATA_A*)malloc(len);
|
||||
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||
|
||||
/* query the data for this device */
|
||||
@ -115,7 +115,7 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
/* this is a wiimote */
|
||||
wm[found]->dev_handle = dev;
|
||||
|
||||
wm[found]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, L"");
|
||||
wm[found]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, "");
|
||||
wm[found]->hid_overlap.Offset = 0;
|
||||
wm[found]->hid_overlap.OffsetHigh = 0;
|
||||
|
||||
|
@ -159,6 +159,8 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
||||
wm[i]->accel_threshold = 5;
|
||||
|
||||
wm[i]->accel_calib.st_alpha = WIIUSE_DEFAULT_SMOOTH_ALPHA;
|
||||
|
||||
wm[i]->type = WIIUSE_WIIMOTE_REGULAR;
|
||||
}
|
||||
|
||||
return wm;
|
||||
|
@ -92,7 +92,9 @@
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
/* windows */
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef WIIUSE_BLUEZ
|
||||
@ -709,6 +711,14 @@ typedef enum WIIUSE_EVENT_TYPE {
|
||||
WIIUSE_MOTION_PLUS_REMOVED
|
||||
} WIIUSE_EVENT_TYPE;
|
||||
|
||||
/**
|
||||
* @brief Type of wiimote peripheral
|
||||
*/
|
||||
typedef enum WIIUSE_WIIMOTE_TYPE {
|
||||
WIIUSE_WIIMOTE_REGULAR = 0,
|
||||
WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE,
|
||||
} WIIUSE_WIIMOTE_TYPE;
|
||||
|
||||
/**
|
||||
* @brief Main Wiimote device structure.
|
||||
*
|
||||
@ -779,6 +789,7 @@ typedef struct wiimote_t {
|
||||
|
||||
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occurred */
|
||||
WCONST byte motion_plus_id[6];
|
||||
WCONST WIIUSE_WIIMOTE_TYPE type;
|
||||
} wiimote;
|
||||
|
||||
/** @brief Data passed to a callback during wiiuse_update() */
|
||||
|
@ -155,9 +155,13 @@
|
||||
#define WM_DEV_MAJOR_CLASS 0x05
|
||||
#define WM_DEV_MAJOR_SERVICE 0x01
|
||||
#else
|
||||
#define WM_DEV_CLASS_0 0x04
|
||||
#define WM_DEV_CLASS_0 0x04 // Regular wiimote
|
||||
#define WM_DEV_CLASS_1 0x25
|
||||
#define WM_DEV_CLASS_2 0x00
|
||||
|
||||
#define WM_PLUS_DEV_CLASS_0 0x08 // For the newer RVL-CNT-01-TR (MotionPlus Inside)
|
||||
#define WM_PLUS_DEV_CLASS_1 0x05
|
||||
#define WM_PLUS_DEV_CLASS_2 0x00
|
||||
#endif
|
||||
#define WM_VENDOR_ID 0x057E
|
||||
#define WM_PRODUCT_ID 0x0306
|
||||
|
Loading…
x
Reference in New Issue
Block a user