2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// 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/
|
|
|
|
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
#include "Common.h" // Common
|
2009-07-12 21:58:32 +00:00
|
|
|
#include "LogManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "StringUtil.h"
|
2009-01-28 16:09:08 +00:00
|
|
|
#include "Timer.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
#define EXCLUDEMAIN_H // Avoid certain declarations in main.h
|
2009-02-01 13:01:50 +00:00
|
|
|
#include "EmuDefinitions.h" // Local
|
|
|
|
#include "wiimote_hid.h"
|
|
|
|
#include "main.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-07-05 04:29:00 +00:00
|
|
|
#include "ConfigPadDlg.h"
|
|
|
|
#include "ConfigBasicDlg.h"
|
|
|
|
|
|
|
|
WiimotePadConfigDialog *m_PadConfigFrame = NULL;
|
|
|
|
WiimoteBasicConfigDialog *m_BasicConfigFrame = NULL;
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
2009-01-28 16:09:08 +00:00
|
|
|
#include "Config.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "pluginspecs_wiimote.h"
|
|
|
|
#include "EmuMain.h"
|
|
|
|
#if HAVE_WIIUSE
|
2009-01-25 23:07:15 +00:00
|
|
|
#include "wiimote_real.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
2009-01-07 02:59:19 +00:00
|
|
|
|
2009-08-02 08:53:54 +00:00
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
2010-07-16 14:14:57 +00:00
|
|
|
Display* WMdisplay = NULL;
|
2009-08-02 08:53:54 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
SWiimoteInitialize g_WiimoteInitialize;
|
2009-03-18 17:17:58 +00:00
|
|
|
PLUGIN_GLOBALS* globals = NULL;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
// General
|
2009-01-25 23:07:15 +00:00
|
|
|
bool g_EmulatorRunning = false;
|
2009-02-20 03:13:22 +00:00
|
|
|
u32 g_ISOId = 0;
|
2010-01-01 03:19:46 +00:00
|
|
|
bool g_SearchDeviceDone = false;
|
2009-01-25 23:07:15 +00:00
|
|
|
bool g_RealWiiMotePresent = false;
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
// Debugging
|
|
|
|
bool g_DebugAccelerometer = false;
|
|
|
|
bool g_DebugData = false;
|
2009-12-27 19:31:02 +00:00
|
|
|
bool g_DebugComm = false;
|
|
|
|
bool g_DebugSoundData = false;
|
2009-02-07 03:16:41 +00:00
|
|
|
bool g_DebugCustom = false;
|
2009-02-01 13:01:50 +00:00
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
// Update speed
|
|
|
|
int g_UpdateCounter = 0;
|
|
|
|
double g_UpdateTime = 0;
|
|
|
|
int g_UpdateRate = 0;
|
|
|
|
int g_UpdateWriteScreen = 0;
|
|
|
|
std::vector<int> g_UpdateTimeList (5, 0);
|
|
|
|
|
|
|
|
// Movement recording
|
Now you can switch between Emulated and Real WiiMotes, connect more Real Wiimotes and even pair them up (if you have MS BT Stack) during gameplay!
All you gotta do is Pause the emulation! That's useful for when your batteries run out during gameplay, for example...
But if you change the WiiMote source (between Emulated, Real or Inactive) you must disconnect and reconnect (Menu Tools -> Connect WiiMote) the WiiMotes affected by the change...
Thanks to jack.fr0st who did all the emulation state notification work!
Now every plugin has a way to know the current emulation state (paused, stopped or playing)
@ayuanx: I thought about doing a PostMessage(g_WiimoteInitialize.hWnd, WM_USER, WIIMOTE_DISCONNECT, current_number); so that the user gets asked to reconnect that WiiMote, trying to avoid having to disconnect and reconnect, but it didn't work because shooting that message only asks to reconnect, doesn't do a disconnect... Do you have any ideas on how to accomplish that?
Also, if anyone could check if Issue 1916 is finally fixed... Or at least when is the cursor being hidden or not...
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4789 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-06 19:26:52 +00:00
|
|
|
std::vector<SRecordingAll> VRecording(RECORDING_ROWS);
|
|
|
|
|
|
|
|
PLUGIN_EMUSTATE g_EmulatorState = PLUGIN_EMUSTATE_STOP;
|
2009-01-28 16:09:08 +00:00
|
|
|
|
2009-07-02 19:00:27 +00:00
|
|
|
// Standard crap to make wxWidgets happy
|
2009-02-07 03:16:41 +00:00
|
|
|
#ifdef _WIN32
|
2009-07-02 19:00:27 +00:00
|
|
|
HINSTANCE g_hInstance;
|
2009-02-07 03:16:41 +00:00
|
|
|
|
2008-12-14 23:52:01 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-07-02 19:00:27 +00:00
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
|
|
|
bool OnInit()
|
2009-01-26 07:01:43 +00:00
|
|
|
{
|
2009-07-02 19:00:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2010-02-22 04:59:57 +00:00
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
2009-07-02 19:00:27 +00:00
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
2008-12-14 23:52:01 +00:00
|
|
|
#endif
|
2009-01-07 02:59:19 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
LPVOID lpvReserved) // reserved
|
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2009-07-02 19:00:27 +00:00
|
|
|
{
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
wxSetInstance((HINSTANCE)hinstDLL);
|
2010-02-22 04:59:57 +00:00
|
|
|
wxInitialize();
|
2009-07-02 19:00:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-07-05 05:59:03 +00:00
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2010-04-26 17:51:32 +00:00
|
|
|
{
|
2009-07-02 19:00:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-02-22 04:59:57 +00:00
|
|
|
wxUninitialize();
|
2009-07-02 19:00:27 +00:00
|
|
|
#endif
|
2010-04-26 17:51:32 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
2009-01-07 02:59:19 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
// Exports
|
2009-07-02 19:00:27 +00:00
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_WIIMOTE;
|
2009-07-02 19:00:27 +00:00
|
|
|
#ifdef DEBUGFAST
|
2010-02-25 12:35:31 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin Wiimote Plugin (DebugFast)");
|
2009-07-02 19:00:27 +00:00
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
2010-02-25 12:35:31 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin Wiimote Plugin");
|
2009-07-02 19:00:27 +00:00
|
|
|
#else
|
2010-02-25 12:35:31 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin Wiimote Plugin (Debug)");
|
2009-07-02 19:00:27 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
|
|
|
{
|
|
|
|
globals = _pPluginGlobals;
|
|
|
|
LogManager::SetInstance((LogManager *)globals->logManager);
|
|
|
|
}
|
2009-01-08 12:12:15 +00:00
|
|
|
|
2010-07-22 02:05:28 +00:00
|
|
|
void *DllDebugger(void *_hParent, bool Show)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-07-30 03:51:49 +00:00
|
|
|
void DllConfig(void *_hParent)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-04-26 17:51:32 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (WiiMoteReal::g_AutoPairUpInvisibleWindow == NULL)
|
|
|
|
{
|
|
|
|
WiiMoteReal::g_AutoPairUpInvisibleWindow = new Common::Thread(WiiMoteReal::RunInvisibleMessageWindow_ThreadFunc, NULL);
|
|
|
|
WiiMoteReal::g_AutoPairUpMonitoring = new Common::Thread(WiiMoteReal::PairUp_ThreadFunc, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-01 03:19:46 +00:00
|
|
|
if (!g_SearchDeviceDone)
|
2009-12-29 13:38:34 +00:00
|
|
|
{
|
|
|
|
// Load settings
|
|
|
|
g_Config.Load();
|
|
|
|
// We do a pad search before creating the dialog
|
|
|
|
WiiMoteEmu::Search_Devices(WiiMoteEmu::joyinfo, WiiMoteEmu::NumPads, WiiMoteEmu::NumGoodPads);
|
2010-01-01 03:19:46 +00:00
|
|
|
g_SearchDeviceDone = true;
|
2009-12-29 13:38:34 +00:00
|
|
|
}
|
2009-12-27 19:31:02 +00:00
|
|
|
|
2010-04-26 17:51:32 +00:00
|
|
|
|
2009-12-14 02:23:14 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-07-30 03:51:49 +00:00
|
|
|
m_BasicConfigFrame = new WiimoteBasicConfigDialog((wxWindow *)_hParent);
|
2010-03-05 07:03:44 +00:00
|
|
|
m_BasicConfigFrame->ShowModal();
|
2010-02-25 17:50:08 +00:00
|
|
|
m_BasicConfigFrame->Destroy();
|
2008-12-14 23:52:01 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-12-14 02:23:14 +00:00
|
|
|
// Start emulation
|
2009-07-02 19:00:27 +00:00
|
|
|
void Initialize(void *init)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-25 23:07:15 +00:00
|
|
|
g_EmulatorRunning = true;
|
2009-12-27 19:31:02 +00:00
|
|
|
g_WiimoteInitialize = *(SWiimoteInitialize *)init;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-26 07:01:43 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-02-25 06:12:35 +00:00
|
|
|
// Load the ISO Id
|
|
|
|
g_ISOId = g_WiimoteInitialize.ISOId;
|
|
|
|
// Load the settings
|
|
|
|
g_Config.Load();
|
2009-01-26 07:01:43 +00:00
|
|
|
#endif
|
2009-08-02 08:53:54 +00:00
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
2010-07-16 14:14:57 +00:00
|
|
|
WMdisplay = XOpenDisplay(NULL);
|
2009-08-02 08:53:54 +00:00
|
|
|
#endif
|
2009-01-26 07:01:43 +00:00
|
|
|
|
2009-02-20 03:13:22 +00:00
|
|
|
g_ISOId = g_WiimoteInitialize.ISOId;
|
2009-12-27 19:31:02 +00:00
|
|
|
DEBUG_LOG(WIIMOTE, "ISOId: %08x %s", g_WiimoteInitialize.ISOId, Hex2Ascii(g_WiimoteInitialize.ISOId).c_str());
|
2009-02-20 03:13:22 +00:00
|
|
|
|
2010-01-16 22:37:38 +00:00
|
|
|
// Load IR settings, as this is a per-game setting and the user might have loaded a different game
|
|
|
|
g_Config.LoadIR();
|
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
// Run this first so that WiiMoteReal::Initialize() overwrites g_Eeprom
|
|
|
|
WiiMoteEmu::Initialize();
|
2009-02-20 03:13:22 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
/* We will run WiiMoteReal::Initialize() even if we are not using a real
|
|
|
|
wiimote, to check if there is a real wiimote connected. We will initiate
|
|
|
|
wiiuse.dll, but we will return before creating a new thread for it if we
|
|
|
|
find no real Wiimotes. Then g_RealWiiMotePresent will also be
|
|
|
|
false. This function call will be done instantly whether there is a real
|
|
|
|
Wiimote connected or not. It takes no time for Wiiuse to check for
|
|
|
|
connected Wiimotes. */
|
2010-02-21 18:53:11 +00:00
|
|
|
#if HAVE_WIIUSE
|
2010-04-26 17:51:32 +00:00
|
|
|
|
2010-02-21 18:53:11 +00:00
|
|
|
WiiMoteReal::Initialize();
|
|
|
|
WiiMoteReal::Allocate();
|
2010-04-26 17:51:32 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (WiiMoteReal::g_AutoPairUpInvisibleWindow == NULL)
|
|
|
|
{
|
|
|
|
WiiMoteReal::g_AutoPairUpInvisibleWindow = new Common::Thread(WiiMoteReal::RunInvisibleMessageWindow_ThreadFunc, NULL);
|
|
|
|
WiiMoteReal::g_AutoPairUpMonitoring = new Common::Thread(WiiMoteReal::PairUp_ThreadFunc, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
2010-02-21 18:53:11 +00:00
|
|
|
#endif
|
2009-01-25 23:07:15 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 07:29:04 +00:00
|
|
|
// If a game is not running this is called by the Configuration window when it's closed
|
2009-07-02 19:00:27 +00:00
|
|
|
void Shutdown(void)
|
2009-01-25 23:07:15 +00:00
|
|
|
{
|
2009-01-26 07:29:04 +00:00
|
|
|
// Not running
|
|
|
|
g_EmulatorRunning = false;
|
|
|
|
|
2009-02-20 03:13:22 +00:00
|
|
|
// Reset the game ID in all cases
|
|
|
|
g_ISOId = 0;
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
#if HAVE_WIIUSE
|
2010-02-21 18:53:11 +00:00
|
|
|
WiiMoteReal::Shutdown();
|
2009-01-25 23:07:15 +00:00
|
|
|
#endif
|
|
|
|
WiiMoteEmu::Shutdown();
|
2010-07-16 14:14:57 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
if (WMdisplay)
|
|
|
|
XCloseDisplay(WMdisplay);
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-02 19:00:27 +00:00
|
|
|
void DoState(unsigned char **ptr, int mode)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-07-03 12:22:32 +00:00
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
|
|
|
|
// TODO: Shorten the list
|
2009-11-24 05:03:47 +00:00
|
|
|
|
2009-07-03 12:22:32 +00:00
|
|
|
//p.Do(g_EmulatorRunning);
|
|
|
|
//p.Do(g_ISOId);
|
2009-12-27 19:31:02 +00:00
|
|
|
//p.Do(g_RealWiiMotePresent);
|
|
|
|
//p.Do(g_RealWiiMoteInitialized);
|
|
|
|
//p.Do(g_EmulatedWiiMoteInitialized);
|
2009-11-24 05:03:47 +00:00
|
|
|
//p.Do(g_UpdateCounter);
|
|
|
|
//p.Do(g_UpdateTime);
|
|
|
|
//p.Do(g_UpdateRate);
|
|
|
|
//p.Do(g_UpdateWriteScreen);
|
|
|
|
//p.Do(g_UpdateTimeList);
|
2009-07-03 12:22:32 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
#if HAVE_WIIUSE
|
2009-07-03 12:22:32 +00:00
|
|
|
WiiMoteReal::DoState(p);
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
2009-07-03 12:22:32 +00:00
|
|
|
WiiMoteEmu::DoState(p);
|
2009-11-24 05:03:47 +00:00
|
|
|
|
|
|
|
return;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
Now you can switch between Emulated and Real WiiMotes, connect more Real Wiimotes and even pair them up (if you have MS BT Stack) during gameplay!
All you gotta do is Pause the emulation! That's useful for when your batteries run out during gameplay, for example...
But if you change the WiiMote source (between Emulated, Real or Inactive) you must disconnect and reconnect (Menu Tools -> Connect WiiMote) the WiiMotes affected by the change...
Thanks to jack.fr0st who did all the emulation state notification work!
Now every plugin has a way to know the current emulation state (paused, stopped or playing)
@ayuanx: I thought about doing a PostMessage(g_WiimoteInitialize.hWnd, WM_USER, WIIMOTE_DISCONNECT, current_number); so that the user gets asked to reconnect that WiiMote, trying to avoid having to disconnect and reconnect, but it didn't work because shooting that message only asks to reconnect, doesn't do a disconnect... Do you have any ideas on how to accomplish that?
Also, if anyone could check if Issue 1916 is finally fixed... Or at least when is the cursor being hidden or not...
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4789 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-06 19:26:52 +00:00
|
|
|
void EmuStateChange(PLUGIN_EMUSTATE newState)
|
|
|
|
{
|
|
|
|
g_EmulatorState = newState;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-06-06 21:06:58 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-06-05 19:03:37 +00:00
|
|
|
// Hack to use wx key events
|
2010-06-06 21:06:58 +00:00
|
|
|
volatile bool wxkeystate[WXK_SPECIAL20];
|
|
|
|
#endif
|
2010-06-05 19:03:37 +00:00
|
|
|
|
|
|
|
// Set buttons status from keyboard input. Currently this is done from
|
|
|
|
// wxWidgets in the main application.
|
|
|
|
// --------------
|
|
|
|
void Wiimote_Input(u16 _Key, u8 _UpDown)
|
|
|
|
{
|
|
|
|
#if defined(__APPLE__) && defined(USE_WX) && USE_WX
|
2010-06-06 21:06:58 +00:00
|
|
|
if (_Key < WXK_SPECIAL20)
|
2010-06-05 19:03:37 +00:00
|
|
|
{
|
|
|
|
wxkeystate[_Key] = _UpDown;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2010-04-26 17:51:32 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
/* This function produce Wiimote Input (reports from the Wiimote) in response
|
2009-01-26 07:01:43 +00:00
|
|
|
to Output from the Wii. It's called from WII_IPC_HLE_WiiMote.cpp.
|
|
|
|
|
|
|
|
Switch between real and emulated wiimote: We send all this Input to WiiMoteEmu::InterruptChannel()
|
|
|
|
so that it knows the channel ID and the data reporting mode at all times.
|
|
|
|
*/
|
2009-12-25 22:10:56 +00:00
|
|
|
void Wiimote_InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
|
2009-01-15 06:48:15 +00:00
|
|
|
{
|
2010-06-20 02:17:53 +00:00
|
|
|
// Decide where to send the message
|
2010-01-01 03:19:46 +00:00
|
|
|
if (WiiMoteEmu::WiiMapping[_number].Source <= 1)
|
2009-12-25 22:10:56 +00:00
|
|
|
WiiMoteEmu::InterruptChannel(_number, _channelID, _pData, _Size);
|
2008-12-08 05:25:12 +00:00
|
|
|
#if HAVE_WIIUSE
|
2009-12-07 12:48:39 +00:00
|
|
|
else if (g_RealWiiMotePresent)
|
2010-01-01 00:38:24 +00:00
|
|
|
WiiMoteReal::InterruptChannel(_number, _channelID, _pData, _Size);
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
2009-01-25 23:07:15 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-07-05 05:59:03 +00:00
|
|
|
// Function: Used for the initial Bluetooth HID handshake.
|
2009-12-25 22:10:56 +00:00
|
|
|
void Wiimote_ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
// Debugging
|
2009-12-26 14:16:21 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
|
|
|
DEBUG_LOG(WIIMOTE, "Wiimote_ControlChannel");
|
2009-12-27 19:31:02 +00:00
|
|
|
DEBUG_LOG(WIIMOTE, " Channel ID: %04x", _channelID);
|
2009-12-26 14:16:21 +00:00
|
|
|
std::string Temp = ArrayToString((const u8*)_pData, _Size);
|
|
|
|
DEBUG_LOG(WIIMOTE, " Data: %s", Temp.c_str());
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-01-03 23:05:52 +00:00
|
|
|
// Check for custom communication
|
|
|
|
if(_channelID == 99 && *(const u8*)_pData == WIIMOTE_DISCONNECT)
|
|
|
|
{
|
|
|
|
WiiMoteEmu::g_ReportingAuto[_number] = false;
|
|
|
|
WARN_LOG(WIIMOTE, "Wiimote: #%i Disconnected", _number);
|
|
|
|
#ifdef _WIN32
|
2010-07-30 03:51:49 +00:00
|
|
|
PostMessage((HWND)g_WiimoteInitialize.hWnd, WM_USER, WIIMOTE_DISCONNECT, _number);
|
2010-01-03 23:05:52 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-01 03:19:46 +00:00
|
|
|
if (WiiMoteEmu::WiiMapping[_number].Source <= 1)
|
2009-12-25 22:10:56 +00:00
|
|
|
WiiMoteEmu::ControlChannel(_number, _channelID, _pData, _Size);
|
2008-12-08 05:25:12 +00:00
|
|
|
#if HAVE_WIIUSE
|
2009-12-07 12:48:39 +00:00
|
|
|
else if (g_RealWiiMotePresent)
|
2010-01-01 00:38:24 +00:00
|
|
|
WiiMoteReal::ControlChannel(_number, _channelID, _pData, _Size);
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
// This sends a Data Report from the Wiimote. See SystemTimers.cpp for the documentation of this update.
|
2009-12-25 22:10:56 +00:00
|
|
|
void Wiimote_Update(int _number)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
// This functions will send:
|
|
|
|
// Emulated Wiimote: Only data reports 0x30-0x37
|
|
|
|
// Real Wiimote: Both data reports 0x30-0x37 and all other read reports
|
2010-01-01 03:19:46 +00:00
|
|
|
if (WiiMoteEmu::WiiMapping[_number].Source <= 1)
|
2009-12-25 22:10:56 +00:00
|
|
|
WiiMoteEmu::Update(_number);
|
2008-12-08 05:25:12 +00:00
|
|
|
#if HAVE_WIIUSE
|
2009-01-25 23:07:15 +00:00
|
|
|
else if (g_RealWiiMotePresent)
|
2010-01-01 00:38:24 +00:00
|
|
|
WiiMoteReal::Update(_number);
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
2009-02-01 13:01:50 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
/*
|
2009-02-01 13:01:50 +00:00
|
|
|
// Debugging
|
|
|
|
#ifdef _WIN32
|
2009-02-07 03:16:41 +00:00
|
|
|
if( GetAsyncKeyState(VK_HOME) && g_DebugComm ) g_DebugComm = false; // Page Down
|
2009-02-01 13:01:50 +00:00
|
|
|
else if (GetAsyncKeyState(VK_HOME) && !g_DebugComm ) g_DebugComm = true;
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
if( GetAsyncKeyState(VK_PRIOR) && g_DebugData ) g_DebugData = false; // Page Up
|
2009-02-01 13:01:50 +00:00
|
|
|
else if (GetAsyncKeyState(VK_PRIOR) && !g_DebugData ) g_DebugData = true;
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
if( GetAsyncKeyState(VK_NEXT) && g_DebugAccelerometer ) g_DebugAccelerometer = false; // Home
|
2009-02-01 13:01:50 +00:00
|
|
|
else if (GetAsyncKeyState(VK_NEXT) && !g_DebugAccelerometer ) g_DebugAccelerometer = true;
|
2009-02-07 03:16:41 +00:00
|
|
|
|
2009-09-15 02:12:55 +00:00
|
|
|
if( GetAsyncKeyState(VK_END) && g_DebugCustom ) { g_DebugCustom = false; DEBUG_LOG(WIIMOTE, "Custom Debug: Off");} // End
|
|
|
|
else if (GetAsyncKeyState(VK_END) && !g_DebugCustom ) {g_DebugCustom = true; DEBUG_LOG(WIIMOTE, "Custom Debug: Off");}
|
2009-02-01 13:01:50 +00:00
|
|
|
#endif
|
2009-12-27 19:31:02 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-07-02 19:00:27 +00:00
|
|
|
unsigned int Wiimote_GetAttachedControllers()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-05-29 10:09:24 +00:00
|
|
|
unsigned int attached = 0;
|
|
|
|
for (unsigned int i=0; i<4; ++i)
|
|
|
|
if (WiiMoteEmu::WiiMapping[i].Source)
|
|
|
|
attached |= (1 << i);
|
|
|
|
return attached;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-20 02:17:53 +00:00
|
|
|
// Unpair Wiimotes, TODO: Add linux/osx un-pair function
|
|
|
|
unsigned int Wiimote_UnPairWiimotes()
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (g_Config.bUnpairRealWiimote)
|
|
|
|
return WiiMoteReal::WiimotePairUp(true);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
2009-02-15 18:23:42 +00:00
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
// Supporting functions
|
2009-02-15 02:01:43 +00:00
|
|
|
|
2010-04-12 01:33:10 +00:00
|
|
|
// Check if the render window is in focus
|
2009-07-05 05:59:03 +00:00
|
|
|
|
2009-02-01 15:40:13 +00:00
|
|
|
bool IsFocus()
|
|
|
|
{
|
2010-04-12 01:33:10 +00:00
|
|
|
return g_WiimoteInitialize.pRendererHasFocus();
|
2009-02-01 15:40:13 +00:00
|
|
|
}
|
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
/* Returns a timestamp with three decimals for precise time comparisons. The return format is
|
|
|
|
of the form seconds.milleseconds for example 1234.123. The leding seconds have no particular meaning
|
|
|
|
but are just there to enable use to tell if we have entered a new second or now. */
|
|
|
|
// -----------------
|