Added UDPWii support to the new plugin. Hopefully I didn't made a mess... Nunchuck support not implemented yet. I want to make it a separate extension.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5835 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
dapetcu21
2010-07-05 10:46:32 +00:00
parent fccacd7f62
commit ca827b9930
16 changed files with 715 additions and 18 deletions

View File

@ -257,7 +257,16 @@ void TiltWiimote(int &_x, int &_y, int &_z)
{
// Select input method and return the x, y, x values
if ((WiiMapping[g_ID].UDPWM.instance)&&(WiiMapping[g_ID].UDPWM.enableAccel))
WiiMapping[g_ID].UDPWM.instance->getAccel(_x,_y,_z);
{
float x,y,z;
WiiMapping[g_ID].UDPWM.instance->getAccel(x,y,z);
float xg = WiiMoteEmu::g_wm.cal_g.x;
float yg = WiiMoteEmu::g_wm.cal_g.y;
float zg = WiiMoteEmu::g_wm.cal_g.z;
_x = WiiMoteEmu::g_wm.cal_zero.x + (int)(xg * x);
_y = WiiMoteEmu::g_wm.cal_zero.y + (int)(yg * y);
_z = WiiMoteEmu::g_wm.cal_zero.z + (int)(zg * z);
}
else
{
if (WiiMapping[g_ID].Tilt.InputWM == FROM_KEYBOARD)

View File

@ -260,15 +260,12 @@ void UDPWiimote::broadcastPresence()
// NOTICE_LOG(WIIMOTE,"UDPWii broadcasting presence");
}
void UDPWiimote::getAccel(int &_x, int &_y, int &_z)
void UDPWiimote::getAccel(float &_x, float &_y, float &_z)
{
float xg = WiiMoteEmu::g_wm.cal_g.x;
float yg = WiiMoteEmu::g_wm.cal_g.y;
float zg = WiiMoteEmu::g_wm.cal_g.z;
d->mutex.Enter();
_x = WiiMoteEmu::g_wm.cal_zero.x + (int)(xg * x);
_y = WiiMoteEmu::g_wm.cal_zero.y + (int)(yg * y);
_z = WiiMoteEmu::g_wm.cal_zero.z + (int)(zg * z);
_x=x;
_y=y;
_z=z;
d->mutex.Leave();
//NOTICE_LOG(WIIMOTE,"%lf %lf %lf",_x, _y, _z);
}

View File

@ -23,7 +23,7 @@ class UDPWiimote
public:
UDPWiimote(const char * port);
virtual ~UDPWiimote();
void getAccel(int &x, int &y, int &z);
void getAccel(float &x, float &y, float &z);
u32 getButtons();
void getNunchuck(float &x, float &y, u8 &mask);
void getIR(float &x, float &y);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="Plugin_WiimoteNew"
ProjectGUID="{BB6CE47B-C676-44BB-AE93-2CF59B8C8BD4}"
RootNamespace="Plugin_WiimoteNew"
@ -544,6 +544,10 @@
RelativePath=".\Src\WiimoteEmu\Speaker.cpp"
>
</File>
<File
RelativePath=".\Src\WiimoteEmu\UDPTLayer.h"
>
</File>
<File
RelativePath=".\Src\WiimoteEmu\WiimoteEmu.cpp"
>

View File

@ -0,0 +1,53 @@
//UDP Wiimote Translation Layer
#ifndef UDPTLAYER_H
#define UDPTLAYER_H
#include "UDPWiimote.h"
namespace UDPTLayer
{
void GetButtons(UDPWrapper * m , wm_core * butt)
{
if (!(m->inst)) return;
if (!(m->updButt)) return;
u32 mask=m->inst->getButtons();
*butt|=(mask&UDPWM_BA)?WIIMOTE_A:0;
*butt|=(mask&UDPWM_BB)?WIIMOTE_B:0;
*butt|=(mask&UDPWM_B1)?WIIMOTE_ONE:0;
*butt|=(mask&UDPWM_B2)?WIIMOTE_TWO:0;
*butt|=(mask&UDPWM_BP)?WIIMOTE_PLUS:0;
*butt|=(mask&UDPWM_BM)?WIIMOTE_MINUS:0;
*butt|=(mask&UDPWM_BH)?WIIMOTE_HOME:0;
*butt|=(mask&UDPWM_BU)?WIIMOTE_PAD_UP:0;
*butt|=(mask&UDPWM_BD)?WIIMOTE_PAD_DOWN:0;
*butt|=(mask&UDPWM_BL)?WIIMOTE_PAD_LEFT:0;
*butt|=(mask&UDPWM_BR)?WIIMOTE_PAD_RIGHT:0;
}
void GetAcceleration(UDPWrapper * m , wm_accel * data, accel_cal * calib)
{
if (!(m->inst)) return;
if (!(m->updAccel)) return;
float x,y,z;
m->inst->getAccel(x,y,z);
data->x=u8(x*(calib->one_g.x-calib->zero_g.x)+calib->zero_g.x);
data->y=u8(y*(calib->one_g.y-calib->zero_g.y)+calib->zero_g.y);
data->z=u8(z*(calib->one_g.z-calib->zero_g.z)+calib->zero_g.z);
}
void GetIR( UDPWrapper * m, float * x, float * y, float * z)
{
if (!(m->inst)) return;
if (!(m->updIR)) return;
if ((*x>-1)&&(*x<1)&&(*y>-1)&&(*y<1)) return; //the recieved values are used ONLY when the normal pointer is offscreen
float _x,_y;
m->inst->getIR(_x,_y);
*x=_x*2-1;
*y=-(_y*2-1);
*z=0;
}
}
#endif

View File

@ -25,6 +25,8 @@
#define WIIMOTE_MINUS 0x1000
#define WIIMOTE_HOME 0x8000
#include "UDPTLayer.h" //this must be included after the buttons
namespace WiimoteEmu
{
@ -274,6 +276,9 @@ Wiimote::Wiimote( const unsigned int index )
// swing
//groups.push_back( m_swing = new Force( "Swing" ) );
//udp
groups.push_back( m_udp = new UDPWrapper( m_index , "UDP Wiimote" ) );
// shake
groups.push_back( m_shake = new Buttons( "Shake" ) );
m_shake->controls.push_back( new ControlGroup::Input( "X" ) );
@ -388,7 +393,7 @@ void Wiimote::Update()
m_buttons->GetState( &m_status.buttons, button_bitmasks );
m_dpad->GetState( &m_status.buttons, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks );
}
UDPTLayer::GetButtons( m_udp, &m_status.buttons );
// check if there is a read data request
if (m_read_requests.size())
{
@ -481,7 +486,7 @@ void Wiimote::Update()
// ----SHAKE----
if (is_focus)
EmulateShake(data + rpt.accel, m_shake, m_shake_step);
UDPTLayer::GetAcceleration( m_udp, (wm_accel*)&data[rpt.accel], (accel_cal*)&m_eeprom[0x16]);
}
// ----ir----
@ -491,6 +496,7 @@ void Wiimote::Update()
if (is_focus)
m_ir->GetState(&xx, &yy, &zz, true);
UDPTLayer::GetIR( m_udp, &xx, &yy, &zz);
xx *= (-256 * 0.95f);
xx += 512;
@ -779,3 +785,4 @@ void Wiimote::Register::Write( size_t address, void* src, size_t length )
}

View File

@ -13,6 +13,7 @@
#include "WiimoteHid.h"
#include "Encryption.h"
#include "UDPWrapper.h"
#include <vector>
#include <queue>
@ -86,6 +87,9 @@ private:
Extension* m_extension;
ControlGroup* m_options;
//UDPWiimote
UDPWrapper* m_udp;
// wiimote index, 0-3
const unsigned int m_index;