revert r4308 - that change was executed quite badly. Let's try and keep things sane...

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4310 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2009-09-21 20:05:42 +00:00
parent 10962d5e10
commit 72f443c5ce
9 changed files with 52 additions and 243 deletions

View File

@ -179,9 +179,6 @@ 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;
/* preserve old btns pressed */
cc->btns_last = cc->btns;
/* pressed now & were pressed, then held */
cc->btns_held = (now & cc->btns);

View File

@ -57,7 +57,6 @@
#include "classic.h"
#include "guitar_hero_3.h"
#include "wiiboard.h"
#include "motion_plus.h"
#include "events.h"
static void idle_cycle(struct wiimote_t* wm);
@ -309,9 +308,6 @@ void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg) {
/* convert to big endian */
now = BIG_ENDIAN_SHORT(*(short*)msg) & WIIMOTE_BUTTON_ALL;
/* preserve old btns pressed */
wm->btns_last = wm->btns;
/* pressed now & were pressed, then held */
wm->btns_held = (now & wm->btns);
@ -446,6 +442,7 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
int led[4] = {0};
int attachment = 0;
int ir = 0;
int exp_changed = 0;
/*
* An event occured.
@ -477,34 +474,17 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
/* find the battery level and normalize between 0 and 1 */
wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE);
if(!ir && WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR_INIT)) {
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR_INIT);
wiiuse_set_ir(wm, 1);
goto done;
}
if(ir && !WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) WIIMOTE_ENABLE_STATE(wm,WIIMOTE_STATE_IR);
/* expansion port */
if (attachment){
if(!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP) && !WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP_FAILED && !WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP_HANDSHAKE))) {
if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
/* send the initialization code for the attachment */
handshake_expansion(wm, NULL, 0);
goto done;
}
} else{
WIIMOTE_DISABLE_STATE(wm,WIIMOTE_STATE_EXP_FAILED);
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
exp_changed = 1;
} else if (!attachment && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
/* attachment removed */
disable_expansion(wm);
goto done;
}
exp_changed = 1;
}
wiiuse_set_report_type(wm);
done:
#ifdef WIN32
if (!attachment) {
WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout);
@ -512,6 +492,20 @@ done:
}
#endif
/*
* From now on the remote will only send status packets.
* We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
* reenable other incoming reports.
*/
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
/*
* Since the expansion status changed IR needs to
* be reset for the new IR report mode.
*/
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1);
} else
wiiuse_set_report_type(wm);
}
@ -610,7 +604,6 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len) {
wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED;
break;
}
default:
{
WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", wid);
@ -655,16 +648,11 @@ void disable_expansion(struct wiimote_t* wm) {
wii_board_disconnected(&wm->exp.wb);
wm->event = WIIUSE_WII_BOARD_CTRL_REMOVED;
break;
case EXP_MOTION_PLUS:
motion_plus_disconnected(&wm->exp.mp);
wm->event = WIIUSE_MOTION_PLUS_CTRL_REMOVED;
break;
default:
break;
}
WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_EXP|WIIMOTE_STATE_EXP_HANDSHAKE));
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
wm->exp.type = EXP_NONE;
}
@ -808,18 +796,12 @@ static int state_changed(struct wiimote_t* wm) {
}
case EXP_WII_BOARD:
{
STATE_CHANGED(wm->exp.wb.rtl, wm->lstate.exp.wb.rtl);
STATE_CHANGED(wm->exp.wb.rtr, wm->lstate.exp.wb.rtr);
STATE_CHANGED(wm->exp.wb.rbl, wm->lstate.exp.wb.rbl);
STATE_CHANGED(wm->exp.wb.rbr, wm->lstate.exp.wb.rbr);
STATE_CHANGED(wm->exp.wb.ltr,wm->exp.wb.tr);
STATE_CHANGED(wm->exp.wb.ltl,wm->exp.wb.tl);
STATE_CHANGED(wm->exp.wb.lbr,wm->exp.wb.br);
STATE_CHANGED(wm->exp.wb.lbl,wm->exp.wb.bl);
break;
}
case EXP_MOTION_PLUS:
{
STATE_CHANGED(wm->lstate.exp.mp.rx, wm->exp.mp.rx);
STATE_CHANGED(wm->lstate.exp.mp.ry, wm->exp.mp.ry);
STATE_CHANGED(wm->lstate.exp.mp.rz, wm->exp.mp.rz);
}
case EXP_NONE:
{
break;

View File

@ -176,10 +176,10 @@ void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg) {
gh3->touch_bar = GUITAR_HERO_3_TOUCH_GREEN;
/* whammy bar */
gh3->whammy_bar = (gh3->wb_raw - GUITAR_HERO_3_WHAMMY_BAR_MIN) / (float)(GUITAR_HERO_3_WHAMMY_BAR_MAX - GUITAR_HERO_3_WHAMMY_BAR_MIN);
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);
calc_joystick_state(&gh3->js, msg[0], msg[1]);
}

