2008-12-08 05:25:12 +00:00
|
|
|
|
// 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/
|
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Includes
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
#include "Common.h" // Common
|
|
|
|
|
#include "pluginspecs_wiimote.h"
|
|
|
|
|
#include "StringUtil.h" // For ArrayToString
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "wiimote_hid.h"
|
2009-01-29 08:35:29 +00:00
|
|
|
|
#include "main.h"
|
2009-01-07 02:59:19 +00:00
|
|
|
|
#include "EmuMain.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "EmuSubroutines.h"
|
|
|
|
|
#include "EmuDefinitions.h"
|
2009-01-17 14:28:09 +00:00
|
|
|
|
#include "Logging.h" // For startConsoleWin, Console::Print, GetConsoleHwnd
|
2009-01-07 02:59:19 +00:00
|
|
|
|
#include "Config.h" // For g_Config
|
|
|
|
|
//////////////////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
extern SWiimoteInitialize g_WiimoteInitialize;
|
|
|
|
|
|
|
|
|
|
namespace WiiMoteEmu
|
|
|
|
|
{
|
|
|
|
|
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
//**************************************************************************************
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// Recorded movements
|
2009-02-03 00:59:26 +00:00
|
|
|
|
//**************************************************************************************
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
|
|
|
|
// ------------------------------------------
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Variables: 0 = Wiimote, 1 = Nunchuck
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// ----------------
|
2009-02-03 00:59:26 +00:00
|
|
|
|
int g_RecordingPlaying[3]; //g_RecordingPlaying[0] = -1; g_RecordingPlaying[1] = -1;
|
|
|
|
|
int g_RecordingCounter[3]; //g_RecordingCounter[0] = 0; g_RecordingCounter[1] = 0;
|
|
|
|
|
int g_RecordingPoint[3]; //g_RecordingPoint[0] = 0; g_RecordingPoint[1] = 0;
|
|
|
|
|
double g_RecordingStart[3]; //g_RecordingStart[0] = 0; g_RecordingStart[1] = 0;
|
|
|
|
|
double g_RecordingCurrentTime[3]; //g_RecordingCurrentTime[0] = 0; g_RecordingCurrentTime[1] = 0;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// --------------------------
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
template<class IRReportType>
|
|
|
|
|
bool RecordingPlayAccIR(u8 &_x, u8 &_y, u8 &_z, IRReportType &_IR, int Wm)
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
|
|
|
|
// Return if the list is empty
|
2009-02-01 13:01:50 +00:00
|
|
|
|
if(VRecording.at(g_RecordingPlaying[Wm]).Recording.size() == 0)
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
g_RecordingPlaying[Wm] = -1;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
Console::Print("Empty\n\n");
|
2009-02-03 00:59:26 +00:00
|
|
|
|
return false;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return if the playback speed is unset
|
2009-02-01 13:01:50 +00:00
|
|
|
|
if(VRecording.at(g_RecordingPlaying[Wm]).PlaybackSpeed < 0)
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
Console::Print("PlaybackSpeed empty: %i\n\n", g_RecordingPlaying[Wm]);
|
|
|
|
|
g_RecordingPlaying[Wm] = -1;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get IR bytes
|
|
|
|
|
int IRBytes = VRecording.at(g_RecordingPlaying[Wm]).IRBytes;
|
|
|
|
|
|
|
|
|
|
// Return if the IR mode is wrong
|
|
|
|
|
if (Wm == WM_RECORDING_IR
|
|
|
|
|
&& ( (IRBytes == 12 && !(g_ReportingMode == 0x33))
|
|
|
|
|
|| (IRBytes == 10 && !(g_ReportingMode == 0x36 || g_ReportingMode == 0x37))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
Console::Print("Wrong IR mode: %i\n\n", g_RecordingPlaying[Wm]);
|
|
|
|
|
g_RecordingPlaying[Wm] = -1;
|
|
|
|
|
return false;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get starting time
|
2009-02-01 13:01:50 +00:00
|
|
|
|
if(g_RecordingCounter[Wm] == 0)
|
|
|
|
|
{
|
|
|
|
|
Console::Print("\n\nBegin\n");
|
|
|
|
|
g_RecordingStart[Wm] = GetDoubleTime();
|
|
|
|
|
}
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
|
|
|
|
// Get current time
|
2009-02-01 13:01:50 +00:00
|
|
|
|
g_RecordingCurrentTime[Wm] = GetDoubleTime() - g_RecordingStart[Wm];
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
|
|
|
|
// Modify the current time
|
2009-02-01 13:01:50 +00:00
|
|
|
|
g_RecordingCurrentTime[Wm] *= ((25.0 + (double)VRecording.at(g_RecordingPlaying[Wm]).PlaybackSpeed * 25.0) / 100.0);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
|
|
|
|
// Select reading
|
2009-02-01 13:01:50 +00:00
|
|
|
|
for (int i = 0; i < VRecording.at(g_RecordingPlaying[Wm]).Recording.size(); i++)
|
|
|
|
|
if (VRecording.at(g_RecordingPlaying[Wm]).Recording.at(i).Time > g_RecordingCurrentTime[Wm])
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
g_RecordingPoint[Wm] = i;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
break; // Break loop
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return if we are at the end of the list
|
2009-02-01 13:01:50 +00:00
|
|
|
|
if(g_RecordingCurrentTime[Wm] >=
|
|
|
|
|
VRecording.at(g_RecordingPlaying[Wm]).Recording.at(
|
|
|
|
|
VRecording.at(g_RecordingPlaying[Wm]).Recording.size() - 1).Time)
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
g_RecordingCounter[Wm] = 0;
|
|
|
|
|
g_RecordingPlaying[Wm] = -1;
|
|
|
|
|
g_RecordingStart[Wm] = 0;
|
|
|
|
|
g_RecordingCurrentTime[Wm] = 0;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
Console::Print("End\n\n");
|
2009-02-03 00:59:26 +00:00
|
|
|
|
return false;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update values
|
2009-02-01 13:01:50 +00:00
|
|
|
|
_x = VRecording.at(g_RecordingPlaying[Wm]).Recording.at(g_RecordingPoint[Wm]).x;
|
|
|
|
|
_y = VRecording.at(g_RecordingPlaying[Wm]).Recording.at(g_RecordingPoint[Wm]).y;
|
|
|
|
|
_z = VRecording.at(g_RecordingPlaying[Wm]).Recording.at(g_RecordingPoint[Wm]).z;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
if(Wm == WM_RECORDING_IR) memcpy(&_IR, VRecording.at(g_RecordingPlaying[Wm]).Recording.at(g_RecordingPoint[Wm]).IR, IRBytes);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
/**/
|
|
|
|
|
if (g_DebugAccelerometer)
|
|
|
|
|
{
|
|
|
|
|
Console::ClearScreen();
|
|
|
|
|
Console::Print("Current time: %f %f %i %i\n",
|
|
|
|
|
VRecording.at(g_RecordingPlaying[Wm]).Recording.at(g_RecordingPoint[Wm]).Time, g_RecordingCurrentTime[Wm],
|
|
|
|
|
VRecording.at(g_RecordingPlaying[Wm]).Recording.size(), g_RecordingPoint[Wm]
|
|
|
|
|
);
|
|
|
|
|
Console::Print("Accel x, y, z: %03u %03u %03u\n\n", _x, _y, _z);
|
|
|
|
|
}
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
g_RecordingCounter[Wm]++;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/* Because the playback is neatly controlled by RecordingPlayAccIR() we use these functions to be able to
|
|
|
|
|
use RecordingPlayAccIR() for both accelerometer and IR recordings */
|
|
|
|
|
bool RecordingPlay(u8 &_x, u8 &_y, u8 &_z, int Wm)
|
|
|
|
|
{
|
|
|
|
|
wm_ir_basic IR;
|
|
|
|
|
return RecordingPlayAccIR(_x, _y, _z, IR, Wm);
|
|
|
|
|
}
|
|
|
|
|
template<class IRReportType>
|
|
|
|
|
bool RecordingPlayIR(IRReportType &_IR)
|
|
|
|
|
{
|
|
|
|
|
u8 x, y, z;
|
|
|
|
|
return RecordingPlayAccIR(x, y, z, _IR, 2);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// Check if we should start the playback of a recording. Once it has been started it can not currently
|
|
|
|
|
// be stopped, it will always run to the end of the recording.
|
|
|
|
|
int RecordingCheckKeys(int Wiimote)
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
2009-02-03 00:59:26 +00:00
|
|
|
|
//Console::Print("RecordingCheckKeys: %i\n", Wiimote);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------------------------
|
|
|
|
|
// Don't allow multiple action keys
|
|
|
|
|
// --------------
|
|
|
|
|
// Return if we have both a Shift, Ctrl, and Alt
|
|
|
|
|
if ( GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) ) return -1;
|
|
|
|
|
// Return if we have both a Shift and Ctrl
|
2009-01-29 08:35:29 +00:00
|
|
|
|
if ( (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_CONTROL)) ) return -1;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// Return if we have both a Ctrl and Alt
|
|
|
|
|
if ( (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU)) ) return -1;
|
|
|
|
|
// Return if we have both a Shift and Alt
|
|
|
|
|
if ( (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_MENU)) ) return -1;
|
|
|
|
|
// ---------------------
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
|
|
|
|
// Return if we don't have both a Wiimote and Shift
|
2009-02-03 00:59:26 +00:00
|
|
|
|
if ( Wiimote == 0 && !GetAsyncKeyState(VK_SHIFT) ) return -1;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
|
|
|
|
// Return if we don't have both a Nunchuck and Ctrl
|
2009-02-03 00:59:26 +00:00
|
|
|
|
if ( Wiimote == 1 && !GetAsyncKeyState(VK_CONTROL) ) return -1;
|
|
|
|
|
|
|
|
|
|
// Return if we don't have both a IR call and Alt
|
|
|
|
|
if ( Wiimote == 2 && !GetAsyncKeyState(VK_MENU) ) return -1;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
|
|
|
|
// Check if we have exactly one numerical key
|
|
|
|
|
int Keys = 0;
|
|
|
|
|
for(int i = 0; i < 10; i++)
|
|
|
|
|
{
|
|
|
|
|
std::string Key = StringFromFormat("%i", i);
|
|
|
|
|
if(GetAsyncKeyState(Key[0])) Keys++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Console::Print("RecordingCheckKeys: %i\n", Keys);
|
|
|
|
|
|
|
|
|
|
// Return if we have less than or more than one
|
|
|
|
|
if (Keys != 1) return -1;
|
|
|
|
|
|
|
|
|
|
// Check which key it is
|
|
|
|
|
int Key;
|
|
|
|
|
for(int i = 0; i < 10; i++)
|
|
|
|
|
{
|
|
|
|
|
std::string TmpKey = StringFromFormat("%i", i);
|
|
|
|
|
if(GetAsyncKeyState(TmpKey[0])) { Key = i; break; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we have a HotKey match
|
|
|
|
|
bool Match = false;
|
|
|
|
|
for(int i = 0; i < RECORDING_ROWS; i++)
|
|
|
|
|
{
|
2009-01-29 08:51:23 +00:00
|
|
|
|
if (VRecording.at(i).HotKey == Key)
|
|
|
|
|
{
|
|
|
|
|
//Console::Print("Match: %i %i\n", i, Key);
|
|
|
|
|
Match = true;
|
|
|
|
|
Key = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return nothing if we don't have a match
|
|
|
|
|
if (!Match) return -1;
|
|
|
|
|
|
|
|
|
|
// Return the match
|
|
|
|
|
return Key;
|
|
|
|
|
#else
|
|
|
|
|
return -1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//******************************************************************************
|
|
|
|
|
// Subroutines
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
|
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
// Wiimote core buttons
|
|
|
|
|
// ---------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
void FillReportInfo(wm_core& _core)
|
|
|
|
|
{
|
2009-01-28 16:09:08 +00:00
|
|
|
|
/* This has to be filled with zeroes (and not for example 0xff) because when no buttons are pressed the
|
2009-01-07 02:59:19 +00:00
|
|
|
|
value is 00 00 */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
memset(&_core, 0x00, sizeof(wm_core));
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2009-02-01 15:40:13 +00:00
|
|
|
|
// Check that Dolphin is in focus
|
|
|
|
|
if (!IsFocus()) return;
|
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// Check the mouse position. Don't allow mouse clicks from outside the window.
|
|
|
|
|
float x, y; GetMousePos(x, y);
|
|
|
|
|
bool InsideScreen = !(x < 0 || x > 1 || y < 0 || y > 1);
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// Allow both mouse buttons and keyboard to press a and b
|
2009-01-31 01:18:57 +00:00
|
|
|
|
if((GetAsyncKeyState(VK_LBUTTON) && InsideScreen) || GetAsyncKeyState('A') ? 1 : 0)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_core.a = 1;
|
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
if((GetAsyncKeyState(VK_RBUTTON) && InsideScreen) || GetAsyncKeyState('B') ? 1 : 0)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_core.b = 1;
|
|
|
|
|
|
|
|
|
|
_core.one = GetAsyncKeyState('1') ? 1 : 0;
|
|
|
|
|
_core.two = GetAsyncKeyState('2') ? 1 : 0;
|
|
|
|
|
_core.plus = GetAsyncKeyState('P') ? 1 : 0;
|
|
|
|
|
_core.minus = GetAsyncKeyState('M') ? 1 : 0;
|
|
|
|
|
_core.home = GetAsyncKeyState('H') ? 1 : 0;
|
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
/* Sideways controls (for example for Wario Land) if the Wiimote is intended to be held sideways */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
if(g_Config.bSidewaysDPad)
|
|
|
|
|
{
|
|
|
|
|
_core.left = GetAsyncKeyState(VK_DOWN) ? 1 : 0;
|
|
|
|
|
_core.up = GetAsyncKeyState(VK_LEFT) ? 1 : 0;
|
|
|
|
|
_core.right = GetAsyncKeyState(VK_UP) ? 1 : 0;
|
|
|
|
|
_core.down = GetAsyncKeyState(VK_RIGHT) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_core.left = GetAsyncKeyState(VK_LEFT) ? 1 : 0;
|
|
|
|
|
_core.up = GetAsyncKeyState(VK_UP) ? 1 : 0;
|
|
|
|
|
_core.right = GetAsyncKeyState(VK_RIGHT) ? 1 : 0;
|
|
|
|
|
_core.down = GetAsyncKeyState(VK_DOWN) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
// TODO: fill in
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2009-01-28 16:09:08 +00:00
|
|
|
|
//////////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
|
2009-01-28 16:18:47 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2009-01-28 16:09:08 +00:00
|
|
|
|
// Wiimote accelerometer
|
|
|
|
|
// ---------------
|
|
|
|
|
/* The accelerometer x, y and z values range from 0x00 to 0xff with the default netural values
|
|
|
|
|
being [y = 0x84, x = 0x84, z = 0x9f] according to a source. The extremes are 0x00 for (-)
|
|
|
|
|
and 0xff for (+). It's important that all values are not 0x80, the mouse pointer can disappear
|
|
|
|
|
from the screen permanently then, until z is adjusted back. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------
|
2009-01-28 16:09:08 +00:00
|
|
|
|
// Global declarations for FillReportAcc: These variables are global so they can be changed during debugging
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//int A = 0, B = 128, C = 64; // for debugging
|
|
|
|
|
//int a = 1, b = 1, c = 2, d = -2; // for debugging
|
|
|
|
|
//int consoleDisplay = 0;
|
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
u8 x, y, z;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
int shake = -1, yhistsize = 15; // for the shake function
|
|
|
|
|
std::vector<u8> yhist(15); // for the tilt function
|
|
|
|
|
|
|
|
|
|
void FillReportAcc(wm_accel& _acc)
|
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Create shortcut names for the default neutral values
|
|
|
|
|
int X = g_accel.cal_zero.x, Y = g_accel.cal_zero.y, Z = g_accel.cal_zero.z + g_accel.cal_g.z;
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _WIN32
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// ------------------------------------
|
|
|
|
|
// Recorded movements
|
|
|
|
|
// --------------
|
|
|
|
|
// Check for a playback command
|
2009-02-01 13:01:50 +00:00
|
|
|
|
if(g_RecordingPlaying[0] < 0)
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
2009-02-03 00:59:26 +00:00
|
|
|
|
g_RecordingPlaying[0] = RecordingCheckKeys(0);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// If the recording reached the end or failed somehow we will not return
|
|
|
|
|
if (RecordingPlay(_acc.x, _acc.y, _acc.z, 0)) return;
|
2009-02-01 13:01:50 +00:00
|
|
|
|
//Console::Print("X, Y, Z: %u %u %u\n", _acc.x, _acc.y, _acc.z);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
// ---------------------
|
|
|
|
|
|
|
|
|
|
|
2009-02-01 15:40:13 +00:00
|
|
|
|
// Check that Dolphin is in focus
|
|
|
|
|
if (!IsFocus())
|
|
|
|
|
{
|
|
|
|
|
_acc.x = X;
|
|
|
|
|
_acc.y = y;
|
|
|
|
|
_acc.z = z;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// ------------------------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// Wiimote to Gamepad translations
|
|
|
|
|
// ----------
|
|
|
|
|
// Tilting Wiimote (Wario Land aiming, Mario Kart steering) : For some reason 150 and 40
|
|
|
|
|
// seemed like decent starting values.
|
|
|
|
|
if(GetAsyncKeyState('3'))
|
|
|
|
|
{
|
|
|
|
|
//if(a < 128) // for debugging
|
|
|
|
|
if(y < 250)
|
|
|
|
|
{
|
|
|
|
|
y += 4; // aim left
|
|
|
|
|
//a += c; // debugging values
|
|
|
|
|
//y = A + a; // aim left
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(GetAsyncKeyState('4'))
|
|
|
|
|
{
|
|
|
|
|
// if(b < 128) // for debugging
|
|
|
|
|
if(y > 5)
|
|
|
|
|
{
|
|
|
|
|
y -= 4; // aim right
|
|
|
|
|
//b -= d; // debugging values
|
|
|
|
|
//y = B + b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Single shake of Wiimote while holding it sideways (Wario Land pound ground)
|
|
|
|
|
if(GetAsyncKeyState('S'))
|
|
|
|
|
z = 0;
|
|
|
|
|
else
|
|
|
|
|
z = Z;*/
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('S'))
|
|
|
|
|
{
|
|
|
|
|
z = 0;
|
|
|
|
|
y = 0;
|
|
|
|
|
shake = 2;
|
|
|
|
|
}
|
2008-12-26 10:53:32 +00:00
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
if(shake == 2)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
|
|
|
|
z = 128;
|
|
|
|
|
y = 0;
|
|
|
|
|
shake = 1;
|
|
|
|
|
}
|
|
|
|
|
else if(shake == 1)
|
|
|
|
|
{
|
|
|
|
|
z = Z;
|
|
|
|
|
y = Y;
|
|
|
|
|
shake = -1;
|
|
|
|
|
}
|
2009-02-01 13:01:50 +00:00
|
|
|
|
else // the default Z if nothing is pressed
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
|
|
|
|
z = Z;
|
|
|
|
|
}
|
|
|
|
|
// ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------
|
|
|
|
|
// For tilting: add new value and move all back
|
|
|
|
|
// ----------
|
|
|
|
|
bool ypressed = false;
|
|
|
|
|
|
2008-12-26 10:53:32 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-12-08 05:25:12 +00:00
|
|
|
|
yhist[yhist.size() - 1] = (
|
|
|
|
|
GetAsyncKeyState('3') ? true : false
|
|
|
|
|
|| GetAsyncKeyState('4') ? true : false
|
|
|
|
|
|| shake > 0
|
|
|
|
|
);
|
2008-12-26 10:53:32 +00:00
|
|
|
|
#endif
|
2009-01-24 01:50:23 +00:00
|
|
|
|
if(yhistsize > (int)yhist.size()) yhistsize = (int)yhist.size();
|
2008-12-08 05:25:12 +00:00
|
|
|
|
for (int i = 1; i < yhistsize; i++)
|
|
|
|
|
{
|
|
|
|
|
yhist[i-1] = yhist[i];
|
|
|
|
|
if(yhist[i]) ypressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!ypressed) // y was not pressed a single time
|
|
|
|
|
{
|
|
|
|
|
y = Y; // this is the default value that will occur most of the time
|
|
|
|
|
//a = 0; // for debugging
|
|
|
|
|
//b = 0;
|
|
|
|
|
}
|
2008-12-26 10:53:32 +00:00
|
|
|
|
// else if(!GetAsyncKeyState('3') && !GetAsyncKeyState('4'))
|
|
|
|
|
// {
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// perhaps start dropping acceleration back?
|
2008-12-26 10:53:32 +00:00
|
|
|
|
// }
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write values
|
|
|
|
|
_acc.x = X;
|
|
|
|
|
_acc.y = y;
|
|
|
|
|
_acc.z = z;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------
|
|
|
|
|
// Debugging for translating Wiimote to Keyboard (or Gamepad)
|
|
|
|
|
// ----------
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
// Toogle console display
|
|
|
|
|
if(GetAsyncKeyState('U'))
|
|
|
|
|
{
|
|
|
|
|
if(consoleDisplay < 2)
|
|
|
|
|
consoleDisplay ++;
|
|
|
|
|
else
|
|
|
|
|
consoleDisplay = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('5'))
|
|
|
|
|
A-=1;
|
|
|
|
|
else if(GetAsyncKeyState('6'))
|
|
|
|
|
A+=1;
|
|
|
|
|
if(GetAsyncKeyState('7'))
|
|
|
|
|
B-=1;
|
|
|
|
|
else if(GetAsyncKeyState('8'))
|
|
|
|
|
B+=1;
|
|
|
|
|
if(GetAsyncKeyState('9'))
|
|
|
|
|
C-=1;
|
|
|
|
|
else if(GetAsyncKeyState('0'))
|
|
|
|
|
C+=1;
|
|
|
|
|
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD3))
|
|
|
|
|
d-=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD6))
|
|
|
|
|
d+=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_ADD))
|
|
|
|
|
yhistsize-=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_SUBTRACT))
|
|
|
|
|
yhistsize+=1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState(VK_INSERT))
|
|
|
|
|
AX-=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_DELETE))
|
|
|
|
|
AX+=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_HOME))
|
|
|
|
|
AY-=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_END))
|
|
|
|
|
AY+=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_SHIFT))
|
|
|
|
|
AZ-=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_CONTROL))
|
|
|
|
|
AZ+=1;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD1))
|
|
|
|
|
X+=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD2))
|
|
|
|
|
X-=1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD4))
|
|
|
|
|
Y+=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD5))
|
|
|
|
|
Y-=1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD7))
|
|
|
|
|
Z+=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD8))
|
|
|
|
|
Z-=1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if(consoleDisplay == 0)
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("x: %03i | y: %03i | z: %03i | A:%i B:%i C:%i a:%i b:%i c:%i d:%i X:%i Y:%i Z:%i\n",
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_acc.x, _acc.y, _acc.z,
|
|
|
|
|
A, B, C,
|
|
|
|
|
a, b, c, d,
|
|
|
|
|
X, Y, Z
|
|
|
|
|
);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("x: %03i | y: %03i | z: %03i | X:%i Y:%i Z:%i | AX:%i AY:%i AZ:%i \n",
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_acc.x, _acc.y, _acc.z,
|
|
|
|
|
X, Y, Z,
|
|
|
|
|
AX, AY, AZ
|
|
|
|
|
);*/
|
|
|
|
|
}
|
2009-01-28 16:09:08 +00:00
|
|
|
|
/////////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
// The extended 12 byte (3 byte per object) reporting
|
|
|
|
|
// ---------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
void FillReportIR(wm_ir_extended& _ir0, wm_ir_extended& _ir1)
|
|
|
|
|
{
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------------------------
|
|
|
|
|
// Recorded movements
|
|
|
|
|
// --------------
|
|
|
|
|
// Check for a playback command
|
|
|
|
|
if(g_RecordingPlaying[2] < 0)
|
|
|
|
|
{
|
|
|
|
|
g_RecordingPlaying[2] = RecordingCheckKeys(2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Console::Print("X, Y, Z: %u %u %u\n", _acc.x, _acc.y, _acc.z);
|
|
|
|
|
if (RecordingPlayIR(_ir0)) return;
|
|
|
|
|
}
|
|
|
|
|
// ---------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
|
|
|
|
|
// --------------------------------------
|
|
|
|
|
/* The calibration is controlled by these values, their absolute value and
|
|
|
|
|
the relative distance between between them control the calibration. WideScreen mode
|
|
|
|
|
has its own settings. */
|
|
|
|
|
// ----------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
int Top, Left, Right, Bottom, SensorBarRadius;
|
|
|
|
|
if(g_Config.bWideScreen)
|
|
|
|
|
{
|
|
|
|
|
Top = wTOP; Left = wLEFT; Right = wRIGHT;
|
|
|
|
|
Bottom = wBOTTOM; SensorBarRadius = wSENSOR_BAR_RADIUS;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Top = TOP; Left = LEFT; Right = RIGHT;
|
|
|
|
|
Bottom = BOTTOM; SensorBarRadius = SENSOR_BAR_RADIUS;
|
|
|
|
|
}
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
/* Fill with 0xff if empty. The real Wiimote seems to use 0xff when it doesn't see a certain point,
|
|
|
|
|
at least from how WiiMoteReal::SendEvent() works. */
|
2009-01-31 01:18:57 +00:00
|
|
|
|
memset(&_ir0, 0xff, sizeof(wm_ir_extended));
|
|
|
|
|
memset(&_ir1, 0xff, sizeof(wm_ir_extended));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
float MouseX, MouseY;
|
|
|
|
|
GetMousePos(MouseX, MouseY);
|
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// If we are outside the screen leave the values at 0xff
|
|
|
|
|
if(MouseX > 1 || MouseX < 0 || MouseY > 1 || MouseY < 0) return;
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// --------------------------------------
|
|
|
|
|
// Actual position calculation
|
|
|
|
|
// ----------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
int y0 = Top + (MouseY * (Bottom - Top));
|
|
|
|
|
int y1 = Top + (MouseY * (Bottom - Top));
|
|
|
|
|
|
|
|
|
|
int x0 = Left + (MouseX * (Right - Left)) - SensorBarRadius;
|
|
|
|
|
int x1 = Left + (MouseX * (Right - Left)) + SensorBarRadius;
|
|
|
|
|
|
|
|
|
|
x0 = 1023 - x0;
|
|
|
|
|
_ir0.x = x0 & 0xFF;
|
|
|
|
|
_ir0.y = y0 & 0xFF;
|
|
|
|
|
_ir0.size = 10;
|
|
|
|
|
_ir0.xHi = x0 >> 8;
|
|
|
|
|
_ir0.yHi = y0 >> 8;
|
|
|
|
|
|
|
|
|
|
x1 = 1023 - x1;
|
|
|
|
|
_ir1.x = x1 & 0xFF;
|
|
|
|
|
_ir1.y = y1 & 0xFF;
|
|
|
|
|
_ir1.size = 10;
|
|
|
|
|
_ir1.xHi = x1 >> 8;
|
|
|
|
|
_ir1.yHi = y1 >> 8;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
// ----------------------------
|
|
|
|
|
// Debugging for calibration
|
|
|
|
|
// ----------
|
|
|
|
|
/*
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD1))
|
|
|
|
|
Right +=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD2))
|
|
|
|
|
Right -=1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD4))
|
|
|
|
|
Left +=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD5))
|
|
|
|
|
Left -=1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD7))
|
|
|
|
|
Top += 1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD8))
|
|
|
|
|
Top -= 1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD6))
|
|
|
|
|
Bottom += 1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD3))
|
|
|
|
|
Bottom -= 1;
|
|
|
|
|
if(GetAsyncKeyState(VK_INSERT))
|
|
|
|
|
SensorBarRadius += 1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_DELETE))
|
|
|
|
|
SensorBarRadius -= 1;
|
|
|
|
|
|
|
|
|
|
//ClearScreen();
|
|
|
|
|
//if(consoleDisplay == 1)
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("x0:%03i x1:%03i y0:%03i y1:%03i irx0:%03i y0:%03i x1:%03i y1:%03i | T:%i L:%i R:%i B:%i S:%i\n",
|
2008-12-08 05:25:12 +00:00
|
|
|
|
x0, x1, y0, y1, _ir0.x, _ir0.y, _ir1.x, _ir1.y, Top, Left, Right, Bottom, SensorBarRadius
|
|
|
|
|
);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("\n");
|
|
|
|
|
Console::Print("ir0.x:%02x xHi:%02x ir1.x:%02x xHi:%02x | ir0.y:%02x yHi:%02x ir1.y:%02x yHi:%02x | 1.s:%02x 2:%02x\n",
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_ir0.x, _ir0.xHi, _ir1.x, _ir1.xHi,
|
|
|
|
|
_ir0.y, _ir0.yHi, _ir1.y, _ir1.yHi,
|
|
|
|
|
_ir0.size, _ir1.size
|
|
|
|
|
);*/
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// The 10 byte reporting used when an extension is connected
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// ---------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1)
|
|
|
|
|
{
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------------------------
|
|
|
|
|
// Recorded movements
|
|
|
|
|
// --------------
|
|
|
|
|
// Check for a playback command
|
|
|
|
|
if(g_RecordingPlaying[2] < 0)
|
|
|
|
|
{
|
|
|
|
|
g_RecordingPlaying[2] = RecordingCheckKeys(2);
|
|
|
|
|
}
|
|
|
|
|
// We are playing back a recording, we don't accept any manual input this time
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Console::Print("X, Y, Z: %u %u %u\n", _acc.x, _acc.y, _acc.z);
|
|
|
|
|
if (RecordingPlayIR(_ir0)) return;
|
|
|
|
|
}
|
|
|
|
|
// ---------------------
|
|
|
|
|
|
|
|
|
|
// --------------------------------------
|
|
|
|
|
/* See calibration description above */
|
|
|
|
|
// ----------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
int Top, Left, Right, Bottom, SensorBarRadius;
|
|
|
|
|
|
|
|
|
|
if(g_Config.bWideScreen)
|
|
|
|
|
{
|
|
|
|
|
Top = wTOP; Left = wLEFT; Right = wRIGHT;
|
|
|
|
|
Bottom = wBOTTOM; SensorBarRadius = wSENSOR_BAR_RADIUS;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Top = TOP; Left = LEFT; Right = RIGHT;
|
|
|
|
|
Bottom = BOTTOM; SensorBarRadius = SENSOR_BAR_RADIUS;
|
|
|
|
|
}
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// Fill with 0xff if empty
|
|
|
|
|
memset(&_ir0, 0xff, sizeof(wm_ir_basic));
|
|
|
|
|
memset(&_ir1, 0xff, sizeof(wm_ir_basic));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
float MouseX, MouseY;
|
|
|
|
|
GetMousePos(MouseX, MouseY);
|
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// If we are outside the screen leave the values at 0xff
|
|
|
|
|
if(MouseX > 1 || MouseX < 0 || MouseY > 1 || MouseY < 0) return;
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
int y1 = Top + (MouseY * (Bottom - Top));
|
|
|
|
|
int y2 = Top + (MouseY * (Bottom - Top));
|
|
|
|
|
|
|
|
|
|
int x1 = Left + (MouseX * (Right - Left)) - SensorBarRadius;
|
|
|
|
|
int x2 = Left + (MouseX * (Right - Left)) + SensorBarRadius;
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
/* As with the extented report we settle with emulating two out of four possible objects */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
x1 = 1023 - x1;
|
|
|
|
|
_ir0.x1 = x1 & 0xff;
|
|
|
|
|
_ir0.y1 = y1 & 0xff;
|
|
|
|
|
_ir0.x1Hi = (x1 >> 8); // we are dealing with 2 bit values here
|
|
|
|
|
_ir0.y1Hi = (y1 >> 8);
|
|
|
|
|
|
|
|
|
|
x2 = 1023 - x2;
|
|
|
|
|
_ir0.x2 = x2 & 0xff;
|
|
|
|
|
_ir0.y2 = y2 & 0xff;
|
|
|
|
|
_ir0.x2Hi = (x2 >> 8);
|
|
|
|
|
_ir0.y2Hi = (y2 >> 8);
|
|
|
|
|
|
|
|
|
|
// I don't understand't the & 0x03, should we do that?
|
|
|
|
|
//_ir1.x1Hi = (x1 >> 8) & 0x3;
|
|
|
|
|
//_ir1.y1Hi = (y1 >> 8) & 0x3;
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// Debugging for calibration
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ----------
|
|
|
|
|
/*
|
2008-12-08 05:25:12 +00:00
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD1))
|
|
|
|
|
Right +=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD2))
|
|
|
|
|
Right -=1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD4))
|
|
|
|
|
Left +=1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD5))
|
|
|
|
|
Left -=1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD7))
|
|
|
|
|
Top += 1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD8))
|
|
|
|
|
Top -= 1;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD6))
|
|
|
|
|
Bottom += 1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_NUMPAD3))
|
|
|
|
|
Bottom -= 1;
|
|
|
|
|
if(GetAsyncKeyState(VK_INSERT))
|
|
|
|
|
SensorBarRadius += 1;
|
|
|
|
|
else if(GetAsyncKeyState(VK_DELETE))
|
|
|
|
|
SensorBarRadius -= 1;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//ClearScreen();
|
|
|
|
|
//if(consoleDisplay == 1)
|
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("x1:%03i x2:%03i y1:%03i y2:%03i irx1:%02x y1:%02x x2:%02x y2:%02x | T:%i L:%i R:%i B:%i S:%i\n",
|
2008-12-08 05:25:12 +00:00
|
|
|
|
x1, x2, y1, y2, _ir0.x1, _ir0.y1, _ir1.x2, _ir1.y2, Top, Left, Right, Bottom, SensorBarRadius
|
|
|
|
|
);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("\n");
|
|
|
|
|
Console::Print("ir0.x1:%02x x1h:%02x x2:%02x x2h:%02x | ir0.y1:%02x y1h:%02x y2:%02x y2h:%02x | ir1.x1:%02x x1h:%02x x2:%02x x2h:%02x | ir1.y1:%02x y1h:%02x y2:%02x y2h:%02x\n",
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_ir0.x1, _ir0.x1Hi, _ir0.x2, _ir0.x2Hi,
|
|
|
|
|
_ir0.y1, _ir0.y1Hi, _ir0.y2, _ir0.y2Hi,
|
|
|
|
|
_ir1.x1, _ir1.x1Hi, _ir1.x2, _ir1.x2Hi,
|
|
|
|
|
_ir1.y1, _ir1.y1Hi, _ir1.y2, _ir1.y2Hi
|
|
|
|
|
);*/
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
|
|
|
|
|
//**************************************************************************************
|
|
|
|
|
// Extensions
|
|
|
|
|
//**************************************************************************************
|
|
|
|
|
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ===================================================
|
2009-01-28 16:09:08 +00:00
|
|
|
|
/* Generate the 6 byte extension report for the Nunchuck, encrypted. The bytes are JX JY AX AY AZ BT. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
|
|
|
|
void FillReportExtension(wm_extension& _ext)
|
|
|
|
|
{
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// ------------------------------------
|
|
|
|
|
// Recorded movements
|
|
|
|
|
// --------------
|
|
|
|
|
// Check for a playback command
|
2009-02-04 06:40:05 +00:00
|
|
|
|
if(g_RecordingPlaying[1] < 0) g_RecordingPlaying[1] = RecordingCheckKeys(1);
|
2009-02-03 00:59:26 +00:00
|
|
|
|
|
2009-02-04 06:40:05 +00:00
|
|
|
|
// We should not play back the accelerometer values
|
|
|
|
|
if (!(g_RecordingPlaying[1] >= 0 && RecordingPlay(_ext.ax, _ext.ay, _ext.az, 1)))
|
2009-01-29 08:35:29 +00:00
|
|
|
|
{
|
2009-02-04 06:40:05 +00:00
|
|
|
|
/* These are the default neutral values for the nunchuck accelerometer according to the calibration
|
|
|
|
|
data we have in nunchuck_calibration[] */
|
|
|
|
|
_ext.ax = 0x80;
|
|
|
|
|
_ext.ay = 0x80;
|
|
|
|
|
_ext.az = 0xb3;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
// ---------------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ------------------------------------
|
|
|
|
|
// The default joystick and button values unless we use them
|
|
|
|
|
// --------------
|
2009-02-07 03:16:41 +00:00
|
|
|
|
_ext.jx = g_nu.jx.center;
|
|
|
|
|
_ext.jy = g_nu.jy.center;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_ext.bt = 0x03; // 0x03 means no button pressed, the button is zero active
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ---------------------
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _WIN32
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Set the max values to the current calibration values
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD4)) // x
|
|
|
|
|
_ext.jx = g_nu.jx.min;
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD6))
|
|
|
|
|
_ext.jx = g_nu.jx.max;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD5)) // y
|
|
|
|
|
_ext.jy = g_nu.jy.min;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD8))
|
2009-02-07 03:16:41 +00:00
|
|
|
|
_ext.jy = g_nu.jy.max;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('C'))
|
|
|
|
|
_ext.bt = 0x01;
|
|
|
|
|
if(GetAsyncKeyState('Z'))
|
2009-02-07 03:16:41 +00:00
|
|
|
|
_ext.bt = 0x02;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
if(GetAsyncKeyState('C') && GetAsyncKeyState('Z'))
|
|
|
|
|
_ext.bt = 0x00;
|
|
|
|
|
#else
|
|
|
|
|
// TODO linux port
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
/* Here we encrypt the report */
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Create a temporary storage for the data
|
|
|
|
|
u8 Tmp[sizeof(_ext)];
|
|
|
|
|
// Clear the array by copying zeroes to it
|
|
|
|
|
memset(Tmp, 0, sizeof(_ext));
|
|
|
|
|
// Copy the data to it
|
|
|
|
|
memcpy(Tmp, &_ext, sizeof(_ext));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// Encrypt it
|
2009-02-07 03:16:41 +00:00
|
|
|
|
wiimote_encrypt(&g_ExtKey, Tmp, 0x00, sizeof(_ext));
|
|
|
|
|
// Write it back to the struct
|
|
|
|
|
memcpy(&_ext, Tmp, sizeof(_ext));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-28 16:09:08 +00:00
|
|
|
|
// =======================
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
|
/* Generate the 6 byte extension report for the Classic Controller, encrypted.
|
|
|
|
|
The bytes are ... */
|
|
|
|
|
// ----------------
|
|
|
|
|
void FillReportClassicExtension(wm_classic_extension& _ext)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* These are the default neutral values for the analog triggers and sticks */
|
|
|
|
|
u8 Rx = 0x80, Ry = 0x80, Lx = 0x80, Ly = 0x80, lT = 0x80, rT = 0x80;
|
|
|
|
|
|
|
|
|
|
_ext.b1.padding = 0x01; // 0x01 means not pressed
|
|
|
|
|
_ext.b1.bRT = 0x01;
|
|
|
|
|
_ext.b1.bP = 0x01;
|
|
|
|
|
_ext.b1.bH = 0x01;
|
|
|
|
|
_ext.b1.bM = 0x01;
|
|
|
|
|
_ext.b1.bLT = 0x01;
|
|
|
|
|
_ext.b1.bdD = 0x01;
|
|
|
|
|
_ext.b1.bdR = 0x01;
|
|
|
|
|
|
|
|
|
|
_ext.b2.bdU = 0x01;
|
|
|
|
|
_ext.b2.bdL = 0x01;
|
|
|
|
|
_ext.b2.bZR = 0x01;
|
|
|
|
|
_ext.b2.bX = 0x01;
|
|
|
|
|
_ext.b2.bA = 0x01;
|
|
|
|
|
_ext.b2.bY = 0x01;
|
|
|
|
|
_ext.b2.bB = 0x01;
|
|
|
|
|
_ext.b2.bZL = 0x01;
|
|
|
|
|
|
2009-02-01 15:40:13 +00:00
|
|
|
|
|
|
|
|
|
// --------------------------------------
|
|
|
|
|
// Check that Dolphin is in focus
|
|
|
|
|
if (!IsFocus()) return;
|
|
|
|
|
// --------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// --------------------------------------
|
|
|
|
|
/* Left and right analog sticks
|
|
|
|
|
|
|
|
|
|
u8 Lx : 6; // byte 0
|
|
|
|
|
u8 Rx : 2;
|
|
|
|
|
u8 Ly : 6; // byte 1
|
|
|
|
|
u8 Rx2 : 2;
|
|
|
|
|
u8 Ry : 5; // byte 2
|
|
|
|
|
u8 lT : 2;
|
|
|
|
|
u8 Rx3 : 1;
|
|
|
|
|
u8 rT : 5; // byte 3
|
|
|
|
|
u8 lT2 : 3;
|
|
|
|
|
*/
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
/* We use a 200 range (28 to 228) for the left analog stick and a 176 range
|
|
|
|
|
(40 to 216) for the right analog stick to match our calibration values
|
|
|
|
|
in classic_calibration */
|
|
|
|
|
if(GetAsyncKeyState('J')) // left analog left
|
|
|
|
|
Lx = 0x1c;
|
|
|
|
|
if(GetAsyncKeyState('I')) // up
|
|
|
|
|
Ly = 0xe4;
|
|
|
|
|
if(GetAsyncKeyState('L')) // right
|
|
|
|
|
Lx = 0xe4;
|
|
|
|
|
if(GetAsyncKeyState('K')) // down
|
|
|
|
|
Ly = 0x1c;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('D')) // right analog left
|
|
|
|
|
Rx = 0x28;
|
|
|
|
|
if(GetAsyncKeyState('R')) // up
|
|
|
|
|
Ry = 0xd8;
|
|
|
|
|
if(GetAsyncKeyState('G')) // right
|
|
|
|
|
Rx = 0xd8;
|
|
|
|
|
if(GetAsyncKeyState('F')) // down
|
|
|
|
|
Ry = 0x28;
|
|
|
|
|
|
2008-12-26 10:53:32 +00:00
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_ext.Lx = (Lx >> 2);
|
|
|
|
|
_ext.Ly = (Ly >> 2);
|
|
|
|
|
_ext.Rx = (Rx >> 3); // this may be wrong
|
|
|
|
|
_ext.Rx2 = (Rx >> 5);
|
|
|
|
|
_ext.Rx3 = (Rx >> 7);
|
|
|
|
|
_ext.Ry = (Ry >> 2);
|
|
|
|
|
|
|
|
|
|
_ext.lT = (Ry >> 2);
|
|
|
|
|
_ext.lT2 = (Ry >> 3);
|
|
|
|
|
_ext.rT = (Ry >> 4);
|
|
|
|
|
// --------------
|
2008-12-26 10:53:32 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------
|
|
|
|
|
/* D-Pad
|
|
|
|
|
|
|
|
|
|
u8 b1;
|
|
|
|
|
0:
|
|
|
|
|
6: bdD
|
|
|
|
|
7: bdR
|
|
|
|
|
|
|
|
|
|
u8 b2;
|
|
|
|
|
0: bdU
|
|
|
|
|
1: bdL
|
|
|
|
|
*/
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD4)) // left
|
|
|
|
|
_ext.b2.bdL = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD8)) // up
|
|
|
|
|
_ext.b2.bdU = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD6)) // right
|
|
|
|
|
_ext.b1.bdR = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState(VK_NUMPAD5)) // down
|
|
|
|
|
_ext.b1.bdD = 0x00;
|
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------
|
|
|
|
|
/* Buttons
|
|
|
|
|
u8 b1;
|
|
|
|
|
0:
|
|
|
|
|
6: -
|
|
|
|
|
7: -
|
|
|
|
|
|
|
|
|
|
u8 b2;
|
|
|
|
|
0: -
|
|
|
|
|
1: -
|
|
|
|
|
2: bZr
|
|
|
|
|
3: bX
|
|
|
|
|
4: bA
|
|
|
|
|
5: bY
|
|
|
|
|
6: bB
|
|
|
|
|
7: bZl
|
|
|
|
|
*/
|
|
|
|
|
if(GetAsyncKeyState('Z'))
|
|
|
|
|
_ext.b2.bA = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('C'))
|
|
|
|
|
_ext.b2.bB = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('Y'))
|
|
|
|
|
_ext.b2.bY = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('X'))
|
|
|
|
|
_ext.b2.bX = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('O')) // O instead of P
|
|
|
|
|
_ext.b1.bP = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('N')) // N instead of M
|
|
|
|
|
_ext.b1.bM = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('U')) // Home button
|
|
|
|
|
_ext.b1.bH = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('7')) // digital left trigger
|
|
|
|
|
_ext.b1.bLT = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('8'))
|
|
|
|
|
_ext.b2.bZL = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('9'))
|
|
|
|
|
_ext.b2.bZR = 0x00;
|
|
|
|
|
|
|
|
|
|
if(GetAsyncKeyState('0')) // digital right trigger
|
|
|
|
|
_ext.b1.bRT = 0x00;
|
|
|
|
|
|
|
|
|
|
// All buttons pressed
|
|
|
|
|
//if(GetAsyncKeyState('C') && GetAsyncKeyState('Z'))
|
|
|
|
|
// { _ext.b2.bA = 0x01; _ext.b2.bB = 0x01; }
|
|
|
|
|
// --------------
|
|
|
|
|
#else
|
|
|
|
|
// TODO linux port
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
/* Here we encrypt the report */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Create a temporary storage for the data
|
|
|
|
|
u8 Tmp[sizeof(_ext)];
|
|
|
|
|
// Clear the array by copying zeroes to it
|
|
|
|
|
memset(Tmp, 0, sizeof(_ext));
|
|
|
|
|
// Copy the data to it
|
|
|
|
|
memcpy(Tmp, &_ext, sizeof(_ext));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// Encrypt it
|
2009-02-07 03:16:41 +00:00
|
|
|
|
wiimote_encrypt(&g_ExtKey, Tmp, 0x00, sizeof(_ext));
|
|
|
|
|
// Write it back to the struct
|
|
|
|
|
memcpy(&_ext, Tmp, sizeof(_ext));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-28 16:09:08 +00:00
|
|
|
|
// =======================
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace
|