Skip to content

Commit

Permalink
Initial Port of old UDP code (for use with Dolphindroid and Just Danc…
Browse files Browse the repository at this point in the history
…e games using android phone, download from playstore the apk)

Sample config for WiimoteNew.ini
[Wiimote2]
Source = 0
UDP Wiimote/Port = 4434
UDP Wiimote/Enable = 1
[Wiimote3]
Source = 0
UDP Wiimote/Enable = 1
UDP Wiimote/Port = 4435
[Wiimote4]
Source = 0
UDP Wiimote/Enable = 1
UDP Wiimote/Port = 4436
  • Loading branch information
kevlahnota committed May 26, 2017
1 parent e139b66 commit aca2fe4
Show file tree
Hide file tree
Showing 23 changed files with 894 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Source/Core/Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
<ClInclude Include="HW\WiimoteEmu\Attachment\Turntable.h" />
<ClInclude Include="HW\WiimoteEmu\Encryption.h" />
<ClInclude Include="HW\WiimoteEmu\MatrixMath.h" />
<ClInclude Include="HW\WiimoteEmu\UDPTLayer.h" />
<ClInclude Include="HW\WiimoteEmu\WiimoteEmu.h" />
<ClInclude Include="HW\WiimoteEmu\WiimoteHid.h" />
<ClInclude Include="HW\WiimoteReal\WiimoteReal.h" />
Expand Down Expand Up @@ -515,4 +516,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
27 changes: 9 additions & 18 deletions Source/Core/Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -769,15 +769,9 @@
<ClCompile Include="IPC_HLE\WII_IPC_HLE_Device_usb_ven.cpp">
<Filter>IPC HLE %28IOS/Starlet%29\USB</Filter>
</ClCompile>
<ClCompile Include="PowerPC\SignatureDB\CSVSignatureDB.cpp">
<Filter>PowerPC\SignatureDB</Filter>
</ClCompile>
<ClCompile Include="PowerPC\SignatureDB\DSYSignatureDB.cpp">
<Filter>PowerPC\SignatureDB</Filter>
</ClCompile>
<ClCompile Include="PowerPC\SignatureDB\SignatureDB.cpp">
<Filter>PowerPC\SignatureDB</Filter>
</ClCompile>
<ClCompile Include="PowerPC\SignatureDB\CSVSignatureDB.cpp" />
<ClCompile Include="PowerPC\SignatureDB\DSYSignatureDB.cpp" />
<ClCompile Include="PowerPC\SignatureDB\SignatureDB.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="BootManager.h" />
Expand Down Expand Up @@ -1336,17 +1330,14 @@
<ClInclude Include="IPC_HLE\WII_IPC_HLE_Device_usb_ven.h">
<Filter>IPC HLE %28IOS/Starlet%29\USB</Filter>
</ClInclude>
<ClInclude Include="PowerPC\SignatureDB\CSVSignatureDB.h">
<Filter>PowerPC\SignatureDB</Filter>
</ClInclude>
<ClInclude Include="PowerPC\SignatureDB\DSYSignatureDB.h">
<Filter>PowerPC\SignatureDB</Filter>
</ClInclude>
<ClInclude Include="PowerPC\SignatureDB\SignatureDB.h">
<Filter>PowerPC\SignatureDB</Filter>
<ClInclude Include="PowerPC\SignatureDB\CSVSignatureDB.h" />
<ClInclude Include="PowerPC\SignatureDB\DSYSignatureDB.h" />
<ClInclude Include="PowerPC\SignatureDB\SignatureDB.h" />
<ClInclude Include="HW\WiimoteEmu\UDPTLayer.h">
<Filter>HW %28Flipper/Hollywood%29\Wiimote</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
</Project>
</Project>
35 changes: 34 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "Common/MathUtil.h"
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/UDPWiimote.h"
#include "InputCommon/UDPWrapper.h"