View File

@ -51,26 +51,6 @@ static float ir_distance(struct ir_dot_t* dot);
static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offset_x, int offset_y);
static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, unsigned int vx, unsigned int vy);
/**
* @brief Set if the wiimote IR mode.
*
* @param wm Pointer to a wiimote_t structure.
*/
void wiiuse_set_ir_mode(struct wiimote_t *wm)
{
byte buf = 0x00;
if(!wm) return;
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) return;
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP))
buf = WM_IR_TYPE_BASIC;
else
buf = WM_IR_TYPE_EXTENDED;
wiiuse_write_data(wm,WM_REG_IR_MODENUM, &buf, 1);
}
/**
* @brief Set if the wiimote should track IR targets.
@ -95,10 +75,7 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
*/
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE)) {
WIIUSE_DEBUG("Tried to enable IR, will wait until handshake finishes.");
if(status)
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
else
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR_INIT);
return;
}
@ -150,11 +127,11 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
/* set the IR mode */
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP))
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
buf = WM_IR_TYPE_BASIC;
else
buf = WM_IR_TYPE_EXTENDED;
wiiuse_write_data(wm,WM_REG_IR_MODENUM, &buf, 1);
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
#ifndef WIN32
usleep(50000);
@ -163,7 +140,7 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
#endif
/* set the wiimote report type */
wiiuse_status(wm);
wiiuse_set_report_type(wm);
WIIUSE_DEBUG("Enabled IR camera for wiimote id %i (sensitivity level %i).", wm->unid, ir_level);
}
@ -327,8 +304,6 @@ void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) {
return;
}
if(!WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) return;
/* set the new sensitivity */
get_ir_sens(wm, &block1, &block2);

View File

