Move the Wiimote connect code out of Host

I don't know who thought it would be a good idea to put the Wiimote
connect code as part of the Host interface, and have that called
from both the UI code and the core. And then hack around it by having
"force connect" events whenever Host_ConnectWiimote is called
from the core...
This commit is contained in:
Léo Lam
2017-07-19 15:55:45 +08:00
parent 9237137c3a
commit ee868e2362
14 changed files with 42 additions and 114 deletions

View File

@ -6,9 +6,15 @@
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/IOS/IOS.h"
#include "Core/IOS/USB/Bluetooth/BTEmu.h"
#include "Core/IOS/USB/Bluetooth/WiimoteDevice.h"
#include "Core/Movie.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
@ -81,6 +87,25 @@ void Initialize(InitializeMode init_mode)
Movie::ChangeWiiPads();
}
void Connect(unsigned int index, bool connect)
{
if (SConfig::GetInstance().m_bt_passthrough_enabled || index >= MAX_BBMOTES)
return;
const auto ios = IOS::HLE::GetIOS();
if (!ios)
return;
const auto bluetooth = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
ios->GetDeviceByName("/dev/usb/oh1/57e/305"));
if (bluetooth)
bluetooth->AccessWiiMote(index | 0x100)->Activate(connect);
const char* message = connect ? "Wii Remote %i connected" : "Wii Remote %i disconnected";
Core::DisplayMessage(StringFromFormat(message, index + 1), 3000);
}
void ResetAllWiimotes()
{
for (int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i)

View File

@ -58,6 +58,7 @@ enum class InitializeMode
void Shutdown();
void Initialize(InitializeMode init_mode);
void Connect(unsigned int index, bool connect);
void ResetAllWiimotes();
void LoadConfig();
void Resume();

View File

@ -948,7 +948,7 @@ void Wiimote::ConnectOnInput()
if (buttons != 0 || m_extension->IsButtonPressed())
{
Host_ConnectWiimote(m_index, true);
::Wiimote::Connect(m_index, true);
// arbitrary value so it doesn't try to send multiple requests before Dolphin can react
// if Wii Remotes are polled at 200Hz then this results in one request being sent per 500ms
m_last_connect_request_counter = 100;

View File

@ -18,6 +18,7 @@
#include "Common/Thread.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteCommon/WiimoteHid.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/IOAndroid.h"
@ -390,7 +391,7 @@ void Wiimote::ConnectOnInput()
// check any button without checking accelerometer data
if ((rpt[2] & 0x1F) != 0 || (rpt[3] & 0x9F) != 0)
{
Host_ConnectWiimote(m_index, true);
::Wiimote::Connect(m_index, true);
// see WiimoteEmu::Wiimote::ConnectOnInput(), same idea here
m_last_connect_request_counter = 100;
}
@ -795,11 +796,14 @@ void ChangeWiimoteSource(unsigned int index, int source)
}
// reconnect to the emulator
Host_ConnectWiimote(index, false);
if (WIIMOTE_SRC_EMU & source)
Host_ConnectWiimote(index, true);
Core::RunAsCPUThread([index, source] {
::Wiimote::Connect(index, false);
if (WIIMOTE_SRC_EMU & source)
::Wiimote::Connect(index, true);
});
}
// Called from the Wiimote scanner thread
static bool TryToConnectWiimoteToSlot(Wiimote* wm, unsigned int i)
{
if (WIIMOTE_SRC_REAL & g_wiimote_sources[i] && !g_wiimotes[i])
@ -808,7 +812,7 @@ static bool TryToConnectWiimoteToSlot(Wiimote* wm, unsigned int i)
{
NOTICE_LOG(WIIMOTE, "Connected to Wiimote %i.", i + 1);
g_wiimotes[i] = wm;
Host_ConnectWiimote(i, true);
Core::RunAsCPUThread([i] { ::Wiimote::Connect(i, true); });
std::lock_guard<std::mutex> lk(s_known_ids_mutex);
s_known_ids.insert(wm->GetId());
}
@ -884,13 +888,11 @@ void Update(int wiimote_number)
if (g_wiimotes[wiimote_number])
g_wiimotes[wiimote_number]->Update();
g_wiimotes_mutex.unlock();
// Wiimote::Update() may remove the Wiimote if it was disconnected.
if (!g_wiimotes[wiimote_number])
{
Host_ConnectWiimote(wiimote_number, false);
}
g_wiimotes_mutex.unlock();
::Wiimote::Connect(wiimote_number, false);
}
void ConnectOnInput(int wiimote_number)

View File

@ -26,7 +26,6 @@
bool Host_UINeedsControllerState();
bool Host_RendererHasFocus();
bool Host_RendererIsFullscreen();
void Host_ConnectWiimote(int wm_idx, bool connect);
void Host_Message(int Id);
void Host_NotifyMapLoaded();
void Host_RefreshDSPDebuggerWindow();