added native wiimote support. The new native wiimote support isn't stable and works for windows only.

Follow this tutorial (http://www.wiibrew.org/wiki/Wiimote/Windows_Tutorial) to connect your wiimote and verify that your connections is established (you can do this is one of the wiiuse sample demos). After that start dolphin. At the beginning LED4 of your wiimote should be enabled and after the wii program has established its own connection only LED1 must be enabled. DONT ASK FOR MULTI-WIIMOTE SUPPORT :) Have fun

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1073 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
fires.gc
2008-11-05 17:15:00 +00:00
parent c208b1bc60
commit 5e300155da
8 changed files with 1357 additions and 34 deletions
@@ -327,18 +327,24 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update()
#ifdef _WIN32
// FiRES: TODO find a good solution to do this
static bool test = true;
if (test && GetAsyncKeyState(VK_LBUTTON) && GetAsyncKeyState(VK_RBUTTON))
static int counter = 1000;
if (test && !stricmp(m_LocalName, "Wii") && (m_ScanEnable & 0x2))
{
test = false;
for (size_t i=0; i<m_WiiMotes.size(); i++)
counter--;
if (counter < 0)
{
if (m_WiiMotes[i].EventPagingChanged(2))
test = false;
for (size_t i=0; i<m_WiiMotes.size(); i++)
{
Host_SetWiiMoteConnectionState(1);
SendEventRequestConnection(m_WiiMotes[i]);
if (m_WiiMotes[i].EventPagingChanged(2))
{
Host_SetWiiMoteConnectionState(1);
SendEventRequestConnection(m_WiiMotes[i]);
}
}
}
}
}
#endif
@@ -1324,18 +1330,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteScanEnable(u8* _Input)
LOG(WII_IPC_WIIMOTE, " scan_enable: %s", Scanning[pWriteScanEnable->scan_enable]);
SendEventCommandComplete(HCI_CMD_WRITE_SCAN_ENABLE, &Reply, sizeof(hci_write_scan_enable_rp));
return;
// TODO: fix this ugly request connection hack :)
//for homebrew works this
for (size_t i=0; i<m_WiiMotes.size(); i++)
{
if (m_WiiMotes[i].EventPagingChanged(pWriteScanEnable->scan_enable))
{
SendEventRequestConnection(m_WiiMotes[i]);
}
}
}
void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteInquiryMode(u8* _Input)
@@ -1673,7 +1667,16 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandDisconnect(u8* _Input)
pWiimote->EventDisconnect();
}
PanicAlert("disconnect");
static bool OneShotMessage = true;
if (OneShotMessage)
{
OneShotMessage = false;
PanicAlert("IPC CommandDisconnect: WiiMote emulation is out of sync.\n"
"This message will be shot one time only, because dolphin\n"
"executes the disconnect at all and some times you can play\n"
"anyway. It is strongly recommed to save and/or restart the"
"emulation.");
}
}
void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLinkSupervisionTimeout(u8* _Input)
@@ -44,7 +44,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\..\Externals\WiiUse\include"
PreprocessorDefinitions="LOGGING;WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_WIIMOTE_TEST_EXPORTS;_SECURE_SCL=0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -67,9 +67,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib rpcrt4.lib"
AdditionalDependencies="comctl32.lib wiiuse.lib rpcrt4.lib"
OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_WiimoteD.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\win32"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="0"
@@ -127,7 +128,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\..\Externals\WiiUse\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_WIIMOTE_TEST_EXPORTS;_SECURE_SCL=0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -150,9 +151,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib rpcrt4.lib"
AdditionalDependencies="comctl32.lib wiiuse.lib rpcrt4.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_WiimoteD.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\x64"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="0"
@@ -209,7 +211,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\..\Externals\WiiUse\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_WIIMOTE_TEST_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
AssemblerListingLocation="$(IntDir)\"
@@ -230,9 +232,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib rpcrt4.lib"
AdditionalDependencies="comctl32.lib wiiuse.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_Wiimote.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\win32"
GenerateManifest="false"
GenerateDebugInformation="false"
SubSystem="0"
@@ -291,7 +294,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\..\Externals\WiiUse\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_WIIMOTE_TEST_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
AssemblerListingLocation="$(IntDir)\"
@@ -312,9 +315,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib winmm.lib rpcrt4.lib"
AdditionalDependencies="comctl32.lib wiiuse.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_Wiimote.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\x64"
GenerateManifest="false"
GenerateDebugInformation="false"
SubSystem="0"
@@ -371,7 +375,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\..\Externals\WiiUse\include"
PreprocessorDefinitions="LOGGING;DEBUGFAST;WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_WIIMOTE_TEST_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
WarningLevel="3"
@@ -390,9 +394,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib rpcrt4.lib"
AdditionalDependencies="comctl32.lib wiiuse.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_WiimoteDF.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\win32"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
@@ -450,7 +455,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="..\..\PluginSpecs;..\..\..\Externals\SDL\include;..\..\Core\Common\Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\..\Externals\WiiUse\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_WIIMOTE_TEST_EXPORTS;DEBUGFAST;_SECURE_SCL=0"
RuntimeLibrary="0"
WarningLevel="3"
@@ -469,9 +474,10 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib rpcrt4.lib"
AdditionalDependencies="comctl32.lib wiiuse.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_WiimoteDF.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\Externals\WiiUse\x64"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
@@ -507,18 +513,38 @@
<References>
</References>
<Files>
<Filter
Name="misc"
>
<File
RelativePath="..\..\PluginSpecs\pluginspecs_wiimote.h"
>
</File>
</Filter>
<File
RelativePath="..\..\PluginSpecs\pluginspecs_wiimote.h"
RelativePath=".\Src\main.cpp"
>
</File>
<File
RelativePath=".\Src\Wiimote.cpp"
RelativePath=".\Src\wiimote_emu.cpp"
>
</File>
<File
RelativePath=".\Src\wiimote_emu.h"
>
</File>
<File
RelativePath=".\Src\wiimote_hid.h"
>
</File>
<File
RelativePath=".\Src\wiimote_real.cpp"
>
</File>
<File
RelativePath=".\Src\wiimote_real.h"
>
</File>
</Files>
<Globals>
</Globals>
@@ -0,0 +1,206 @@
// Copyright (C) 2003-2008 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#if !defined(OSX64)
#include <wx/aboutdlg.h>
#endif
#include "Common.h"
#include "StringUtil.h"
#include "pluginspecs_wiimote.h"
#include "wiimote_emu.h"
#include "wiimote_real.h"
SWiimoteInitialize g_WiimoteInitialize;
#define VERSION_STRING "0.1"
bool g_UseRealWiiMote = false;
HINSTANCE g_hInstance;
class wxDLLApp : public wxApp
{
bool OnInit()
{
return true;
}
};
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
#ifdef _WIN32
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
DWORD dwReason, // reason called
LPVOID lpvReserved) // reserved
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{ //use wxInitialize() if you don't want GUI instead of the following 12 lines
wxSetInstance((HINSTANCE)hinstDLL);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
if ( !wxTheApp || !wxTheApp->CallOnInit() )
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
wxEntryCleanup(); //use wxUninitialize() if you don't want GUI
break;
default:
break;
}
g_hInstance = hinstDLL;
return TRUE;
}
#endif
//******************************************************************************
// Exports
//******************************************************************************
extern "C" void GetDllInfo (PLUGIN_INFO* _PluginInfo)
{
_PluginInfo->Version = 0x0100;
_PluginInfo->Type = PLUGIN_TYPE_WIIMOTE;
#ifdef DEBUGFAST
sprintf(_PluginInfo->Name, "Wiimote Test (DebugFast) " VERSION_STRING);
#else
#ifndef _DEBUG
sprintf(_PluginInfo->Name, "Wiimote Test " VERSION_STRING);
#else
sprintf(_PluginInfo->Name, "Wiimote Test (Debug) " VERSION_STRING);
#endif
#endif
}
extern "C" void DllAbout(HWND _hParent)
{
#if !defined(OSX64)
wxAboutDialogInfo info;
info.SetName(_T("Wiimote test plugin"));
info.AddDeveloper(_T("masken (masken3@gmail.com)"));
info.SetDescription(_T("Wiimote test plugin"));
wxAboutBox(info);
#endif
}
extern "C" void DllConfig(HWND _hParent)
{
}
extern "C" void Wiimote_Initialize(SWiimoteInitialize _WiimoteInitialize)
{
g_WiimoteInitialize = _WiimoteInitialize;
g_UseRealWiiMote = WiiMoteReal::Initialize() > 0;
WiiMoteEmu::Initialize();
}
extern "C" void Wiimote_DoState(void* ptr, int mode)
{
WiiMoteReal::DoState(ptr, mode);
WiiMoteEmu::DoState(ptr, mode);
}
extern "C" void Wiimote_Shutdown(void)
{
WiiMoteReal::Shutdown();
WiiMoteEmu::Shutdown();
}
extern "C" void Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
{
const u8* data = (const u8*)_pData;
// dump raw data
{
LOG(WII_IPC_WIIMOTE, "Wiimote_Input");
std::string Temp;
for (u32 j=0; j<_Size; j++)
{
char Buffer[128];
sprintf(Buffer, "%02x ", data[j]);
Temp.append(Buffer);
}
LOG(WII_IPC_WIIMOTE, " Data: %s", Temp.c_str());
}
if (g_UseRealWiiMote)
WiiMoteReal::InterruptChannel(_channelID, _pData, _Size);
else
WiiMoteEmu::InterruptChannel(_channelID, _pData, _Size);
}
extern "C" void Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
{
const u8* data = (const u8*)_pData;
// dump raw data
{
LOG(WII_IPC_WIIMOTE, "Wiimote_ControlChannel");
std::string Temp;
for (u32 j=0; j<_Size; j++)
{
char Buffer[128];
sprintf(Buffer, "%02x ", data[j]);
Temp.append(Buffer);
}
LOG(WII_IPC_WIIMOTE, " Data: %s", Temp.c_str());
}
if (g_UseRealWiiMote)
WiiMoteReal::ControlChannel(_channelID, _pData, _Size);
else
WiiMoteEmu::ControlChannel(_channelID, _pData, _Size);
}
extern "C" void Wiimote_Update()
{
if (g_UseRealWiiMote)
WiiMoteReal::Update();
else
WiiMoteEmu::Update();
}
extern "C" unsigned int Wiimote_GetAttachedControllers()
{
return 1;
}
void __Log(int log, const char *_fmt, ...)
{
char Msg[512];
va_list ap;
va_start( ap, _fmt );
vsprintf( Msg, _fmt, ap );
va_end( ap );
g_WiimoteInitialize.pLog(Msg);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,37 @@
// Copyright (C) 2003-2008 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef WIIMOTE_EMU_H
#define WIIMOTE_EMU_H
#include "wiimote_hid.h"
namespace WiiMoteEmu
{
void Initialize();
void DoState(void* ptr, int mode);
void Shutdown(void);
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size);
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ;
void Update();
void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1);
};
#endif
@@ -1,3 +1,20 @@
// Copyright (C) 2003-2008 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef WIIMOTE_HID_H
#define WIIMOTE_HID_H
@@ -0,0 +1,271 @@
// Copyright (C) 2003-2008 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "pluginspecs_wiimote.h"
#include <queue>
#include "common.h"
#include "thread.h"
#include "wiimote_hid.h"
#include "wiimote_emu.h"
#define WIIUSE_INTERNAL_H_INCLUDED
#define WIIUSE_COMPILE_LIB
#include "wiiuse_012/wiiuse.h"
#include "wiiuse_012/io.h"
extern SWiimoteInitialize g_WiimoteInitialize;
extern void __Log(int log, const char *format, ...);
namespace WiiMoteReal
{
#define MAX_WIIMOTES 1
//******************************************************************************
// Variable declarations
//******************************************************************************
wiimote_t** m_WiiMotesFromWiiUse = NULL;
Common::Thread* g_pReadThread = NULL;
Common::CriticalSection* g_pCriticalSection = NULL;
bool g_Shutdown = false;
class CWiiMote
{
public:
CWiiMote(u8 _WiimoteNumber, wiimote_t* _pWiimote)
: m_WiimoteNumber(_WiimoteNumber)
, m_pWiiMote(_pWiimote)
, m_LastReportValid(false)
, m_channelID(0)
{
wiiuse_set_leds(m_pWiiMote, WIIMOTE_LED_4);
#ifdef _WIN32
// F|RES: i dunno if we really need this
CancelIo(m_pWiiMote->dev_handle);
#endif
}
virtual ~CWiiMote()
{};
// send raw HID data from the core to wiimote
void SendData(u16 _channelID, const u8* _pData, u32 _Size)
{
m_channelID = _channelID;
g_pCriticalSection->Enter();
{
SEvent WriteEvent;
memcpy(WriteEvent.m_PayLoad, _pData+1, _Size-1);
m_EventWriteQueue.push(WriteEvent);
}
g_pCriticalSection->Leave();
}
// read data from wiimote (but don't send it to the core, just filter and queue)
void ReadData()
{
g_pCriticalSection->Enter();
if (!m_EventWriteQueue.empty())
{
SEvent& rEvent = m_EventWriteQueue.front();
wiiuse_io_write(m_pWiiMote, (byte*)rEvent.m_PayLoad, MAX_PAYLOAD);
m_EventWriteQueue.pop();
}
g_pCriticalSection->Leave();
memset(m_pWiiMote->event_buf, 0, MAX_PAYLOAD);
if (wiiuse_io_read(m_pWiiMote))
{
byte* pBuffer = m_pWiiMote->event_buf;
// check if we have a channel (connection) if so save the data...
if (m_channelID > 0)
{
g_pCriticalSection->Enter();
// filter out reports
if (pBuffer[0] >= 0x30)
{
memcpy(m_LastReport.m_PayLoad, pBuffer, MAX_PAYLOAD);
m_LastReportValid = true;
}
else
{
SEvent ImportantEvent;
memcpy(ImportantEvent.m_PayLoad, pBuffer, MAX_PAYLOAD);
m_EventReadQueue.push(ImportantEvent);
}
g_pCriticalSection->Leave();
}
}
};
// send queued data to the core
void Update()
{
g_pCriticalSection->Enter();
if (m_EventReadQueue.empty())
{
if (m_LastReportValid)
SendEvent(m_LastReport);
}
else
{
SendEvent(m_EventReadQueue.front());
m_EventReadQueue.pop();
}
g_pCriticalSection->Leave();
};
private:
struct SEvent
{
SEvent()
{
memset(m_PayLoad, 0, MAX_PAYLOAD);
}
byte m_PayLoad[MAX_PAYLOAD];
};
typedef std::queue<SEvent> CEventQueue;
u8 m_WiimoteNumber; // just for debugging
u16 m_channelID;
wiimote_t* m_pWiiMote;
CEventQueue m_EventReadQueue;
CEventQueue m_EventWriteQueue;
bool m_LastReportValid;
SEvent m_LastReport;
void SendEvent(SEvent& _rEvent)
{
// we don't have an answer channel
if (m_channelID == 0)
return;
// check event buffer;
u8 Buffer[1024];
u32 Offset = 0;
hid_packet* pHidHeader = (hid_packet*)(Buffer + Offset);
Offset += sizeof(hid_packet);
pHidHeader->type = HID_TYPE_DATA;
pHidHeader->param = HID_PARAM_INPUT;
memcpy(&Buffer[Offset], _rEvent.m_PayLoad, MAX_PAYLOAD);
Offset += MAX_PAYLOAD;
g_WiimoteInitialize.pWiimoteInput(m_channelID, Buffer, Offset);
}
};
int g_NumberOfWiiMotes;
CWiiMote* g_WiiMotes[MAX_WIIMOTES];
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg);
//******************************************************************************
// Function Definitions
//******************************************************************************
int Initialize()
{
memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES);
m_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
g_NumberOfWiiMotes= wiiuse_find(m_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
for (int i=0; i<g_NumberOfWiiMotes; i++)
{
g_WiiMotes[i] = new CWiiMote(i+1, m_WiiMotesFromWiiUse[i]);
}
if (g_NumberOfWiiMotes == 0)
return 0;
g_pCriticalSection = new Common::CriticalSection();
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
return true;
}
void DoState(void* ptr, int mode)
{}
void Shutdown(void)
{
g_Shutdown = true;
g_pReadThread->WaitForDeath();
for (int i=0; i<g_NumberOfWiiMotes; i++)
{
delete g_WiiMotes[i];
g_WiiMotes[i] = NULL;
}
delete g_pReadThread;
g_pReadThread = NULL;
delete g_pCriticalSection;
g_pCriticalSection = NULL;
}
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
{
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size);
}
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
{
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size);
}
void Update()
{
for (int i=0; i<g_NumberOfWiiMotes; i++)
{
g_WiiMotes[i]->Update();
}
}
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg)
{
while (!g_Shutdown)
{
for (int i=0; i<g_NumberOfWiiMotes; i++)
{
g_WiiMotes[i]->ReadData();
}
}
return 0;
}
}; // end of namespace
@@ -0,0 +1,34 @@
// Copyright (C) 2003-2008 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef WIIMOTE_REAL_H
#define WIIMOTE_REAL_H
namespace WiiMoteReal
{
int Initialize();
void DoState(void* ptr, int mode);
void Shutdown(void);
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size);
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ;
void Update();
};
#endif