@ -1,93 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#ifdef WIN32
#include <Winsock2.h>
#endif
#include "definitions.h"
#include "wiiuse_internal.h"
#include "dynamics.h"
#include "events.h"
#include "wiiboard.h"
#include "io.h"
void wiiuse_motion_plus_check(struct wiimote_t *wm,ubyte *data,uword len)
{
u32 val;
if(data == NULL)
{
wiiuse_read_data(wm, wm->motion_plus_id, WM_EXP_ID, 6, wiiuse_motion_plus_check);
}
else
{
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
val = (data[3] << 16) | (data[2] << 24) | (data[4] << 8) | data[5];
if(val == EXP_ID_CODE_MOTION_PLUS)
{
/* handshake done */
wm->event = WIIUSE_MOTION_PLUS_ACTIVATED;
wm->exp.type = EXP_MOTION_PLUS;
WIIMOTE_ENABLE_STATE(wm,WIIMOTE_STATE_EXP);
wiiuse_set_ir_mode(wm);
}
}
}
static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm,ubyte *data,uword len)
{
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
wiiuse_set_ir_mode(wm);
wiiuse_status(wm,NULL);
}
static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm,ubyte *data,uword len)
{
ubyte val = 0x00;
wiiuse_write_data(wm,WM_EXP_MEM_ENABLE1,&val,1,wiiuse_set_motion_plus_clear2);
}
void wiiuse_set_motion_plus(struct wiimote_t *wm, int status)
{
ubyte val;
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP_HANDSHAKE))
return;
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
if(status)
{
val = 0x04;
wiiuse_write_data(wm,WM_EXP_MOTION_PLUS_ENABLE,&val,1,wiiuse_motion_plus_check);
}
else
{
wiiuse_disable_expansion(wm);
val = 0x55;
wiiuse_write_data(wm,WM_EXP_MEM_ENABLE1,&val,1,wiiuse_set_motion_plus_clear1);
}
}
void motion_plus_disconnected(struct motion_plus_t* mp)
{
WIIUSE_DEBUG("Motion plus disconnected");
memset(mp, 0, sizeof(struct motion_plus_t));
}
void motion_plus_event(struct motion_plus_t* mp, ubyte* msg)
{
mp->rx = ((msg[5] & 0xFC) << 6) | msg[2]; // Pitch
mp->ry = ((msg[4] & 0xFC) << 6) | msg[1]; // Roll
mp->rz = ((msg[3] & 0xFC) << 6) | msg[0]; // Yaw
mp->ext = msg[4] & 0x1;
mp->status = (msg[3] & 0x3) | ((msg[4] & 0x2) << 1); // roll, yaw, pitch
}

View File

