Emulated Wiimote: Fixed the Classic Controller left and right analog triggers, and the right stick

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2417 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-02-24 18:37:53 +00:00
parent 2d6a977dc5
commit 1f0f0f4295
5 changed files with 93 additions and 43 deletions

View File

@ -364,4 +364,20 @@ void IRData2Distance()
//////////////////////////////// ////////////////////////////////
//******************************************************************************
// Classic Controller functions
//******************************************************************************
std::string CCData2Values(u8 *Data)
{
return StringFromFormat(
"Tl:%03i Tr:%03i Lx:%03i Ly:%03i Rx:%03i Ry:%03i",
(((Data[2] & 0x60) >> 2) | ((Data[3] & 0xe0) >> 5)),
(Data[3] & 0x1f),
(Data[0] & 0x3f),
(Data[1] & 0x3f),
((Data[0] & 0xc0) >> 3) | ((Data[1] & 0xc0) >> 5) | ((Data[2] & 0x80) >> 7),
(Data[2] & 0x1f));
}
} // WiiMoteEmu } // WiiMoteEmu

View File

@ -68,6 +68,9 @@ void IRData2DotsBasic(u8 *Data);
void ReorderIRDots(); void ReorderIRDots();
void IRData2Distance(); void IRData2Distance();
// Classic Controller data
std::string CCData2Values(u8 *Data);
}; // WiiMoteEmu }; // WiiMoteEmu

View File

@ -929,9 +929,6 @@ void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1)
_ir0.x2 = x2 & 0xff; _ir0.x2Hi = (x2 >> 8); _ir0.x2 = x2 & 0xff; _ir0.x2Hi = (x2 >> 8);
_ir0.y2 = y2 & 0xff; _ir0.y2Hi = (y2 >> 8); _ir0.y2 = y2 & 0xff; _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;
// ------------------------------------ // ------------------------------------
// Debugging for calibration // Debugging for calibration
@ -1259,14 +1256,9 @@ void FillReportClassicExtension(wm_classic_extension& _ext)
if (_Tl == 0xff) _ext.b1.bLT = 0x00; if (_Tl == 0xff) _ext.b1.bLT = 0x00;
if (_Tr == 0xff) _ext.b1.bRT = 0x00; if (_Tr == 0xff) _ext.b1.bRT = 0x00;
// The reported data is supposed to be divided by 8 so that we return 0x1f at most, I think. But // These can be copied directly, the bitshift further down fix this value to
// I'm not sure about the bit shifts further down. lT = _Tl;
lT = _Tl / 8; rT = _Tr;
rT = _Tr / 8;
// Boundaries
if (lT > 0x1f) lT = 0x1f;
if (rT > 0x1f) rT = 0x1f;
} }
@ -1344,15 +1336,21 @@ void FillReportClassicExtension(wm_classic_extension& _ext)
// -------------------------------------- // --------------------------------------
// Convert data for reporting // Convert data for reporting
// --------------
_ext.Lx = (Lx >> 2); _ext.Lx = (Lx >> 2);
_ext.Ly = (Ly >> 2); _ext.Ly = (Ly >> 2);
_ext.Rx = (Rx >> 3); // This may be wrong // 5 bit to 1 bit
_ext.Rx2 = (Rx >> 5); _ext.Rx = (Rx >> 3) & 0x01;
_ext.Rx3 = (Rx >> 7); // 5 bit to the next 2 bit
_ext.Ry = (Ry >> 2); _ext.Rx2 = ((Rx >> 3) >> 1) & 0x03;
// 5 bit to the next 2 bit
_ext.Rx3 = ((Rx >> 3) >> 3) & 0x03;
_ext.Ry = (Ry >> 3);
_ext.lT = (lT >> 6); // This may be wrong // 5 bit to 3 bit
_ext.lT2 = (lT >> 5); _ext.lT = (lT >> 3) & 0x07;
// 5 bit to the highest two bits
_ext.lT2 = (lT >> 3) >> 3;
_ext.rT = (rT >> 3); _ext.rT = (rT >> 3);
// -------------- // --------------

View File