namespace WiimoteEmu
{
Expand All @@ -19,7 +22,7 @@ static const u8 nunchuk_button_bitmasks[] = {
Nunchuk::BUTTON_C, Nunchuk::BUTTON_Z,
};

Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"), _reg)
Nunchuk::Nunchuk(UDPWrapper *wrp, WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"), _reg), m_udpWrap(wrp)
{
// buttons
groups.emplace_back(m_buttons = new Buttons("Buttons"));
Expand Down Expand Up @@ -91,6 +94,36 @@ void Nunchuk::GetState(u8* const data)
// flip the button bits :/
ncdata->bt.hex ^= 0x03;

//udp
if (m_udpWrap->inst)
{
if (m_udpWrap->updNun)
{
u8 mask;
float x, y;
m_udpWrap->inst->getNunchuck(&x, &y, &mask);
// buttons
if (mask & UDPWM_NC)
ncdata->bt.c &= ~WiimoteEmu::Nunchuk::BUTTON_C;
if (mask & UDPWM_NZ)
ncdata->bt.z &= ~WiimoteEmu::Nunchuk::BUTTON_Z;
// stick
if (ncdata->jx == 0x80 && ncdata->jy == 0x80)
{
ncdata->jx = u8(0x80 + x * 127);
ncdata->jy = u8(0x80 + y * 127);
}
}
if (m_udpWrap->updNunAccel)
{
float x, y, z;
m_udpWrap->inst->getNunchuckAccel(&x, &y, &z);
accel.x = x;
accel.y = y;
accel.z = z;
}
}

// We now use 2 bits more precision, so multiply by 4 before converting to int
s16 accel_x = (s16)(4 * (accel.x * ACCEL_RANGE + ACCEL_ZERO_G));
s16 accel_y = (s16)(4 * (accel.y * ACCEL_RANGE + ACCEL_ZERO_G));
Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "Core/HW/WiimoteEmu/Attachment/Attachment.h"

class UDPWrapper;

namespace WiimoteEmu
{
enum class NunchukGroup;
Expand All @@ -14,7 +16,7 @@ struct ExtensionReg;
class Nunchuk : public Attachment
{
public:
Nunchuk(WiimoteEmu::ExtensionReg& _reg);
Nunchuk(UDPWrapper * wrp, WiimoteEmu::ExtensionReg& _reg);

void GetState(u8* const data) override;
bool IsButtonPressed() const override;
Expand Down Expand Up @@ -52,5 +54,7 @@ class Nunchuk : public Attachment
AnalogStick* m_stick;

u8 m_shake_step[3];

UDPWrapper* const m_udpWrap;
};
}
50 changes: 50 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/UDPTLayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/UDPWiimote.h"

namespace UDPTLayer
{
static void GetButtons(UDPWrapper * m, wm_core * butt)
{
if (!(m->inst)) return;
if (!(m->updButt)) return;
u32 mask = m->inst->getButtons();
*butt |= (mask & UDPWM_BA) ? WiimoteEmu::Wiimote::BUTTON_A : 0;
*butt |= (mask & UDPWM_BB) ? WiimoteEmu::Wiimote::BUTTON_B : 0;
*butt |= (mask & UDPWM_B1) ? WiimoteEmu::Wiimote::BUTTON_ONE : 0;
*butt |= (mask & UDPWM_B2) ? WiimoteEmu::Wiimote::BUTTON_TWO : 0;
*butt |= (mask & UDPWM_BP) ? WiimoteEmu::Wiimote::BUTTON_PLUS : 0;
*butt |= (mask & UDPWM_BM) ? WiimoteEmu::Wiimote::BUTTON_MINUS : 0;
*butt |= (mask & UDPWM_BH) ? WiimoteEmu::Wiimote::BUTTON_HOME : 0;
*butt |= (mask & UDPWM_BU) ? WiimoteEmu::Wiimote::PAD_UP : 0;
*butt |= (mask & UDPWM_BD) ? WiimoteEmu::Wiimote::PAD_DOWN : 0;
*butt |= (mask & UDPWM_BL) ? WiimoteEmu::Wiimote::PAD_LEFT : 0;
*butt |= (mask & UDPWM_BR) ? WiimoteEmu::Wiimote::PAD_RIGHT : 0;
}

static void GetAcceleration(UDPWrapper * m, WiimoteEmu::AccelData * const data)
{
if (!(m->inst)) return;
if (!(m->updAccel)) return;
float x, y, z;
m->inst->getAccel(&x, &y, &z);
data->x = x;
data->y = y;
data->z = z;
}

static void GetIR(UDPWrapper * m, ControlState * x, ControlState * y, ControlState * z)
{
if (!(m->inst)) return;
if (!(m->updIR)) return;
// if ((*x >= -0.999) && (*x <= 0.999) && (*y >= -0.999) && (*y <= 0.999)) return; //the received 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);
*x = _x;
*y = _y;
*z = 0;
}
}
10 changes: 9 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include "Core/HW/WiimoteEmu/Attachment/Turntable.h"
#include "Core/HW/WiimoteEmu/MatrixMath.h"
#include "Core/HW/WiimoteEmu/UDPTLayer.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
Expand Down Expand Up @@ -243,6 +244,9 @@ Wiimote::Wiimote(const unsigned int index)
for (auto& named_button : named_buttons)
m_buttons->controls.emplace_back(new ControlGroup::Input(named_button));

// udp
groups.emplace_back(m_udp = new UDPWrapper(m_index, _trans("UDP Wiimote")));

// ir
groups.emplace_back(m_ir = new Cursor(_trans("IR")));

Expand All @@ -261,7 +265,7 @@ Wiimote::Wiimote(const unsigned int index)
// extension
groups.emplace_back(m_extension = new Extension(_trans("Extension")));
m_extension->attachments.emplace_back(new WiimoteEmu::None(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_udp, m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Classic(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Guitar(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Drums(m_reg_ext));
Expand Down Expand Up @@ -433,6 +437,7 @@ void Wiimote::UpdateButtonsStatus()
sideways_modifier_switch;
m_buttons->GetState(&m_status.buttons.hex, button_bitmasks);
m_dpad->GetState(&m_status.buttons.hex, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks);
UDPTLayer::GetButtons(m_udp, &m_status.buttons.hex);
}

void Wiimote::GetButtonData(u8* const data)
Expand Down Expand Up @@ -461,6 +466,7 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright);
EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
EmulateShake(&m_accel, m_shake, m_shake_step);
UDPTLayer::GetAcceleration(m_udp, &m_accel);

wm_accel& accel = *(wm_accel*)(data + rptf.accel);
wm_buttons& core = *(wm_buttons*)(data + rptf.core);
Expand Down Expand Up @@ -498,6 +504,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
memset(x, 0xFF, sizeof(x));

ControlState xx = 10000, yy = 0, zz = 0;
//float xxf = 10000, yyf = 0, zzf = 0;
double nsin, ncos;

if (use_accel)
Expand Down Expand Up @@ -533,6 +540,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
LowPassFilter(ir_cos, ncos, 1.0 / 60);

m_ir->GetState(&xx, &yy, &zz, true);
UDPTLayer::GetIR(m_udp, &xx, &yy, &zz);

Vertex v[4];

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Core/HW/WiimoteEmu/Encryption.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/UDPWrapper.h"

// Registry sizes
#define WIIMOTE_EEPROM_SIZE (16 * 1024)
Expand Down Expand Up @@ -242,6 +243,8 @@ class Wiimote : public ControllerEmu

double ir_sin, ir_cos; // for the low pass filter

UDPWrapper* m_udp;

bool m_rumble_on;
bool m_speaker_mute;
bool m_motion_plus_present;
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteHid.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct hid_packet

// Source: http://wiibrew.org/wiki/Wiimote

typedef u16 wm_core;

union wm_buttons // also just called "core data"
{
u16 hex;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinWX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set(GUI_SRCS
PostProcessingConfigDiag.cpp
SoftwareVideoConfigDialog.cpp
TASInputDlg.cpp
UDPConfigDiag.cpp
VideoConfigDiag.cpp
WxEventUtils.cpp
WXInputBase.cpp
Expand Down
6 changes: 5 additions & 1 deletion Source/Core/DolphinWX/Dolphin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath);</LibraryPath>
<ExecutablePath>$(VC_ExecutablePath_x64);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(FxCopDir);$(PATH);</ExecutablePath>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
Expand Down Expand Up @@ -136,6 +138,7 @@
<ClCompile Include="PatchAddEdit.cpp" />
<ClCompile Include="SoftwareVideoConfigDialog.cpp" />
<ClCompile Include="TASInputDlg.cpp" />
<ClCompile Include="UDPConfigDiag.cpp" />
<ClCompile Include="VideoConfigDiag.cpp" />
<ClCompile Include="PostProcessingConfigDiag.cpp" />
<ClCompile Include="ControllerConfigDiag.cpp" />
Expand Down Expand Up @@ -213,6 +216,7 @@
<ClInclude Include="PatchAddEdit.h" />
<ClInclude Include="SoftwareVideoConfigDialog.h" />
<ClInclude Include="TASInputDlg.h" />
<ClInclude Include="UDPConfigDiag.h" />
<ClInclude Include="VideoConfigDiag.h" />
<ClInclude Include="PostProcessingConfigDiag.h" />
<ClInclude Include="ControllerConfigDiag.h" />
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinWX/Dolphin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
<ClCompile Include="Input\MicButtonConfigDiag.cpp">
<Filter>GUI\InputConfig</Filter>
</ClCompile>
<ClCompile Include="UDPConfigDiag.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Main.h" />
Expand Down Expand Up @@ -479,6 +480,7 @@
<ClInclude Include="Input\MicButtonConfigDiag.h">
<Filter>GUI\InputConfig</Filter>
</ClInclude>
<ClInclude Include="UDPConfigDiag.h" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
Expand Down
18 changes: 18 additions & 0 deletions Source/Core/DolphinWX/Input/InputConfigDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "DolphinWX/Input/DrumsInputConfigDiag.h"
#include "DolphinWX/Input/GuitarInputConfigDiag.h"
#include "DolphinWX/Input/InputConfigDiag.h"
#include "DolphinWX/UDPConfigDiag.h"
#include "DolphinWX/Input/NunchukInputConfigDiag.h"
#include "DolphinWX/Input/TurntableInputConfigDiag.h"
#include "DolphinWX/WxUtils.h"
Expand All @@ -58,8 +59,17 @@
#include "InputCommon/ControllerInterface/ExpressionParser.h"
#include "InputCommon/InputConfig.h"

class UDPWrapper;

using namespace ciface::ExpressionParser;

void InputConfigDialog::ConfigUDPWii(wxCommandEvent &event)
{
UDPWrapper* const wrp = ((UDPConfigButton*)event.GetEventObject())->wrapper;
UDPConfigDiag diag(this, wrp);
diag.ShowModal();
}

void InputConfigDialog::ConfigExtension(wxCommandEvent& event)
{
ControllerEmu::Extension* const ex = ((ExtensionButton*)event.GetEventObject())->extension;
Expand Down Expand Up @@ -1130,6 +1140,14 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
Add(configure_btn, 0, wxEXPAND | wxLEFT | wxRIGHT, space3);
}
break;
case GROUP_TYPE_UDPWII:
{
wxButton* const btn = new UDPConfigButton(parent, (UDPWrapper*)group);
btn->Bind(wxEVT_BUTTON, &InputConfigDialog::ConfigUDPWii, eventsink);
Add(btn, 0, wxALL | wxEXPAND, 3);
}
break;

default:
{
// options
Expand Down
Loading

0 comments on commit aca2fe4

Please sign in to comment.