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-07-05 05:59:03 +00:00
|
|
|
/* Data reports guide. The different structures location in the Input
|
|
|
|
reports. The ? in the IR coordinates is the High coordinates that are four
|
|
|
|
in one byte.
|
2009-01-07 02:59:19 +00:00
|
|
|
|
2009-07-05 05:59:03 +00:00
|
|
|
0x37: For the data reportingmode 0x37 there are five unused IR bytes in the
|
|
|
|
end (represented) by "..." below, it seems like they can be set to either
|
|
|
|
0xff or 0x00 without affecting the IR emulation. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-07-05 05:59:03 +00:00
|
|
|
/* 0x33 [c.left etc] [c.a etc] acc.x y z ir0.x y ? ir1.x y ? ir2.x y ? ir3.x y
|
|
|
|
?
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-07-05 05:59:03 +00:00
|
|
|
0x37 [c.left etc] [c.a etc] acc.x y z ir0.x1 y1 ? x2 y2 ir1.x1 y1 ? x2 y2
|
|
|
|
... ext.jx jy ax ay az bt
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
The Data Report's path from here is
|
|
|
|
WII_IPC_HLE_WiiMote.cpp:
|
|
|
|
Callback_WiimoteInput()
|
|
|
|
CWII_IPC_HLE_WiiMote::SendL2capData()
|
|
|
|
WII_IPC_HLE_Device_usb.cpp:
|
2009-11-24 05:03:47 +00:00
|
|
|
CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLPacket()
|
2008-12-08 05:25:12 +00:00
|
|
|
at that point the message is queued and will be sent by the next
|
2009-07-05 05:59:03 +00:00
|
|
|
CWII_IPC_HLE_Device_usb_oh1_57e_305::Update()
|
|
|
|
*/
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "pluginspecs_wiimote.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
#include "Common.h" // Common
|
|
|
|
#include "StringUtil.h" // for ArrayToString
|
|
|
|
|
|
|
|
#include "wiimote_hid.h" // Local
|
2009-02-01 13:01:50 +00:00
|
|
|
#include "main.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "EmuMain.h"
|
|
|
|
#include "EmuSubroutines.h"
|
|
|
|
#include "EmuDefinitions.h"
|
|
|
|
#include "Encryption.h" // for extension encryption
|
|
|
|
#include "Config.h" // for g_Config
|
|
|
|
|
|
|
|
|
2009-07-05 05:59:03 +00:00
|
|
|
extern SWiimoteInitialize g_WiimoteInitialize;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
namespace WiiMoteEmu
|
|
|
|
{
|
|
|
|
|
|
|
|
// Subroutines
|
|
|
|
|
2009-07-05 05:59:03 +00:00
|
|
|
// Update the data reporting mode
|
|
|
|
|
2009-11-24 05:03:47 +00:00
|
|
|
void WmReportMode(u16 _channelID, wm_report_mode* dr)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-11-24 05:03:47 +00:00
|
|
|
INFO_LOG(WIIMOTE, "Set data report mode");
|
2009-09-15 02:12:55 +00:00
|
|
|
DEBUG_LOG(WIIMOTE, " Rumble: %x", dr->rumble);
|
|
|
|
DEBUG_LOG(WIIMOTE, " Continuous: %x", dr->continuous);
|
2010-01-05 17:39:06 +00:00
|
|
|
DEBUG_LOG(WIIMOTE, " All The Time: %x", dr->all_the_time);
|
2009-09-15 02:12:55 +00:00
|
|
|
DEBUG_LOG(WIIMOTE, " Mode: 0x%02x", dr->mode);
|
2009-11-24 05:03:47 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
g_ReportingAuto[g_ID] = dr->all_the_time;
|
|
|
|
g_ReportingMode[g_ID] = dr->mode;
|
|
|
|
g_ReportingChannel[g_ID] = _channelID;
|
2009-11-24 05:03:47 +00:00
|
|
|
|
2010-01-05 17:39:06 +00:00
|
|
|
if (dr->all_the_time == 0)
|
|
|
|
{
|
|
|
|
PanicAlert("Wiimote: Reporting Always is set to OFF!");
|
|
|
|
}
|
|
|
|
|
2009-11-24 05:03:47 +00:00
|
|
|
// Validation check
|
|
|
|
switch(dr->mode)
|
2009-01-07 02:59:19 +00:00
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
case WM_REPORT_CORE:
|
|
|
|
case WM_REPORT_CORE_ACCEL:
|
|
|
|
case WM_REPORT_CORE_ACCEL_IR12:
|
|
|
|
case WM_REPORT_CORE_ACCEL_EXT16:
|
|
|
|
case WM_REPORT_CORE_ACCEL_IR10_EXT6:
|
|
|
|
break;
|
|
|
|
default:
|
2009-02-01 13:01:50 +00:00
|
|
|
PanicAlert("Wiimote: Unsupported reporting mode 0x%x", dr->mode);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Case 0x30: Core Buttons */
|
|
|
|
void SendReportCore(u16 _channelID)
|
|
|
|
{
|
|
|
|
u8 DataFrame[1024];
|
2009-11-24 05:03:47 +00:00
|
|
|
u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
wm_report_core* pReport = (wm_report_core*)(DataFrame + Offset);
|
|
|
|
Offset += sizeof(wm_report_core);
|
|
|
|
memset(pReport, 0, sizeof(wm_report_core));
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportInfo(pReport->c);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-11-24 05:03:47 +00:00
|
|
|
INFO_LOG(WIIMOTE, " SendReportCore(0x30)");
|
|
|
|
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
|
|
|
|
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
|
2009-02-01 13:01:50 +00:00
|
|
|
// Debugging
|
2009-11-24 05:03:47 +00:00
|
|
|
//ReadDebugging(true, DataFrame, Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 0x31: Core Buttons and Accelerometer */
|
|
|
|
void SendReportCoreAccel(u16 _channelID)
|
|
|
|
{
|
|
|
|
u8 DataFrame[1024];
|
2009-11-24 05:03:47 +00:00
|
|
|
u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
wm_report_core_accel* pReport = (wm_report_core_accel*)(DataFrame + Offset);
|
|
|
|
Offset += sizeof(wm_report_core_accel);
|
|
|
|
memset(pReport, 0, sizeof(wm_report_core_accel));
|
|
|
|
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportInfo(pReport->c);
|
|
|
|
FillReportAcc(pReport->a);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 02:12:55 +00:00
|
|
|
INFO_LOG(WIIMOTE, " SendReportCoreAccel (0x31)");
|
2009-11-24 05:03:47 +00:00
|
|
|
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
|
|
|
|
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
// Debugging
|
2009-11-24 05:03:47 +00:00
|
|
|
//ReadDebugging(true, DataFrame, Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Case 0x33: Core Buttons and Accelerometer with 12 IR bytes */
|
|
|
|
void SendReportCoreAccelIr12(u16 _channelID) {
|
|
|
|
u8 DataFrame[1024];
|
2009-11-24 05:03:47 +00:00
|
|
|
u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL_IR12);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
wm_report_core_accel_ir12* pReport = (wm_report_core_accel_ir12*)(DataFrame + Offset);
|
|
|
|
Offset += sizeof(wm_report_core_accel_ir12);
|
|
|
|
memset(pReport, 0, sizeof(wm_report_core_accel_ir12));
|
|
|
|
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportInfo(pReport->c);
|
|
|
|
FillReportAcc(pReport->a);
|
2009-02-03 00:59:26 +00:00
|
|
|
// We settle with emulating two objects, not all four. We leave object 2 and 3 with 0xff.
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportIR(pReport->ir[0], pReport->ir[1]);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2009-02-03 00:59:26 +00:00
|
|
|
memset(&pReport->ir[2], 0xff, sizeof(wm_ir_extended));
|
|
|
|
memset(&pReport->ir[3], 0xff, sizeof(wm_ir_extended));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-11-24 05:03:47 +00:00
|
|
|
INFO_LOG(WIIMOTE, " SendReportCoreAccelIr12(0x33)");
|
|
|
|
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
|
|
|
|
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
// Debugging
|
2009-11-24 05:03:47 +00:00
|
|
|
//ReadDebugging(true, DataFrame, Offset);
|
2009-02-01 13:01:50 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Case 0x35: Core Buttons and Accelerometer with 16 Extension Bytes */
|
|
|
|
void SendReportCoreAccelExt16(u16 _channelID)
|
|
|
|
{
|
|
|
|
u8 DataFrame[1024];
|
2009-11-24 05:03:47 +00:00
|
|
|
u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL_EXT16);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
wm_report_core_accel_ext16* pReport = (wm_report_core_accel_ext16*)(DataFrame + Offset);
|
|
|
|
Offset += sizeof(wm_report_core_accel_ext16);
|
|
|
|
memset(pReport, 0, sizeof(wm_report_core_accel_ext16));
|
|
|
|
|
|
|
|
// Make a classic extension struct
|
|
|
|
wm_classic_extension _ext;
|
|
|
|
memset(&_ext, 0, sizeof(wm_classic_extension));
|
|
|
|
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportInfo(pReport->c);
|
|
|
|
FillReportAcc(pReport->a);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
if(WiiMapping[g_ID].iExtensionConnected == EXT_NUNCHUCK)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportExtension(pReport->ext);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-12-27 19:31:02 +00:00
|
|
|
else if(WiiMapping[g_ID].iExtensionConnected == EXT_CLASSIC_CONTROLLER)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportClassicExtension(_ext);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2009-11-24 05:03:47 +00:00
|
|
|
// Copy _ext to pReport->ext
|
2008-12-08 05:25:12 +00:00
|
|
|
memcpy(&pReport->ext, &_ext, sizeof(_ext));
|
|
|
|
}
|
|
|
|
|
2009-09-15 02:12:55 +00:00
|
|
|
INFO_LOG(WIIMOTE, " SendReportCoreAccelExt16 (0x35)");
|
2009-11-24 05:03:47 +00:00
|
|
|
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
|
|
|
|
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
// Debugging
|
2009-11-24 05:03:47 +00:00
|
|
|
//ReadDebugging(true, DataFrame, Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Case 0x37: Core Buttons and Accelerometer with 10 IR bytes and 6 Extension Bytes */
|
|
|
|
void SendReportCoreAccelIr10Ext(u16 _channelID)
|
|
|
|
{
|
|
|
|
u8 DataFrame[1024];
|
2009-11-24 05:03:47 +00:00
|
|
|
u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL_IR10_EXT6);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
wm_report_core_accel_ir10_ext6* pReport = (wm_report_core_accel_ir10_ext6*)(DataFrame + Offset);
|
|
|
|
Offset += sizeof(wm_report_core_accel_ir10_ext6);
|
|
|
|
memset(pReport, 0, sizeof(wm_report_core_accel_ir10_ext6));
|
|
|
|
|
|
|
|
// Make a classic extension struct
|
|
|
|
wm_classic_extension _ext;
|
2009-07-09 03:58:53 +00:00
|
|
|
wm_GH3_extension _GH3_ext;
|
2008-12-08 05:25:12 +00:00
|
|
|
memset(&_ext, 0, sizeof(wm_classic_extension));
|
2009-07-09 03:58:53 +00:00
|
|
|
memset(&_GH3_ext, 0, sizeof(wm_GH3_extension));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportInfo(pReport->c);
|
|
|
|
FillReportAcc(pReport->a);
|
|
|
|
FillReportIRBasic(pReport->ir[0], pReport->ir[1]);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2009-12-27 19:31:02 +00:00
|
|
|
if(WiiMapping[g_ID].iExtensionConnected == EXT_NUNCHUCK)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportExtension(pReport->ext);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-12-27 19:31:02 +00:00
|
|
|
else if(WiiMapping[g_ID].iExtensionConnected == EXT_CLASSIC_CONTROLLER)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-02-17 22:15:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
FillReportClassicExtension(_ext);
|
2009-02-17 22:15:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
// Copy _ext to pReport->ext
|
|
|
|
memcpy(&pReport->ext, &_ext, sizeof(_ext));
|
|
|
|
}
|
2009-12-27 19:31:02 +00:00
|
|
|
else if(WiiMapping[g_ID].iExtensionConnected == EXT_GUITARHERO)
|
2009-07-09 03:58:53 +00:00
|
|
|
{
|
2009-08-01 18:31:25 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-07-09 03:58:53 +00:00
|
|
|
FillReportGuitarHero3Extension(_GH3_ext);
|
2009-08-01 18:31:25 +00:00
|
|
|
#endif
|
2009-07-09 03:58:53 +00:00
|
|
|
memcpy(&pReport->ext, &_GH3_ext, sizeof(_GH3_ext));
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-11-24 05:03:47 +00:00
|
|
|
INFO_LOG(WIIMOTE, " SendReportCoreAccelIr10Ext(0x37)");
|
|
|
|
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
|
|
|
|
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-12-27 19:31:02 +00:00
|
|
|
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
// Debugging
|
2009-11-24 05:03:47 +00:00
|
|
|
//ReadDebugging(true, DataFrame, Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace
|