@ -617,6 +617,8 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
if(WiiMoteEmu::g_Encryption) if(WiiMoteEmu::g_Encryption)
wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[0x07], 0x00, (data[4] >> 0x04) + 1); wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[0x07], 0x00, (data[4] >> 0x04) + 1);
if (g_Config.bNunchuckConnected)
{
Console::Print("\nGame got the Nunchuck calibration:\n"); Console::Print("\nGame got the Nunchuck calibration:\n");
Console::Print("Cal_zero.x: %i\n", data[7 + 0]); Console::Print("Cal_zero.x: %i\n", data[7 + 0]);
Console::Print("Cal_zero.y: %i\n", data[7 + 1]); Console::Print("Cal_zero.y: %i\n", data[7 + 1]);
@ -630,8 +632,27 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
Console::Print("Js.Max.y: %i\n", data[7 + 11]); Console::Print("Js.Max.y: %i\n", data[7 + 11]);
Console::Print("Js.Min.y: %i\n", data[7 + 12]); Console::Print("Js.Min.y: %i\n", data[7 + 12]);
Console::Print("JS.Center.y: %i\n\n", data[7 + 13]); Console::Print("JS.Center.y: %i\n\n", data[7 + 13]);
}
else // g_Config.bClassicControllerConnected
{
Console::Print("\nGame got the Classic Controller calibration:\n");
Console::Print("Lx.Max: %i\n", data[7 + 0]);
Console::Print("Lx.Min: %i\n", data[7 + 1]);
Console::Print("Lx.Center: %i\n", data[7 + 2]);
Console::Print("Ly.Max: %i\n", data[7 + 3]);
Console::Print("Ly.Min: %i\n", data[7 + 4]);
Console::Print("Ly.Center: %i\n", data[7 + 5]);
Console::Print("Rx.Max.x: %i\n", data[7 + 6]);
Console::Print("Rx.Min.x: %i\n", data[7 + 7]);
Console::Print("Rx.Center.x: %i\n", data[7 + 8]);
Console::Print("Ry.Max.y: %i\n", data[7 + 9]);
Console::Print("Ry.Min: %i\n", data[7 + 10]);
Console::Print("Ry.Center: %i\n\n", data[7 + 11]);
Console::Print("Lt.Neutral: %i\n", data[7 + 12]);
Console::Print("Rt.Neutral %i\n\n", data[7 + 13]);
}
// Save the values // Save the values if they come from the real Wiimote
if (!Emu) if (!Emu)
{ {
// Save the values from the Nunchuck // Save the values from the Nunchuck
@ -716,11 +737,13 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
// Decrypt extension data // Decrypt extension data
if(WiiMoteEmu::g_ReportingMode == 0x37) if(WiiMoteEmu::g_ReportingMode == 0x37)
wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[17], 0x00, 0x06); wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[17], 0x00, 0x06);
if(WiiMoteEmu::g_ReportingMode == 0x35)
wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[7], 0x00, 0x06);
// Produce string // Produce string
//std::string TmpData = ArrayToString(data, size + 2, 0, 30); //std::string TmpData = ArrayToString(data, size + 2, 0, 30);
//LOGV(WII_IPC_WIIMOTE, 3, " Data: %s", Temp.c_str()); //LOGV(WII_IPC_WIIMOTE, 3, " Data: %s", Temp.c_str());
std::string TmpCore = "", TmpAccel = "", TmpIR = "", TmpExt = ""; std::string TmpCore = "", TmpAccel = "", TmpIR = "", TmpExt = "", CCData = "";
TmpCore = StringFromFormat( TmpCore = StringFromFormat(
"%02x %02x %02x %02x", "%02x %02x %02x %02x",
data[0], data[1], data[2], data[3]); // Header and core buttons data[0], data[1], data[2], data[3]); // Header and core buttons
@ -744,6 +767,8 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
data[7], data[8], // Nunchuck stick data[7], data[8], // Nunchuck stick
data[9], data[10], data[11], // Nunchuck Accelerometer data[9], data[10], data[11], // Nunchuck Accelerometer
data[12]); // Nunchuck buttons data[12]); // Nunchuck buttons
CCData = WiiMoteEmu::CCData2Values(&data[7]);
} }
if (data[1] == 0x37) // WM_REPORT_CORE_ACCEL_IR10_EXT6 if (data[1] == 0x37) // WM_REPORT_CORE_ACCEL_IR10_EXT6
{ {
@ -757,6 +782,7 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
data[17], data[18], // Nunchuck stick data[17], data[18], // Nunchuck stick
data[19], data[20], data[21], // Nunchuck Accelerometer data[19], data[20], data[21], // Nunchuck Accelerometer
data[22]); // Nunchuck buttons data[22]); // Nunchuck buttons
CCData = WiiMoteEmu::CCData2Values(&data[17]);
} }
@ -813,11 +839,18 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
IRData += StringFromFormat(" | Distance:%i", WiiMoteEmu::g_Wm.IR.Distance); IRData += StringFromFormat(" | Distance:%i", WiiMoteEmu::g_Wm.IR.Distance);
// ------------------------- // -------------------------
//Console::Print("Read[%s]: 0x%02x | %s | %s | %s\n", (Emu ? "Emu" : "Real"), data[1], RollPitch.c_str(), GForce.c_str(), IRData.c_str()); // Formatted data only // Classic Controller data
//Console::Print("Read[%s]: %s | %s\n", (Emu ? "Emu" : "Real"), TmpData.c_str(), IRData.c_str()); // IR data Console::Print("Read[%s]: %s | %s | %s | %s | %s\n", (Emu ? "Emu" : "Real"),
Console::Print("Read[%s]: %s | %s | %s | %s | %s | %s\n", (Emu ? "Emu" : "Real"), TmpCore.c_str(), TmpAccel.c_str(), TmpIR.c_str(), TmpExt.c_str(), CCData.c_str());
TmpCore.c_str(), TmpAccel.c_str(), TmpIR.c_str(), TmpExt.c_str(), RollPitch.c_str(), GForce.c_str()); // Accelerometer // Formatted data only
//Console::Print(" (%s): %s\n", Tm(true).c_str(), Temp.c_str()); // Timestamp //Console::Print("Read[%s]: 0x%02x | %s | %s | %s\n", (Emu ? "Emu" : "Real"), data[1], RollPitch.c_str(), GForce.c_str(), IRData.c_str());
// IR data
//Console::Print("Read[%s]: %s | %s\n", (Emu ? "Emu" : "Real"), TmpData.c_str(), IRData.c_str());
// Accelerometer data
//Console::Print("Read[%s]: %s | %s | %s | %s | %s | %s | %s\n", (Emu ? "Emu" : "Real"),
// TmpCore.c_str(), TmpAccel.c_str(), TmpIR.c_str(), TmpExt.c_str(), RollPitch.c_str(), GForce.c_str(), CCData.c_str());
// Timestamp
//Console::Print(" (%s): %s\n", Tm(true).c_str(), Temp.c_str());
} }
if(g_DebugAccelerometer) if(g_DebugAccelerometer)
@ -1058,8 +1091,8 @@ void DoInitialize()
to check if there is a real wiimote connected. We will initiate wiiuse.dll, but 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. 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 Then g_RealWiiMotePresent will also be false. This function call will be done
instantly if there is no real Wiimote connected. I'm not sure how long time instantly whether there is a real Wiimote connected or not. It takes no time for
it takes if a Wiimote is connected. */ Wiiuse to check for connected Wiimotes. */
#if HAVE_WIIUSE #if HAVE_WIIUSE
if (g_Config.bConnectRealWiimote) WiiMoteReal::Initialize(); if (g_Config.bConnectRealWiimote) WiiMoteReal::Initialize();
#endif #endif

View File

@ -214,14 +214,14 @@ struct wm_cc_5
struct wm_classic_extension struct wm_classic_extension
{ {
u8 Lx : 6; // byte 0 u8 Lx : 6; // byte 0
u8 Rx : 2; u8 Rx3 : 2;
u8 Ly : 6; // byte 1 u8 Ly : 6; // byte 1
u8 Rx2 : 2; u8 Rx2 : 2;
u8 Ry : 5; // byte 2 u8 Ry : 5; // byte 2
u8 lT : 2; u8 lT2 : 2;
u8 Rx3 : 1; u8 Rx : 1;
u8 rT : 5; // byte 3 u8 rT : 5; // byte 3
u8 lT2 : 3; u8 lT : 3;
wm_cc_4 b1; // byte 4 wm_cc_4 b1; // byte 4
wm_cc_5 b2; // byte 5 wm_cc_5 b2; // byte 5
}; };