@ -1,23 +0,0 @@
/**
* @file
* @brief Motion plus extension
*/
#ifndef MOTION_PLUS_H_INCLUDED
#define MOTION_PLUS_H_INCLUDED
#include "wiiuse_internal.h"
#ifdef __cplusplus
extern "C" {
#endif
void motion_plus_disconnected(struct motion_plus_t* mp);
void motion_plus_event(struct motion_plus_t* mp, byte* msg);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -189,9 +189,6 @@ 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;
/* preserve old btns pressed */
nc->btns_last = nc->btns;
/* pressed now & were pressed, then held */
nc->btns_held = (now & nc->btns);

View File

@ -138,7 +138,6 @@
#define EXP_CLASSIC 2
#define EXP_GUITAR_HERO_3 3
#define EXP_WII_BOARD 4
#define EXP_MOTION_PLUS 5
/* IR correction types */
typedef enum ir_position_t {
@ -215,8 +214,8 @@ typedef enum ir_position_t {
* be a useful feature to keep so it wasn't removed.
*/
#ifdef WIN32
#define WIIMOTE_DEFAULT_TIMEOUT 100
#define WIIMOTE_EXP_TIMEOUT 100
#define WIIMOTE_DEFAULT_TIMEOUT 10
#define WIIMOTE_EXP_TIMEOUT 10
#endif
typedef unsigned char byte;
@ -419,7 +418,6 @@ typedef struct nunchuk_t {
int* flags; /**< options flag (points to wiimote_t.flags) */
byte btns; /**< what buttons have just been pressed */
byte btns_last; /**< what buttons have just been pressed */
byte btns_held; /**< what buttons are being held down */
byte btns_released; /**< what buttons were just released this */
@ -438,7 +436,6 @@ typedef struct nunchuk_t {
*/
typedef struct classic_ctrl_t {
short btns; /**< what buttons have just been pressed */
short btns_last; /**< what buttons have just been pressed */
short btns_held; /**< what buttons are being held down */
short btns_released; /**< what buttons were just released this */
@ -493,13 +490,6 @@ typedef struct wii_board_t {
float y;
} wii_board_t;
typedef struct motion_plus_t
{
short rx, ry, rz;
byte status;
byte ext;
} motion_plus_t;
/**
* @struct expansion_t
* @brief Generic expansion device plugged into wiimote.
@ -512,7 +502,6 @@ typedef struct expansion_t {
struct classic_ctrl_t classic;
struct guitar_hero_3_t gh3;
struct wii_board_t wb;
struct motion_plus_t mp;
};
} expansion_t;
@ -553,8 +542,6 @@ typedef struct wiimote_state_t {
unsigned short btns;
struct vec3b_t accel;
struct expansion_t exp;
} wiimote_state_t;
@ -577,9 +564,7 @@ typedef enum WIIUSE_EVENT_TYPE {
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED,
WIIUSE_WII_BOARD_CTRL_INSERTED,
WIIUSE_WII_BOARD_CTRL_REMOVED,
WIIUSE_MOTION_PLUS_CTRL_REMOVED,
WIIUSE_MOTION_PLUS_CTRL_INSERTED
WIIUSE_WII_BOARD_CTRL_REMOVED
} WIIUSE_EVENT_TYPE;
/**
@ -626,7 +611,6 @@ typedef struct wiimote_t {
WCONST struct ir_t ir; /**< IR data */
WCONST unsigned short btns; /**< what buttons have just been pressed */
WCONST unsigned short btns_last; /**< what buttons have just been pressed */
WCONST unsigned short btns_held; /**< what buttons are being held down */
WCONST unsigned short btns_released; /**< what buttons were just released this */
@ -637,8 +621,6 @@ typedef struct wiimote_t {
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
WCONST byte motion_plus_id[6];
} wiimote;
@ -714,9 +696,6 @@ WIIUSE_EXPORT extern int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int le
/* Balance Board */
WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
/* motion_plus.c */
WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status);
#ifdef __cplusplus
}
#endif

View File

@ -157,7 +157,6 @@
#define EXP_ID_CODE_WII_BOARD 0xa4200402 //Find the encrypted epansion id code
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD
#define EXP_ID_CODE_GUITAR 0x9A1EFDFB
#define EXP_ID_CODE_MOTION_PLUS 0xa4200405 //Find the encrypted epansion id code
#define EXP_HANDSHAKE_LEN 224
@ -168,24 +167,20 @@
********************/
/* wiimote state flags - (some duplicated in wiiuse.h)*/
#define WIIMOTE_STATE_DEV_FOUND 0x00001
//#define WIIMOTE_STATE_DEV_REGISTER 0x00002
#define WIIMOTE_STATE_HANDSHAKE 0x00004 /* actual connection exists but no handshake yet */
#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x00008 /* actual connection exists but no handshake yet */
#define WIIMOTE_STATE_CONNECTED 0x00010
#define WIIMOTE_STATE_EXP_HANDSHAKE 0x00020 /* actual connection exists but no handshake yet */
#define WIIMOTE_STATE_EXP_FAILED 0x00040 /* actual connection exists but no handshake yet */
#define WIIMOTE_STATE_RUMBLE 0x00100
#define WIIMOTE_STATE_ACC 0x00100
#define WIIMOTE_STATE_EXP 0x00200
#define WIIMOTE_STATE_IR 0x00400
#define WIIMOTE_STATE_SPEAKER 0x00800
#define WIIMOTE_STATE_IR_SENS_LVL1 0x01000
#define WIIMOTE_STATE_IR_SENS_LVL2 0x02000
#define WIIMOTE_STATE_IR_SENS_LVL3 0x04000
#define WIIMOTE_STATE_IR_SENS_LVL4 0x08000
#define WIIMOTE_STATE_IR_SENS_LVL5 0x10000
#define WIIMOTE_STATE_IR_INIT 0x20000
#define WIIMOTE_STATE_DEV_FOUND 0x0001
#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
#define WIIMOTE_STATE_CONNECTED 0x0008
#define WIIMOTE_STATE_RUMBLE 0x0010
#define WIIMOTE_STATE_ACC 0x0020
#define WIIMOTE_STATE_EXP 0x0040
#define WIIMOTE_STATE_IR 0x0080
#define WIIMOTE_STATE_SPEAKER 0x0100
#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
#define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)