Now Dolphin officially supports multiple REAL WiiMotes!

Only downside: You can't change between Real and Emulated WiiMotes while the game is running anymore... This is due to the way the Real WiiMotes are assigned to the slots...

I've tested it with 2 real WiiMotes, but I can't see why it wouldn't work with 4!
Also, you can assign Real or Emulated WiiMotes to any one of the four slots that it will be respected!

Happy New Year everybody!

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4765 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
fgfemperor 2010-01-01 00:38:24 +00:00
parent 7ad2f5087a
commit 7359b3b2a6
7 changed files with 190 additions and 91 deletions

View File

@ -1402,7 +1402,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandDisconnect(u8* _Input)
PanicAlert("Wiimote (%i) has been disconnected by system due to idle time out.\n" PanicAlert("Wiimote (%i) has been disconnected by system due to idle time out.\n"
"Don't panic, this is quite a normal behavior for power saving.\n\n" "Don't panic, this is quite a normal behavior for power saving.\n\n"
"To reconnect, Pasue game and Click \"Menu -> Tools -> Connect Wiimote\"", (pDiscon->con_handle & 0xFF) + 1); "To reconnect, Click \"Menu -> Tools -> Connect Wiimote\"", (pDiscon->con_handle & 0xFF) + 1);
CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pDiscon->con_handle); CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pDiscon->con_handle);
if (pWiimote) if (pWiimote)

View File

