Merge in slightly fixed version of the delft changes
This commit is contained in:
22
src/events.c
22
src/events.c
@@ -56,6 +56,7 @@
|
||||
#include "nunchuk.h"
|
||||
#include "classic.h"
|
||||
#include "guitar_hero_3.h"
|
||||
#include "wiiboard.h"
|
||||
#include "events.h"
|
||||
|
||||
static void idle_cycle(struct wiimote_t* wm);
|
||||
@@ -611,6 +612,9 @@ static void handle_expansion(struct wiimote_t* wm, byte* msg) {
|
||||
case EXP_GUITAR_HERO_3:
|
||||
guitar_hero_3_event(&wm->exp.gh3, msg);
|
||||
break;
|
||||
case EXP_WII_BOARD:
|
||||
wii_board_event(&wm->exp.wb, msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -680,6 +684,12 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED;
|
||||
break;
|
||||
}
|
||||
case EXP_ID_CODE_WII_BOARD:
|
||||
{
|
||||
if (wii_board_handshake(wm, &wm->exp.wb, data, len))
|
||||
wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id);
|
||||
@@ -720,6 +730,10 @@ void disable_expansion(struct wiimote_t* wm) {
|
||||
guitar_hero_3_disconnected(&wm->exp.gh3);
|
||||
wm->event = WIIUSE_GUITAR_HERO_3_CTRL_REMOVED;
|
||||
break;
|
||||
case EXP_WII_BOARD:
|
||||
guitar_hero_3_disconnected(&wm->exp.gh3);
|
||||
wm->event = WIIUSE_WII_BOARD_CTRL_REMOVED;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -866,6 +880,14 @@ static int state_changed(struct wiimote_t* wm) {
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
|
||||
break;
|
||||
}
|
||||
case EXP_WII_BOARD:
|
||||
{
|
||||
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_NONE:
|
||||
{
|
||||
break;
|
||||
|
||||
183
src/wiiboard.c
Normal file
183
src/wiiboard.c
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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 Wii Fit Balance Board 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 "wiiboard.h"
|
||||
|
||||
static short big_to_lil(unsigned short num)
|
||||
{
|
||||
short ret = num;
|
||||
char *bret = (char*)&ret;
|
||||
char tmp = bret[1];
|
||||
bret[1] = bret[0];
|
||||
bret[0] = tmp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data, unsigned short len) {
|
||||
int i;
|
||||
/* decrypt data */
|
||||
printf("DECRYPTED DATA WIIBOARD\n");
|
||||
for (i = 0; i < len; ++i)
|
||||
{
|
||||
if(i%16==0)
|
||||
{
|
||||
if(i!=0)
|
||||
printf("\n");
|
||||
|
||||
printf("%X: ",0x4a40000+32+i);
|
||||
}
|
||||
printf("%02X ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
short *handshake_short = (short*)data;
|
||||
|
||||
wb->ctr[0] = big_to_lil(handshake_short[2]);
|
||||
wb->cbr[0] = big_to_lil(handshake_short[3]);
|
||||
wb->ctl[0] = big_to_lil(handshake_short[4]);
|
||||
wb->cbl[0] = big_to_lil(handshake_short[5]);
|
||||
|
||||
wb->ctr[1] = big_to_lil(handshake_short[6]);
|
||||
wb->cbr[1] = big_to_lil(handshake_short[7]);
|
||||
wb->ctl[1] = big_to_lil(handshake_short[8]);
|
||||
wb->cbl[1] = big_to_lil(handshake_short[9]);
|
||||
|
||||
wb->ctr[2] = big_to_lil(handshake_short[10]);
|
||||
wb->cbr[2] = big_to_lil(handshake_short[11]);
|
||||
wb->ctl[2] = big_to_lil(handshake_short[12]);
|
||||
wb->cbl[2] = big_to_lil(handshake_short[13]);
|
||||
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_WII_BOARD;
|
||||
|
||||
#ifdef WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The wii board disconnected.
|
||||
*
|
||||
* @param cc A pointer to a wii_board_t structure.
|
||||
*/
|
||||
void wii_board_disconnected(struct wii_board_t* wb) {
|
||||
memset(wb, 0, sizeof(struct wii_board_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 wii_board_event(struct wii_board_t* wb, byte* msg) {
|
||||
short *shmsg = (short*)(msg);
|
||||
wb->rtr = big_to_lil(shmsg[0]);
|
||||
if(wb->rtr<0) wb->rtr = 0;
|
||||
wb->rbr = big_to_lil(shmsg[1]);
|
||||
if(wb->rbr<0) wb->rbr = 0;
|
||||
wb->rtl = big_to_lil(shmsg[2]);
|
||||
if(wb->rtl<0) wb->rtl = 0;
|
||||
wb->rbl = big_to_lil(shmsg[3]);
|
||||
if(wb->rbl<0) wb->rbl = 0;
|
||||
|
||||
/*
|
||||
Interpolate values
|
||||
Calculations borrowed from wiili.org - No names to mention sadly :( http://www.wiili.org/index.php/Wii_Balance_Board_PC_Drivers page however!
|
||||
*/
|
||||
|
||||
if(wb->rtr<wb->ctr[1])
|
||||
{
|
||||
wb->tr = 68*(wb->rtr-wb->ctr[0])/(wb->ctr[1]-wb->ctr[0]);
|
||||
}
|
||||
else if(wb->rtr >= wb->ctr[1])
|
||||
{
|
||||
wb->tr = 68*(wb->rtr-wb->ctr[1])/(wb->ctr[2]-wb->ctr[1]) + 68;
|
||||
}
|
||||
|
||||
if(wb->rtl<wb->ctl[1])
|
||||
{
|
||||
wb->tl = 68*(wb->rtl-wb->ctl[0])/(wb->ctl[1]-wb->ctl[0]);
|
||||
}
|
||||
else if(wb->rtl >= wb->ctl[1])
|
||||
{
|
||||
wb->tl = 68*(wb->rtl-wb->ctl[1])/(wb->ctl[2]-wb->ctl[1]) + 68;
|
||||
}
|
||||
|
||||
if(wb->rbr<wb->cbr[1])
|
||||
{
|
||||
wb->br = 68*(wb->rbr-wb->cbr[0])/(wb->cbr[1]-wb->cbr[0]);
|
||||
}
|
||||
else if(wb->rbr >= wb->cbr[1])
|
||||
{
|
||||
wb->br = 68*(wb->rbr-wb->cbr[1])/(wb->cbr[2]-wb->cbr[1]) + 68;
|
||||
}
|
||||
|
||||
if(wb->rbl<wb->cbl[1])
|
||||
{
|
||||
wb->bl = 68*(wb->rbl-wb->cbl[0])/(wb->cbl[1]-wb->cbl[0]);
|
||||
}
|
||||
else if(wb->rbl >= wb->cbl[1])
|
||||
{
|
||||
wb->bl = 68*(wb->rbl-wb->cbl[1])/(wb->cbl[2]-wb->cbl[1]) + 68;
|
||||
}
|
||||
}
|
||||
|
||||
void wiiuse_set_wii_board_calib(struct wiimote_t *wm)
|
||||
{
|
||||
}
|
||||
53
src/wiiboard.h
Normal file
53
src/wiiboard.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 WII_BOARD_H_INCLUDED
|
||||
#define WII_BOARD_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data, unsigned short len);
|
||||
|
||||
void wii_board_disconnected(struct wii_board_t* wb);
|
||||
|
||||
void wii_board_event(struct wii_board_t* wb, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
30
src/wiiuse.h
30
src/wiiuse.h
@@ -128,6 +128,7 @@
|
||||
#define EXP_NUNCHUK 1
|
||||
#define EXP_CLASSIC 2
|
||||
#define EXP_GUITAR_HERO_3 3
|
||||
#define EXP_WII_BOARD 4
|
||||
|
||||
/* IR correction types */
|
||||
typedef enum ir_position_t {
|
||||
@@ -450,6 +451,28 @@ typedef struct guitar_hero_3_t {
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
} guitar_hero_3_t;
|
||||
|
||||
/*
|
||||
Wii board
|
||||
*/
|
||||
typedef struct wii_board_t {
|
||||
short tl; /* Interpolated */
|
||||
short tr;
|
||||
short bl;
|
||||
short br; /* End interp */
|
||||
short rtl; /* RAW */
|
||||
short rtr;
|
||||
short rbl;
|
||||
short rbr; /* /RAW */
|
||||
short ltl;
|
||||
short ltr;
|
||||
short lbl;
|
||||
short lbr;
|
||||
short ctl[3]; /* Calibration */
|
||||
short ctr[3];
|
||||
short cbl[3];
|
||||
short cbr[3]; /* /Calibration */
|
||||
} wii_board_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct expansion_t
|
||||
@@ -462,6 +485,7 @@ typedef struct expansion_t {
|
||||
struct nunchuk_t nunchuk;
|
||||
struct classic_ctrl_t classic;
|
||||
struct guitar_hero_3_t gh3;
|
||||
struct wii_board_t wb;
|
||||
};
|
||||
} expansion_t;
|
||||
|
||||
@@ -522,7 +546,9 @@ typedef enum WIIUSE_EVENT_TYPE {
|
||||
WIIUSE_CLASSIC_CTRL_INSERTED,
|
||||
WIIUSE_CLASSIC_CTRL_REMOVED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED,
|
||||
WIIUSE_WII_BOARD_CTRL_INSERTED,
|
||||
WIIUSE_WII_BOARD_CTRL_REMOVED
|
||||
} WIIUSE_EVENT_TYPE;
|
||||
|
||||
/**
|
||||
@@ -643,6 +669,8 @@ WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int le
|
||||
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);
|
||||
|
||||
/* Balance Board */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -150,6 +150,7 @@
|
||||
|
||||
/* encrypted expansion id codes (located at 0x04A400FC) */
|
||||
#define EXP_ID_CODE_NUNCHUK 0x9A1EFEFE
|
||||
#define EXP_ID_CODE_WII_BOARD 0xA4200402
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD
|
||||
#define EXP_ID_CODE_GUITAR 0x9A1EFDFB
|
||||
|
||||
|
||||
Reference in New Issue
Block a user