From aae5c950f04ff555c459b91ec65002635b2d4987 Mon Sep 17 00:00:00 2001 From: spycrab Date: Wed, 24 Jan 2018 15:25:35 +0100 Subject: [PATCH] Qt: Implement "Connect Wii Remotes" menu --- Source/Core/DolphinQt2/HotkeyScheduler.cpp | 4 +-- Source/Core/DolphinQt2/HotkeyScheduler.h | 1 + Source/Core/DolphinQt2/MainWindow.cpp | 18 ++++++++++++ Source/Core/DolphinQt2/MainWindow.h | 1 + Source/Core/DolphinQt2/MenuBar.cpp | 33 ++++++++++++++++++++++ Source/Core/DolphinQt2/MenuBar.h | 3 ++ 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt2/HotkeyScheduler.cpp b/Source/Core/DolphinQt2/HotkeyScheduler.cpp index b68bc4172e..ad0114b96c 100644 --- a/Source/Core/DolphinQt2/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt2/HotkeyScheduler.cpp @@ -209,8 +209,8 @@ void HotkeyScheduler::Run() if (IsHotkey(HK_BALANCEBOARD_CONNECT)) wiimote_id = 4; - // TODO Implement Wiimote connecting / disconnecting (Separate PR) - // if (wiimote_id > -1) + if (wiimote_id > -1) + emit ConnectWiiRemote(wiimote_id); } // Graphics diff --git a/Source/Core/DolphinQt2/HotkeyScheduler.h b/Source/Core/DolphinQt2/HotkeyScheduler.h index 08ff20b725..7aee962eec 100644 --- a/Source/Core/DolphinQt2/HotkeyScheduler.h +++ b/Source/Core/DolphinQt2/HotkeyScheduler.h @@ -31,6 +31,7 @@ signals: void StartRecording(); void ExportRecording(); void ToggleReadOnlyMode(); + void ConnectWiiRemote(int id); private: void Run(); diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 12e2d41b40..f64daf44ff 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -32,6 +32,8 @@ #include "Core/HW/Wiimote.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HotkeyManager.h" +#include "Core/IOS/USB/Bluetooth/BTEmu.h" +#include "Core/IOS/USB/Bluetooth/WiimoteDevice.h" #include "Core/Movie.h" #include "Core/NetPlayClient.h" #include "Core/NetPlayProto.h" @@ -238,6 +240,7 @@ void MainWindow::ConnectMenuBar() connect(m_menu_bar, &MenuBar::BootWiiSystemMenu, this, &MainWindow::BootWiiSystemMenu); connect(m_menu_bar, &MenuBar::StartNetPlay, this, &MainWindow::ShowNetPlaySetupDialog); connect(m_menu_bar, &MenuBar::ShowFIFOPlayer, this, &MainWindow::ShowFIFOPlayer); + connect(m_menu_bar, &MenuBar::ConnectWiiRemote, this, &MainWindow::OnConnectWiiRemote); // Movie connect(m_menu_bar, &MenuBar::PlayRecording, this, &MainWindow::OnPlayRecording); @@ -282,6 +285,8 @@ void MainWindow::ConnectHotkeys() &MainWindow::OnStartRecording); connect(m_hotkey_scheduler, &HotkeyScheduler::ExportRecording, this, &MainWindow::OnExportRecording); + connect(m_hotkey_scheduler, &HotkeyScheduler::ConnectWiiRemote, this, + &MainWindow::OnConnectWiiRemote); connect(m_hotkey_scheduler, &HotkeyScheduler::ToggleReadOnlyMode, [this] { bool read_only = !Movie::IsReadOnly(); Movie::SetReadOnly(read_only); @@ -1047,3 +1052,16 @@ void MainWindow::OnExportRecording() Movie::SaveRecording(dtm_file.toStdString()); } + +void MainWindow::OnConnectWiiRemote(int id) +{ + const auto ios = IOS::HLE::GetIOS(); + if (!ios || SConfig::GetInstance().m_bt_passthrough_enabled) + return; + Core::RunAsCPUThread([&] { + const auto bt = std::static_pointer_cast( + ios->GetDeviceByName("/dev/usb/oh1/57e/305")); + const bool is_connected = bt && bt->AccessWiiMote(id | 0x100)->IsConnected(); + Wiimote::Connect(id, !is_connected); + }); +} diff --git a/Source/Core/DolphinQt2/MainWindow.h b/Source/Core/DolphinQt2/MainWindow.h index 8966fe45e2..9759558c7f 100644 --- a/Source/Core/DolphinQt2/MainWindow.h +++ b/Source/Core/DolphinQt2/MainWindow.h @@ -112,6 +112,7 @@ private: void OnBootGameCubeIPL(DiscIO::Region region); void OnImportNANDBackup(); + void OnConnectWiiRemote(int id); void OnPlayRecording(); void OnStartRecording(); diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index 326d35a1b4..bd580713ca 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -24,6 +24,7 @@ #include "Core/HW/Wiimote.h" #include "Core/IOS/ES/ES.h" #include "Core/IOS/IOS.h" +#include "Core/IOS/USB/Bluetooth/BTEmu.h" #include "Core/Movie.h" #include "Core/State.h" #include "Core/TitleDatabase.h" @@ -156,6 +157,24 @@ void MenuBar::AddToolsMenu() [this] { emit PerformOnlineUpdate("KOR"); }); AddAction(m_perform_online_update_menu, tr("United States"), this, [this] { emit PerformOnlineUpdate("USA"); }); + + QMenu* menu = new QMenu(tr("Connect Wii Remotes")); + + tools_menu->addSeparator(); + tools_menu->addMenu(menu); + + for (int i = 0; i < 4; i++) + { + m_wii_remotes[i] = AddAction(menu, tr("Connect Wii Remote %1").arg(i + 1), this, + [this, i] { emit ConnectWiiRemote(i); }); + m_wii_remotes[i]->setCheckable(true); + } + + menu->addSeparator(); + + m_wii_remotes[4] = + AddAction(menu, tr("Connect Balance Board"), this, [this] { emit ConnectWiiRemote(4); }); + m_wii_remotes[4]->setCheckable(true); } void MenuBar::AddEmulationMenu() @@ -541,6 +560,20 @@ void MenuBar::UpdateToolsMenu(bool emulation_started) action->setEnabled(!tmd.IsValid()); m_perform_online_update_for_current_region->setEnabled(tmd.IsValid()); } + + const auto ios = IOS::HLE::GetIOS(); + const auto bt = ios ? std::static_pointer_cast( + ios->GetDeviceByName("/dev/usb/oh1/57e/305")) : + nullptr; + bool enable_wiimotes = + emulation_started && bt && !SConfig::GetInstance().m_bt_passthrough_enabled; + + for (int i = 0; i < 5; i++) + { + m_wii_remotes[i]->setEnabled(enable_wiimotes); + if (enable_wiimotes) + m_wii_remotes[i]->setChecked(bt->AccessWiiMote(0x0100 + i)->IsConnected()); + } } void MenuBar::InstallWAD() diff --git a/Source/Core/DolphinQt2/MenuBar.h b/Source/Core/DolphinQt2/MenuBar.h index ef73d8623f..a8fb661701 100644 --- a/Source/Core/DolphinQt2/MenuBar.h +++ b/Source/Core/DolphinQt2/MenuBar.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include @@ -64,6 +65,7 @@ signals: void BootGameCubeIPL(DiscIO::Region region); void ShowFIFOPlayer(); void ShowAboutDialog(); + void ConnectWiiRemote(int id); // Options void Configure(); @@ -135,6 +137,7 @@ private: QAction* m_import_backup; QAction* m_check_nand; QAction* m_extract_certificates; + std::array m_wii_remotes; // Emulation QAction* m_play_action;