@ -271,6 +271,8 @@ void Config::Load()
iniFile.Get("Real", "AccNunNeutralY", &iAccNunNeutralY, 0); iniFile.Get("Real", "AccNunNeutralY", &iAccNunNeutralY, 0);
iniFile.Get("Real", "AccNunNeutralZ", &iAccNunNeutralZ, 0); iniFile.Get("Real", "AccNunNeutralZ", &iAccNunNeutralZ, 0);
g_Config.bNumberEmuWiimotes = g_Config.bNumberRealWiimotes = 0;
for (int i = 0; i < MAX_WIIMOTES; i++) for (int i = 0; i < MAX_WIIMOTES; i++)
{ {
// Slot specific settings // Slot specific settings
@ -279,6 +281,11 @@ void Config::Load()
// General // General
iniFile.Get(SectionName, "Source", &WiiMoteEmu::WiiMapping[i].Source, (i) ? 0 : 1); iniFile.Get(SectionName, "Source", &WiiMoteEmu::WiiMapping[i].Source, (i) ? 0 : 1);
if(WiiMoteEmu::WiiMapping[i].Source == 1)
g_Config.bNumberEmuWiimotes++;
else if((WiiMoteEmu::WiiMapping[i].Source == 2) || (WiiMoteEmu::WiiMapping[i].Source == -1))
g_Config.bNumberRealWiimotes++;
iniFile.Get(SectionName, "Sideways", &WiiMoteEmu::WiiMapping[i].bSideways, false); iniFile.Get(SectionName, "Sideways", &WiiMoteEmu::WiiMapping[i].bSideways, false);
iniFile.Get(SectionName, "Upright", &WiiMoteEmu::WiiMapping[i].bUpright, false); iniFile.Get(SectionName, "Upright", &WiiMoteEmu::WiiMapping[i].bUpright, false);
iniFile.Get(SectionName, "ExtensionConnected", &WiiMoteEmu::WiiMapping[i].iExtensionConnected, WiiMoteEmu::EXT_NONE); iniFile.Get(SectionName, "ExtensionConnected", &WiiMoteEmu::WiiMapping[i].iExtensionConnected, WiiMoteEmu::EXT_NONE);

View File

@ -32,7 +32,8 @@ struct Config
int CurrentPage; int CurrentPage;
// Real Wiimote // Real Wiimote
bool bConnectRealWiimote, bUseRealWiimote, bUpdateRealWiimote; bool bConnectRealWiimote, bUpdateRealWiimote;
int bFoundRealWiimotes, bNumberRealWiimotes, bNumberEmuWiimotes;
int iIRLeft, iIRTop, iIRWidth, iIRHeight; int iIRLeft, iIRTop, iIRWidth, iIRHeight;
int iAccNeutralX, iAccNeutralY, iAccNeutralZ; int iAccNeutralX, iAccNeutralY, iAccNeutralZ;
int iAccNunNeutralX, iAccNunNeutralY, iAccNunNeutralZ; int iAccNunNeutralX, iAccNunNeutralY, iAccNunNeutralZ;

View File

@ -73,6 +73,10 @@ void WiimoteBasicConfigDialog::OnClose(wxCloseEvent& event)
UpdateGUI(); UpdateGUI();
g_FrameOpen = false; g_FrameOpen = false;
EndModal(wxID_CLOSE); EndModal(wxID_CLOSE);
// Shutdown Real WiiMotes so everything is set properly before the game starts
if (g_RealWiiMoteInitialized)
WiiMoteReal::Shutdown();
} }
/* Timeout the shutdown. In Windows at least the g_pReadThread execution will hang at any attempt to /* Timeout the shutdown. In Windows at least the g_pReadThread execution will hang at any attempt to
@ -80,7 +84,7 @@ void WiimoteBasicConfigDialog::OnClose(wxCloseEvent& event)
We must therefore shut down the thread from here and wait for that before we can call ShutDown(). */ We must therefore shut down the thread from here and wait for that before we can call ShutDown(). */
void WiimoteBasicConfigDialog::ShutDown(wxTimerEvent& WXUNUSED(event)) void WiimoteBasicConfigDialog::ShutDown(wxTimerEvent& WXUNUSED(event))
{ {
if(!WiiMoteReal::g_ThreadGoing) if (!WiiMoteReal::g_ThreadGoing)
{ {
m_ShutDownTimer->Stop(); m_ShutDownTimer->Stop();
Close(); Close();
@ -271,6 +275,10 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
#endif #endif
ControlsCreated = true; ControlsCreated = true;
// Initialize the Real WiiMotes here, so we get a count of how many were found and set everything properly
if (!g_RealWiiMoteInitialized && g_Config.bConnectRealWiimote)
WiiMoteReal::Initialize();
} }
// Execute a delayed function // Execute a delayed function
@ -323,7 +331,7 @@ void WiimoteBasicConfigDialog::DoUseReal()
DEBUG_LOG(WIIMOTE, "DoUseReal() Connect extension: %i", !UsingExtension); DEBUG_LOG(WIIMOTE, "DoUseReal() Connect extension: %i", !UsingExtension);
DoExtensionConnectedDisconnected(UsingExtension ? 1 : 0); DoExtensionConnectedDisconnected(UsingExtension ? 1 : 0);
if(g_EmulatorRunning) if (g_EmulatorRunning)
{ {
// Disable the checkbox for a moment // Disable the checkbox for a moment
SetCursor(wxCursor(wxCURSOR_WAIT)); SetCursor(wxCursor(wxCURSOR_WAIT));
@ -342,14 +350,14 @@ void WiimoteBasicConfigDialog::DoUseReal()
void WiimoteBasicConfigDialog::DoExtensionConnectedDisconnected(int Extension) void WiimoteBasicConfigDialog::DoExtensionConnectedDisconnected(int Extension)
{ {
// There is no need for this if no game is running // There is no need for this if no game is running
if(!g_EmulatorRunning || WiiMoteEmu::WiiMapping[m_Page].Source <= 0) if (!g_EmulatorRunning || WiiMoteEmu::WiiMapping[m_Page].Source <= 0)
return; return;
u8 DataFrame[8] = {0}; // make a blank report for it u8 DataFrame[8] = {0}; // make a blank report for it
wm_request_status *rs = (wm_request_status*)DataFrame; wm_request_status *rs = (wm_request_status*)DataFrame;
// Check if a game is running, in that case change the status // Check if a game is running, in that case change the status
if(WiiMoteEmu::g_ReportingChannel[m_Page] > 0) if (WiiMoteEmu::g_ReportingChannel[m_Page] > 0)
{ {
WiiMoteEmu::g_ID = m_Page; WiiMoteEmu::g_ID = m_Page;
WiiMoteEmu::WmRequestStatus(WiiMoteEmu::g_ReportingChannel[m_Page], rs, Extension); WiiMoteEmu::WmRequestStatus(WiiMoteEmu::g_ReportingChannel[m_Page], rs, Extension);
@ -378,15 +386,23 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
case IDC_INPUT_SOURCE: case IDC_INPUT_SOURCE:
if (m_InputSource[m_Page]->GetSelection() == 2) if (m_InputSource[m_Page]->GetSelection() == 2)
{ {
g_Config.bUseRealWiimote = true; int current_real = 0;
WiiMoteEmu::WiiMapping[m_Page].Source = -1; for (int i = 0; i < MAX_WIIMOTES; i++)
DoUseReal(); if (WiiMoteEmu::WiiMapping[i].Source < 0)
current_real++;
if (current_real >= WiiMoteReal::g_NumberOfWiiMotes)
{
PanicAlert("You've already assigned all your %i Real WiiMote(s) connected!", WiiMoteReal::g_NumberOfWiiMotes);
m_InputSource[m_Page]->SetSelection(1);
} }
else else
{ {
g_Config.bUseRealWiimote = false; WiiMoteEmu::WiiMapping[m_Page].Source = -1;
WiiMoteEmu::WiiMapping[m_Page].Source = m_InputSource[m_Page]->GetSelection(); DoUseReal();
} }
}
else
WiiMoteEmu::WiiMapping[m_Page].Source = m_InputSource[m_Page]->GetSelection();
break; break;
case IDC_SIDEWAYSWIIMOTE: case IDC_SIDEWAYSWIIMOTE:
WiiMoteEmu::WiiMapping[m_Page].bSideways = m_SidewaysWiimote[m_Page]->IsChecked(); WiiMoteEmu::WiiMapping[m_Page].bSideways = m_SidewaysWiimote[m_Page]->IsChecked();
@ -402,7 +418,8 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
DoExtensionConnectedDisconnected(WiiMoteEmu::EXT_NONE); DoExtensionConnectedDisconnected(WiiMoteEmu::EXT_NONE);
// It doesn't seem to be needed but shouldn't it at least take 25 ms to // It doesn't seem to be needed but shouldn't it at least take 25 ms to
// reconnect an extension after we disconnected another? // reconnect an extension after we disconnected another?
if(g_EmulatorRunning) SLEEP(25); if(g_EmulatorRunning)
SLEEP(25);
// Update status // Update status
WiiMoteEmu::WiiMapping[m_Page].iExtensionConnected = m_Extension[m_Page]->GetSelection(); WiiMoteEmu::WiiMapping[m_Page].iExtensionConnected = m_Extension[m_Page]->GetSelection();
// Copy the calibration data // Copy the calibration data
@ -443,12 +460,26 @@ void WiimoteBasicConfigDialog::UpdateGUI()
could possibly be simplified to one option. */ could possibly be simplified to one option. */
m_ConnectRealWiimote[m_Page]->SetValue(g_Config.bConnectRealWiimote); m_ConnectRealWiimote[m_Page]->SetValue(g_Config.bConnectRealWiimote);
m_ConnectRealWiimote[m_Page]->Enable(!g_EmulatorRunning); m_ConnectRealWiimote[m_Page]->Enable(!g_EmulatorRunning);
m_InputSource[m_Page]->Enable(!g_EmulatorRunning);
if (WiiMoteEmu::WiiMapping[m_Page].Source < 0) if (WiiMoteEmu::WiiMapping[m_Page].Source < 0)
m_InputSource[m_Page]->SetSelection(2); m_InputSource[m_Page]->SetSelection(2);
else else
m_InputSource[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].Source); m_InputSource[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].Source);
if (m_InputSource[m_Page]->GetSelection() == 2)
{
m_SidewaysWiimote[m_Page]->Enable(false);
m_UprightWiimote[m_Page]->Enable(false);
m_Extension[m_Page]->Enable(false);
}
else
{
m_SidewaysWiimote[m_Page]->Enable(true);
m_UprightWiimote[m_Page]->Enable(true);
m_Extension[m_Page]->Enable(true);
}
m_SidewaysWiimote[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bSideways); m_SidewaysWiimote[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bSideways);
m_UprightWiimote[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bUpright); m_UprightWiimote[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bUpright);
m_WiiMotionPlusConnected[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bMotionPlusConnected); m_WiiMotionPlusConnected[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bMotionPlusConnected);

View File

@ -310,7 +310,7 @@ void Wiimote_InterruptChannel(int _number, u16 _channelID, const void* _pData, u
WiiMoteEmu::InterruptChannel(_number, _channelID, _pData, _Size); WiiMoteEmu::InterruptChannel(_number, _channelID, _pData, _Size);
#if HAVE_WIIUSE #if HAVE_WIIUSE
else if (g_RealWiiMotePresent) else if (g_RealWiiMotePresent)
WiiMoteReal::InterruptChannel(_channelID, _pData, _Size); // TODO: Multi-Wiimote WiiMoteReal::InterruptChannel(_number, _channelID, _pData, _Size);
#endif #endif
} }
@ -330,7 +330,7 @@ void Wiimote_ControlChannel(int _number, u16 _channelID, const void* _pData, u32
WiiMoteEmu::ControlChannel(_number, _channelID, _pData, _Size); WiiMoteEmu::ControlChannel(_number, _channelID, _pData, _Size);
#if HAVE_WIIUSE #if HAVE_WIIUSE
else if (g_RealWiiMotePresent) else if (g_RealWiiMotePresent)
WiiMoteReal::ControlChannel(_channelID, _pData, _Size); // TODO: Multi-Wiimote WiiMoteReal::ControlChannel(_number, _channelID, _pData, _Size);
#endif #endif
} }
@ -359,7 +359,7 @@ void Wiimote_Update(int _number)
WiiMoteEmu::Update(_number); WiiMoteEmu::Update(_number);
#if HAVE_WIIUSE #if HAVE_WIIUSE
else if (g_RealWiiMotePresent) else if (g_RealWiiMotePresent)
WiiMoteReal::Update(); // TODO: Multi-Wiimote WiiMoteReal::Update(_number);
#endif #endif
/* /*

View File

@ -62,6 +62,7 @@ int g_UpdateCounter = 0;
bool g_RunTemporary = false; bool g_RunTemporary = false;
int g_RunTemporaryCountdown = 0; int g_RunTemporaryCountdown = 0;
u8 g_EventBuffer[32]; u8 g_EventBuffer[32];
bool g_WiimoteInUse[MAX_WIIMOTES];
// Probably this class should be in its own file // Probably this class should be in its own file
@ -171,7 +172,8 @@ void Update()
if (m_EventReadQueue.empty()) if (m_EventReadQueue.empty())
{ {
// Send the data report // Send the data report
if (m_LastReportValid) SendEvent(m_LastReport); if (m_LastReportValid)
SendEvent(m_LastReport);
} }
else else
{ {
@ -219,7 +221,8 @@ private:
void SendEvent(SEvent& _rEvent) void SendEvent(SEvent& _rEvent)
{ {
// We don't have an answer channel // We don't have an answer channel
if (m_channelID == 0) return; if (m_channelID == 0)
return;
// Check event buffer // Check event buffer
u8 Buffer[1024]; u8 Buffer[1024];
@ -235,7 +238,7 @@ void SendEvent(SEvent& _rEvent)
Offset += sizeof(_rEvent.m_PayLoad); Offset += sizeof(_rEvent.m_PayLoad);
// Send it // Send it
g_WiimoteInitialize.pWiimoteInput(0, m_channelID, Buffer, Offset); // TODO: Multi-Wiimote g_WiimoteInitialize.pWiimoteInput(m_WiimoteNumber, m_channelID, Buffer, Offset);
// Debugging // Debugging
// ReadDebugging(false, Buffer, Offset); // ReadDebugging(false, Buffer, Offset);
@ -255,8 +258,8 @@ void SendAcc(u8 _ReportID)
DataAcc[2] = 0x00; DataAcc[2] = 0x00;
DataAcc[3] = _ReportID; // Reporting mode DataAcc[3] = _ReportID; // Reporting mode
// TODO: Update for multiple wiimotes? for (int i = 0; i < g_NumberOfWiiMotes; i++)
wiiuse_io_write(WiiMoteReal::g_WiiMotesFromWiiUse[0], (byte*)DataAcc, MAX_PAYLOAD); wiiuse_io_write(WiiMoteReal::g_WiiMotesFromWiiUse[i], (byte*)DataAcc, MAX_PAYLOAD);
std::string Temp = ArrayToString(DataAcc, 28, 0, 30); std::string Temp = ArrayToString(DataAcc, 28, 0, 30);
DEBUG_LOG(WIIMOTE, "SendAcc: %s", Temp.c_str()); DEBUG_LOG(WIIMOTE, "SendAcc: %s", Temp.c_str());
@ -277,37 +280,59 @@ void FlashLights(bool Connect)
for (int i = 0; i < g_NumberOfWiiMotes; i++) for (int i = 0; i < g_NumberOfWiiMotes; i++)
{ {
if(Connect) wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[i], 1); if (Connect)
wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[i], 1);
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1 | WIIMOTE_LED_2 | WIIMOTE_LED_3 | WIIMOTE_LED_4); wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1 | WIIMOTE_LED_2 | WIIMOTE_LED_3 | WIIMOTE_LED_4);
} }
SLEEP(100); SLEEP(100);
for (int i = 0; i < g_NumberOfWiiMotes; i++) for (int i = 0; i < g_NumberOfWiiMotes; i++)
{ {
if(Connect) if (Connect)
{
wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[i], 0); wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[i], 0);
// We are not connecting, so turn off all the LEDs
// End with light 1 or 4 else
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1); wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_NONE);
}
else wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_4);
} }
} }
int Initialize() int Initialize()
{ {
// Return if already initialized // Return if already initialized
if (g_RealWiiMoteInitialized) return g_NumberOfWiiMotes; if (g_RealWiiMoteInitialized)
return g_NumberOfWiiMotes;
// Clear the wiimote classes // Clear the wiimote classes
memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES); memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES);
for (int i = 0; i < MAX_WIIMOTES; i++)
g_WiimoteInUse[i] = false;
g_RealWiiMotePresent = false;
if (!g_Config.bConnectRealWiimote)
return 0;
// Call Wiiuse.dll // Call Wiiuse.dll
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES); g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5); g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
if (g_NumberOfWiiMotes > 0) g_RealWiiMotePresent = true; if (g_NumberOfWiiMotes > 0)
g_RealWiiMotePresent = true;
DEBUG_LOG(WIIMOTE, "Found No of Wiimotes: %i", g_NumberOfWiiMotes); DEBUG_LOG(WIIMOTE, "Found No of Wiimotes: %i", g_NumberOfWiiMotes);
DEBUG_LOG(WIIMOTE, "Using %i Real Wiimote(s) and %i Emu Wiimote(s)", g_Config.bNumberRealWiimotes, g_Config.bNumberEmuWiimotes);
// We want to use more Real WiiMotes than we really have, so we disable some...
if (g_Config.bNumberRealWiimotes > g_NumberOfWiiMotes)
{
int tmp = 0;
for(int i = 0; i < MAX_WIIMOTES; i++)
{
if (WiiMoteEmu::WiiMapping[i].Source < 0)
tmp++;
if (tmp > g_NumberOfWiiMotes)
WiiMoteEmu::WiiMapping[i].Source = 0;
}
}
for (int i = 0; i < g_NumberOfWiiMotes; i++) for (int i = 0; i < g_NumberOfWiiMotes; i++)
{ {
@ -332,19 +357,50 @@ int Initialize()
DEBUG_LOG(WIIMOTE, "Connected: %i", Connect); DEBUG_LOG(WIIMOTE, "Connected: %i", Connect);
#endif #endif
// If we are connecting from the config window without a game running we flash the lights // If we are connecting from the config window without a game running we set the LEDs
if (!g_EmulatorRunning && g_RealWiiMotePresent) FlashLights(true); if (!g_EmulatorRunning && g_RealWiiMotePresent)
FlashLights(true);
// Create Wiimote classes // Create Wiimote classes
for (int i = 0; i < g_NumberOfWiiMotes; i++) int current_number = 0;
g_WiiMotes[i] = new CWiiMote(i + 1, g_WiiMotesFromWiiUse[i]); for (int i = 0; i < g_NumberOfWiiMotes; i++) {
// Determine the number of the current WiiMote
for (; current_number < MAX_WIIMOTES; current_number++)
{
if (g_WiimoteInUse[current_number] == true)
continue;
if (WiiMoteEmu::WiiMapping[current_number].Source < 0)
break;
}
g_WiiMotes[current_number] = new CWiiMote(current_number, g_WiiMotesFromWiiUse[i]);
g_WiimoteInUse[current_number] = true;
switch (current_number)
{
case 0:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1);
break;
case 1:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_2);
break;
case 2:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_3);
break;
case 3:
default:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_NONE);
break;
}
DEBUG_LOG(WIIMOTE, "Real WiiMote allocated as WiiMote #%i", current_number);
}
// Create a new thread and start listening for Wiimote data // Create a new thread and start listening for Wiimote data
if (g_NumberOfWiiMotes > 0) if (g_NumberOfWiiMotes > 0)
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL); g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
// If we are not using the emulated wiimote we can run the thread temporary until the data has beeen copied // If we are not using any emulated wiimotes we can run the thread temporary until the data has beeen copied
if(g_Config.bUseRealWiimote) g_RunTemporary = true; if (g_Config.bNumberEmuWiimotes == 0)
g_RunTemporary = true;
/* Allocate memory and copy the Wiimote eeprom accelerometer neutral values /* Allocate memory and copy the Wiimote eeprom accelerometer neutral values
to g_Eeprom. Unlike with and extension we have to do this here, because to g_Eeprom. Unlike with and extension we have to do this here, because
@ -353,12 +409,15 @@ int Initialize()
we update its eeprom? In any case it's probably better to let the we update its eeprom? In any case it's probably better to let the
current calibration be where it is and adjust the global values after current calibration be where it is and adjust the global values after
that to avoid overwriting critical data on any Wiimote. */ that to avoid overwriting critical data on any Wiimote. */
// TODO: Update for multiple wiimotes? for (int i = 0; i < g_NumberOfWiiMotes; i++)
{
byte *data = (byte*)malloc(sizeof(byte) * sizeof(WiiMoteEmu::EepromData_0)); byte *data = (byte*)malloc(sizeof(byte) * sizeof(WiiMoteEmu::EepromData_0));
wiiuse_read_data(g_WiiMotesFromWiiUse[0], data, 0, sizeof(WiiMoteEmu::EepromData_0)); wiiuse_read_data(g_WiiMotesFromWiiUse[i], data, 0, sizeof(WiiMoteEmu::EepromData_0));
}
// Don't run the Wiimote thread if no wiimotes were found // Don't run the Wiimote thread if no wiimotes were found
if (g_NumberOfWiiMotes > 0) g_Shutdown = false; if (g_NumberOfWiiMotes > 0)
g_Shutdown = false;
// Initialized, even if we didn't find a Wiimote // Initialized, even if we didn't find a Wiimote
g_RealWiiMoteInitialized = true; g_RealWiiMoteInitialized = true;
@ -402,28 +461,24 @@ void Shutdown(void)
g_RealWiiMotePresent = false; g_RealWiiMotePresent = false;
} }
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size) void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size)
{ {
//DEBUG_LOG(WIIMOTE, "Real InterruptChannel"); //DEBUG_LOG(WIIMOTE, "Real InterruptChannel on WiiMote #%i", _WiimoteNumber);
// TODO: Update for multiple Wiimotes g_WiiMotes[_WiimoteNumber]->SendData(_channelID, (const u8*)_pData, _Size);
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size);
} }
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) void ControlChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size)
{ {
//DEBUG_LOG(WIIMOTE, "Real ControlChannel"); //DEBUG_LOG(WIIMOTE, "Real ControlChannel on WiiMote #%i", _WiimoteNumber);
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size); g_WiiMotes[_WiimoteNumber]->SendData(_channelID, (const u8*)_pData, _Size);
} }
// Read the Wiimote once // Read the Wiimote once
void Update() void Update(int _WiimoteNumber)
{ {
//DEBUG_LOG(WIIMOTE, "Real Update"); //DEBUG_LOG(WIIMOTE, "Real Update on WiiMote #%i", _WiimoteNumber);
for (int i = 0; i < g_NumberOfWiiMotes; i++) g_WiiMotes[_WiimoteNumber]->Update();
{
g_WiiMotes[i]->Update();
}
} }
/* Continuously read the Wiimote status. However, the actual sending of data /* Continuously read the Wiimote status. However, the actual sending of data
@ -436,8 +491,13 @@ THREAD_RETURN ReadWiimote_ThreadFunc(void* arg)
{ {
// We need g_ThreadGoing to do a manual WaitForSingleObject() from the configuration window // We need g_ThreadGoing to do a manual WaitForSingleObject() from the configuration window
g_ThreadGoing = true; g_ThreadGoing = true;
if(g_Config.bUseRealWiimote && !g_RunTemporary) // There is at least one Real Wiimote in use
for (int i = 0; i < g_NumberOfWiiMotes; i++) g_WiiMotes[i]->ReadData(); if (g_Config.bNumberRealWiimotes > 0 && !g_RunTemporary)
{
for (int i = 0; i < MAX_WIIMOTES; i++)
if (g_WiimoteInUse[i] == true)
g_WiiMotes[i]->ReadData();
}
else else
ReadWiimote(); ReadWiimote();
g_ThreadGoing = false; g_ThreadGoing = false;

View File

@ -29,9 +29,9 @@ namespace WiiMoteReal
int Initialize(); int Initialize();
void DoState(PointerWrap &p); void DoState(PointerWrap &p);
void Shutdown(void); void Shutdown(void);
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size); void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size); void ControlChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);
void Update(); void Update(int _WiimoteNumber);
void SendAcc(u8 _ReportID); void SendAcc(u8 _ReportID);
void SetDataReportingMode(u8 ReportingMode = 0); void SetDataReportingMode(u8 ReportingMode = 0);