mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
MAJOR and long ago overdue wiiuse and real wiimote sourcecode cleanup. Removed "recording" in old wiimote plugin and other not necessary functions(EEPROM reading, we 'll just do a reconnect instead to use default accel calibration data etc). Recording is not needed anymore(playback of recorded moves should be still working). Everything the recording feature offered, the new wiimote plugin does as well and even more. The cleanup will ease the port of the real wiimote feature into new wiimote plugin, which is still only offering emulated wiimote support. Billiard said he's now on it.:)
Wiimotes are now slighty more responsive and multiple wiimotes should harmonize now slighty better. This clean up was requested/inevitable and should have be done way more earlier. This "might" break osx/linux builds, so please test. If your aware of any "real wiimote" issues please post it in the comments as well(dont forget to state your OS). Known wiimote issues: 1.) Possible wiimote disconnect on pressing the home button 2.) 1-2 Possible wiimote disconnects directly after starting a game 3.) Rumble causes lag. I don't think this is a wiimote plugin issue itself, I'm not sure tho. It would be interesting to know whether the lag still happens on emulated wiimotes as well, when the game tries to rumble. 4.) Connecting(pairing up and refreshing) a 2nd/3rd/4th real wiimote while having a game running/paused, might swap player slots and cause disconnects at that moment. If u have more issues, feel free to post them, to have them all here collected once more to get a brief overview. Apart from that, increase the wiimote read timeout @settings(20-200). If your expecting frequent disconnects, restart dolphin, and don't open the wiimote gui before playing instead directly start games. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5788 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Vendored
+1
-17
@@ -611,18 +611,11 @@ WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
|
||||
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
|
||||
/* connect.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
@@ -633,20 +626,11 @@ WIIUSE_EXPORT extern int wiiuse_check_system_notification(unsigned int nMsg, WPA
|
||||
WIIUSE_EXPORT extern int wiiuse_register_system_notification(HWND hwnd);
|
||||
#endif
|
||||
|
||||
/* events.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
|
||||
|
||||
/* ir.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
|
||||
/* nunchuk.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
/* io.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_io_read(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len);
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
-5
@@ -48,14 +48,9 @@ INCLUDES = -I.
|
||||
# Generate a list of object files
|
||||
#
|
||||
OBJS = \
|
||||
$(OBJ_DIR)/classic.o \
|
||||
$(OBJ_DIR)/dynamics.o \
|
||||
$(OBJ_DIR)/events.o \
|
||||
$(OBJ_DIR)/io.o \
|
||||
$(OBJ_DIR)/io_nix.o \
|
||||
$(OBJ_DIR)/ir.o \
|
||||
$(OBJ_DIR)/nunchuk.o \
|
||||
$(OBJ_DIR)/guitar_hero_3.o \
|
||||
$(OBJ_DIR)/wiiuse.o
|
||||
|
||||
###############################
|
||||
|
||||
Vendored
-6
@@ -8,14 +8,8 @@ if (env['HAVE_BLUEZ'] != 1 and sys.platform != 'darwin'):
|
||||
Return()
|
||||
|
||||
files = [
|
||||
"classic.c",
|
||||
"dynamics.c",
|
||||
"events.c",
|
||||
"io.c",
|
||||
"ir.c",
|
||||
"nunchuk.c",
|
||||
"guitar_hero_3.c",
|
||||
"wiiboard.c",
|
||||
"wiiuse.c",
|
||||
]
|
||||
|
||||
|
||||
Vendored
-188
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "classic.h"
|
||||
|
||||
static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the classic controller.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @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 offset = 0;
|
||||
|
||||
cc->btns = 0;
|
||||
cc->btns_held = 0;
|
||||
cc->btns_released = 0;
|
||||
cc->r_shoulder = 0;
|
||||
cc->l_shoulder = 0;
|
||||
|
||||
/* 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("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;
|
||||
cc->ljs.min.x = data[1 + offset] / 4;
|
||||
cc->ljs.center.x = data[2 + offset] / 4;
|
||||
cc->ljs.max.y = data[3 + offset] / 4;
|
||||
cc->ljs.min.y = data[4 + offset] / 4;
|
||||
cc->ljs.center.y = data[5 + offset] / 4;
|
||||
|
||||
cc->rjs.max.x = data[6 + offset] / 8;
|
||||
cc->rjs.min.x = data[7 + offset] / 8;
|
||||
cc->rjs.center.x = data[8 + offset] / 8;
|
||||
cc->rjs.max.y = data[9 + offset] / 8;
|
||||
cc->rjs.min.y = data[10 + offset] / 8;
|
||||
cc->rjs.center.y = data[11 + offset] / 8;
|
||||
|
||||
/* handshake done */
|
||||
wm->expansion.type = EXP_CLASSIC;
|
||||
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The classic controller disconnected.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
*/
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc) {
|
||||
memset(cc, 0, sizeof(struct classic_ctrl_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle classic controller event.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg) {
|
||||
int i;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
classic_ctrl_pressed_buttons(cc, BIG_ENDIAN_SHORT(*(short*)(msg + 4)));
|
||||
|
||||
/* left/right buttons */
|
||||
cc->ls_raw = (((msg[2] & 0x60) >> 2) | ((msg[3] & 0xE0) >> 5));
|
||||
cc->rs_raw = (msg[3] & 0x1F);
|
||||
|
||||
/*
|
||||
* TODO - LR range hardcoded from 0x00 to 0x1F.
|
||||
* This is probably in the calibration somewhere.
|
||||
*/
|
||||
cc->r_shoulder = ((float)cc->rs_raw / 0x1F);
|
||||
cc->l_shoulder = ((float)cc->ls_raw / 0x1F);
|
||||
|
||||
/* calculate joystick orientation */
|
||||
|
||||
cc->ljs.pos.x = (msg[0] & 0x3F);
|
||||
cc->ljs.pos.y = (msg[1] & 0x3F);
|
||||
cc->rjs.pos.x = ((msg[0] & 0xC0) >> 3) | ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7);
|
||||
cc->rjs.pos.y = (msg[2] & 0x1F);
|
||||
|
||||
calc_joystick_state(&cc->ljs, cc->ljs.pos.x, cc->ljs.pos.y);
|
||||
calc_joystick_state(&cc->rjs, cc->rjs.pos.x, cc->rjs.pos.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & CLASSIC_CTRL_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
cc->btns_held = (now & cc->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
cc->btns_released = ((cc->btns | cc->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
cc->btns = now;
|
||||
}
|
||||
Vendored
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
|
||||
#ifndef CLASSIC_H_INCLUDED
|
||||
#define CLASSIC_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len);
|
||||
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc);
|
||||
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CLASSIC_H_INCLUDED
|
||||
Vendored
-276
@@ -1,276 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles the dynamics of the wiimote.
|
||||
*
|
||||
* The file includes functions that handle the dynamics
|
||||
* of the wiimote. Such dynamics include orientation and
|
||||
* motion sensing.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "ir.h"
|
||||
#include "dynamics.h"
|
||||
|
||||
/**
|
||||
* @brief Calculate the roll, pitch, yaw.
|
||||
*
|
||||
* @param ac An accelerometer (accel_t) structure.
|
||||
* @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data.
|
||||
* @param orient [out] Pointer to a orient_t structure that will hold the orientation data.
|
||||
* @param rorient [out] Pointer to a orient_t structure that will hold the non-smoothed orientation data.
|
||||
* @param smooth If smoothing should be performed on the angles calculated. 1 to enable, 0 to disable.
|
||||
*
|
||||
* Given the raw acceleration data from the accelerometer struct, calculate
|
||||
* the orientation of the device and set it in the \a orient parameter.
|
||||
*/
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth) {
|
||||
float xg, yg, zg;
|
||||
float x, y, z;
|
||||
|
||||
/*
|
||||
* roll - use atan(z / x) [ ranges from -180 to 180 ]
|
||||
* pitch - use atan(z / y) [ ranges from -180 to 180 ]
|
||||
* yaw - impossible to tell without IR
|
||||
*/
|
||||
|
||||
/* yaw - set to 0, IR will take care of it if it's enabled */
|
||||
orient->yaw = 0.0f;
|
||||
|
||||
/* find out how much it has to move to be 1g */
|
||||
xg = (float)ac->cal_g.x;
|
||||
yg = (float)ac->cal_g.y;
|
||||
zg = (float)ac->cal_g.z;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
x = ((float)accel->x - (float)ac->cal_zero.x) / xg;
|
||||
y = ((float)accel->y - (float)ac->cal_zero.y) / yg;
|
||||
z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||
|
||||
/* make sure x,y,z are between -1 and 1 for the tan functions */
|
||||
if (x < -1.0f) x = -1.0f;
|
||||
else if (x > 1.0f) x = 1.0f;
|
||||
if (y < -1.0f) y = -1.0f;
|
||||
else if (y > 1.0f) y = 1.0f;
|
||||
if (z < -1.0f) z = -1.0f;
|
||||
else if (z > 1.0f) z = 1.0f;
|
||||
|
||||
/* 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 = RAD_TO_DEGREE(atan2f(x, z));
|
||||
|
||||
orient->roll = x;
|
||||
orient->a_roll = x;
|
||||
}
|
||||
|
||||
if (abs(accel->y - ac->cal_zero.y) <= ac->cal_g.y) {
|
||||
/* pitch */
|
||||
y = RAD_TO_DEGREE(atan2f(y, z));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the gravity forces on each axis.
|
||||
*
|
||||
* @param ac An accelerometer (accel_t) structure.
|
||||
* @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data.
|
||||
* @param gforce [out] Pointer to a gforce_t structure that will hold the gravity force data.
|
||||
*/
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce) {
|
||||
float xg, yg, zg;
|
||||
|
||||
/* find out how much it has to move to be 1g */
|
||||
xg = (float)ac->cal_g.x;
|
||||
yg = (float)ac->cal_g.y;
|
||||
zg = (float)ac->cal_g.z;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
gforce->x = ((float)accel->x - (float)ac->cal_zero.x) / xg;
|
||||
gforce->y = ((float)accel->y - (float)ac->cal_zero.y) / yg;
|
||||
gforce->z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the angle and magnitude of a joystick.
|
||||
*
|
||||
* @param js [out] Pointer to a joystick_t structure.
|
||||
* @param x The raw x-axis value.
|
||||
* @param y The raw y-axis value.
|
||||
*/
|
||||
void calc_joystick_state(struct joystick_t* js, float x, float y) {
|
||||
float rx, ry, ang;
|
||||
|
||||
/*
|
||||
* Since the joystick center may not be exactly:
|
||||
* (min + max) / 2
|
||||
* Then the range from the min to the center and the center to the max
|
||||
* may be different.
|
||||
* Because of this, depending on if the current x or y value is greater
|
||||
* or less than the assoicated axis center value, it needs to be interpolated
|
||||
* between the center and the minimum or maxmimum rather than between
|
||||
* the minimum and maximum.
|
||||
*
|
||||
* So we have something like this:
|
||||
* (x min) [-1] ---------*------ [0] (x center) [0] -------- [1] (x max)
|
||||
* Where the * is the current x value.
|
||||
* The range is therefore -1 to 1, 0 being the exact center rather than
|
||||
* the middle of min and max.
|
||||
*/
|
||||
if (x == js->center.x)
|
||||
rx = 0;
|
||||
else if (x >= js->center.x)
|
||||
rx = ((float)(x - js->center.x) / (float)(js->max.x - js->center.x));
|
||||
else
|
||||
rx = ((float)(x - js->min.x) / (float)(js->center.x - js->min.x)) - 1.0f;
|
||||
|
||||
if (y == js->center.y)
|
||||
ry = 0;
|
||||
else if (y >= js->center.y)
|
||||
ry = ((float)(y - js->center.y) / (float)(js->max.y - js->center.y));
|
||||
else
|
||||
ry = ((float)(y - js->min.y) / (float)(js->center.y - js->min.y)) - 1.0f;
|
||||
|
||||
/* calculate the joystick angle and magnitude */
|
||||
ang = RAD_TO_DEGREE(atanf(ry / rx));
|
||||
ang -= 90.0f;
|
||||
if (rx < 0.0f)
|
||||
ang -= 180.0f;
|
||||
js->ang = absf(ang);
|
||||
js->mag = (float) sqrt((rx * rx) + (ry * ry));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
/*
|
||||
* If the sign changes (which will happen if going from -180 to 180)
|
||||
* or from (-1 to 1) then don't smooth, just use the new angle.
|
||||
*/
|
||||
if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) {
|
||||
ac->st_roll = orient->roll;
|
||||
} else {
|
||||
orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll));
|
||||
ac->st_roll = orient->roll;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
case SMOOTH_PITCH:
|
||||
{
|
||||
if (isnan(ac->st_pitch) || isinf(ac->st_pitch))
|
||||
ac->st_pitch = 0.0f;
|
||||
|
||||
if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) {
|
||||
ac->st_pitch = orient->pitch;
|
||||
} else {
|
||||
orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch));
|
||||
ac->st_pitch = orient->pitch;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void calc_balanceboard_state(struct wii_board_t *wb)
|
||||
{
|
||||
/*
|
||||
Interpolate values
|
||||
Calculations borrowed from wiili.org - No names to mention sadly :( http://www.wiili.org/index.php/Wii_Balance_Board_PC_Drivers
|
||||
*/
|
||||
|
||||
if(wb->rtr<wb->ctr[1])
|
||||
{
|
||||
wb->tr = 17.0f*(float)(wb->rtr-wb->ctr[0])/(float)(wb->ctr[1]-wb->ctr[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
wb->tr = 17.0f*(float)(wb->rtr-wb->ctr[1])/(float)(wb->ctr[2]-wb->ctr[1]) + 17.0f;
|
||||
}
|
||||
|
||||
if(wb->rtl<wb->ctl[1])
|
||||
{
|
||||
wb->tl = 17.0f*(float)(wb->rtl-wb->ctl[0])/(float)(wb->ctl[1]-wb->ctl[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
wb->tl = 17.0f*(float)(wb->rtl-wb->ctl[1])/(float)(wb->ctl[2]-wb->ctl[1]) + 17.0f;
|
||||
}
|
||||
|
||||
if(wb->rbr<wb->cbr[1])
|
||||
{
|
||||
wb->br = 17.0f*(float)(wb->rbr-wb->cbr[0])/(float)(wb->cbr[1]-wb->cbr[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
wb->br = 17.0f*(float)(wb->rbr-wb->cbr[1])/(float)(wb->cbr[2]-wb->cbr[1]) + 17.0f;
|
||||
}
|
||||
|
||||
if(wb->rbl<wb->cbl[1])
|
||||
{
|
||||
wb->bl = 17.0f*(float)(wb->rbl-wb->cbl[0])/(float)(wb->cbl[1]-wb->cbl[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
wb->bl = 17.0f*(float)(wb->rbl-wb->cbl[1])/(float)(wb->cbl[2]-wb->cbl[1]) + 17.0f;
|
||||
}
|
||||
|
||||
wb->x = (wb->tr+wb->br) - (wb->tl+wb->bl)/2.0f;
|
||||
wb->y = (wb->bl+wb->br) - (wb->tl+wb->tr)/2.0f;
|
||||
}
|
||||
Vendored
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles the dynamics of the wiimote.
|
||||
*
|
||||
* The file includes functions that handle the dynamics
|
||||
* of the wiimote. Such dynamics include orientation and
|
||||
* motion sensing.
|
||||
*/
|
||||
|
||||
#ifndef DYNAMICS_H_INCLUDED
|
||||
#define DYNAMICS_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth);
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce);
|
||||
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 calc_balanceboard_state(struct wii_board_t *wb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DYNAMICS_H_INCLUDED
|
||||
Vendored
-810
File diff suppressed because it is too large
Load Diff
Vendored
-54
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles wiimote events.
|
||||
*
|
||||
* The file includes functions that handle the events
|
||||
* that are sent from the wiimote to us.
|
||||
*/
|
||||
|
||||
#ifndef EVENTS_H_INCLUDED
|
||||
#define EVENTS_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg);
|
||||
|
||||
void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len);
|
||||
void disable_expansion(struct wiimote_t* wm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // EVENTS_H_INCLUDED
|
||||
-177
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "guitar_hero_3.h"
|
||||
|
||||
static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the guitar.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @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) {
|
||||
/*
|
||||
* The good fellows that made the Guitar Hero 3 controller
|
||||
* failed to factory calibrate the devices. There is no
|
||||
* calibration data on the device.
|
||||
*/
|
||||
|
||||
gh3->btns = 0;
|
||||
gh3->btns_held = 0;
|
||||
gh3->btns_released = 0;
|
||||
gh3->wb_raw = 0;
|
||||
gh3->whammy_bar = 0.0f;
|
||||
gh3->tb_raw = 0;
|
||||
gh3->touch_bar = -1;
|
||||
|
||||
/* joystick stuff */
|
||||
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;
|
||||
gh3->js.min.x = GUITAR_HERO_3_JS_MIN_X;
|
||||
gh3->js.center.x = GUITAR_HERO_3_JS_CENTER_X;
|
||||
gh3->js.max.y = GUITAR_HERO_3_JS_MAX_Y;
|
||||
gh3->js.min.y = GUITAR_HERO_3_JS_MIN_Y;
|
||||
gh3->js.center.y = GUITAR_HERO_3_JS_CENTER_Y;
|
||||
|
||||
/* handshake done */
|
||||
wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED;
|
||||
wm->expansion.type = EXP_GUITAR_HERO_3;
|
||||
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The guitar disconnected.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
*/
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3) {
|
||||
memset(gh3, 0, sizeof(struct guitar_hero_3_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle guitar event.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg) {
|
||||
int i;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
guitar_hero_3_pressed_buttons(gh3, BIG_ENDIAN_SHORT(*(short*)(msg + 4)));
|
||||
|
||||
gh3->js.pos.x = (msg[0] & GUITAR_HERO_3_JS_MASK);
|
||||
gh3->js.pos.y = (msg[1] & GUITAR_HERO_3_JS_MASK);
|
||||
gh3->tb_raw = (msg[2] & GUITAR_HERO_3_TOUCH_MASK);
|
||||
gh3->wb_raw = (msg[3] & GUITAR_HERO_3_WHAMMY_MASK);
|
||||
|
||||
/* touch bar */
|
||||
gh3->touch_bar = 0;
|
||||
if (gh3->tb_raw > 0x1B)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_ORANGE;
|
||||
else if (gh3->tb_raw > 0x18)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_ORANGE | GUITAR_HERO_3_TOUCH_BLUE;
|
||||
else if (gh3->tb_raw > 0x15)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_BLUE;
|
||||
else if (gh3->tb_raw > 0x13)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_BLUE | GUITAR_HERO_3_TOUCH_YELLOW;
|
||||
else if (gh3->tb_raw > 0x10)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_YELLOW;
|
||||
else if (gh3->tb_raw > 0x0D)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_AVAILABLE;
|
||||
else if (gh3->tb_raw > 0x0B)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_YELLOW | GUITAR_HERO_3_TOUCH_RED;
|
||||
else if (gh3->tb_raw > 0x08)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_RED;
|
||||
else if (gh3->tb_raw > 0x05)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_RED | GUITAR_HERO_3_TOUCH_GREEN;
|
||||
else if (gh3->tb_raw > 0x02)
|
||||
gh3->touch_bar = GUITAR_HERO_3_TOUCH_GREEN;
|
||||
|
||||
/* whammy bar */
|
||||
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, gh3->js.pos.x, gh3->js.pos.y);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now) {
|
||||
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & GUITAR_HERO_3_BUTTON_ALL;
|
||||
|
||||
/* preserve old btns pressed */
|
||||
gh3->btns_last = gh3->btns;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
gh3->btns_held = (now & gh3->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
gh3->btns_released = ((gh3->btns | gh3->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
gh3->btns = now;
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
|
||||
#ifndef GUITAR_HERO_3_H_INCLUDED
|
||||
#define GUITAR_HERO_3_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#define GUITAR_HERO_3_JS_MASK 0x3F
|
||||
#define GUITAR_HERO_3_TOUCH_MASK 0x1F
|
||||
#define GUITAR_HERO_3_WHAMMY_MASK 0x1F
|
||||
|
||||
#define GUITAR_HERO_3_JS_MIN_X 0x05
|
||||
#define GUITAR_HERO_3_JS_MAX_X 0x3C
|
||||
#define GUITAR_HERO_3_JS_CENTER_X 0x20
|
||||
#define GUITAR_HERO_3_JS_MIN_Y 0x05
|
||||
#define GUITAR_HERO_3_JS_MAX_Y 0x3A
|
||||
#define GUITAR_HERO_3_JS_CENTER_Y 0x20
|
||||
#define GUITAR_HERO_3_WHAMMY_BAR_MIN 0x0F
|
||||
#define GUITAR_HERO_3_WHAMMY_BAR_MAX 0x1A
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len);
|
||||
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3);
|
||||
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GUITAR_HERO_3_H_INCLUDED
|
||||
Vendored
-10
@@ -95,20 +95,10 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
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);
|
||||
|
||||
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)) {
|
||||
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Vendored
+1
-1
@@ -120,7 +120,7 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* do the handshake */
|
||||
/* do the handshake * shouldn't be needed as well, I'm gonna leave first it tho*/
|
||||
wiiuse_handshake(wm[found], NULL, 0);
|
||||
|
||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid);
|
||||
|
||||
Vendored
-550
File diff suppressed because it is too large
Load Diff
Vendored
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles IR data.
|
||||
*/
|
||||
|
||||
#ifndef IR_H_INCLUDED
|
||||
#define IR_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#define WII_VRES_X 560
|
||||
#define WII_VRES_Y 340
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void calculate_basic_ir(struct wiimote_t* wm, byte* data);
|
||||
void calculate_extended_ir(struct wiimote_t* wm, byte* data);
|
||||
float calc_yaw(struct ir_t* ir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // IR_H_INCLUDED
|
||||
|
||||
|
||||
Vendored
-231
@@ -1,231 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "nunchuk.h"
|
||||
|
||||
static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the nunchuk.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @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;
|
||||
|
||||
nc->btns = 0;
|
||||
nc->btns_held = 0;
|
||||
nc->btns_released = 0;
|
||||
|
||||
/* set the smoothing to the same as the wiimote */
|
||||
nc->flags = &wm->flags;
|
||||
nc->accel_calib.st_alpha = wm->accel_calib.st_alpha;
|
||||
|
||||
/* 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("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];
|
||||
nc->accel_calib.cal_zero.y = data[offset + 1];
|
||||
nc->accel_calib.cal_zero.z = data[offset + 2];
|
||||
nc->accel_calib.cal_g.x = data[offset + 4];
|
||||
nc->accel_calib.cal_g.y = data[offset + 5];
|
||||
nc->accel_calib.cal_g.z = data[offset + 6];
|
||||
nc->js.max.x = data[offset + 8];
|
||||
nc->js.min.x = data[offset + 9];
|
||||
nc->js.center.x = data[offset + 10];
|
||||
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->expansion.type = EXP_NUNCHUK;
|
||||
|
||||
/* 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.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.y = nc->js.center.y - 80;
|
||||
if (nc->js.max.y == 0) nc->js.max.y = nc->js.center.y + 80;
|
||||
}
|
||||
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The nunchuk disconnected.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
*/
|
||||
void nunchuk_disconnected(struct nunchuk_t* nc) {
|
||||
memset(nc, 0, sizeof(struct nunchuk_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle nunchuk event.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void nunchuk_event(struct nunchuk_t* nc, byte* msg) {
|
||||
int i;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
/* get button states */
|
||||
nunchuk_pressed_buttons(nc, msg[5]);
|
||||
|
||||
nc->js.pos.x = msg[0];
|
||||
nc->js.pos.y = msg[1];
|
||||
|
||||
/* extend min and max values to physical range of motion */
|
||||
if (nc->js.center.x) {
|
||||
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 > 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];
|
||||
nc->accel.z = msg[4];
|
||||
|
||||
calculate_orientation(&nc->accel_calib, &nc->accel, &nc->orient, NUNCHUK_IS_FLAG_SET(nc, WIIUSE_SMOOTHING));
|
||||
calculate_gforce(&nc->accel_calib, &nc->accel, &nc->gforce);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param nc Pointer to a nunchuk_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & NUNCHUK_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
nc->btns_held = (now & nc->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
nc->btns_released = ((nc->btns | nc->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
nc->btns = now;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the orientation event threshold for the nunchuk.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure with a nunchuk attached.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->expansion.nunchuk.orient_threshold = threshold;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the accelerometer event threshold for the nunchuk.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure with a nunchuk attached.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->expansion.nunchuk.accel_threshold = threshold;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user