Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/gui/wxgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ add_library(CemuWxGui STATIC
input/InputAPIAddWindow.h
input/InputSettings2.cpp
input/InputSettings2.h
input/PairingDialog.cpp
input/PairingDialog.h
input/panels/ClassicControllerInputPanel.cpp
input/panels/ClassicControllerInputPanel.h
input/panels/InputPanel.cpp
Expand Down Expand Up @@ -124,10 +126,11 @@ if (ENABLE_METAL)
endif()

if (ENABLE_BLUEZ)
target_sources(CemuWxGui PRIVATE
input/PairingDialog.cpp
input/PairingDialog.h
)
target_compile_definitions(CemuWxGui PRIVATE HAS_BLUEZ)
endif()

if (SUPPORTS_WIIMOTE)
target_compile_definitions(CemuWxGui PRIVATE SUPPORTS_WIIMOTE)
endif()

set_property(TARGET CemuWxGui PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand Down
4 changes: 0 additions & 4 deletions src/gui/wxgui/input/InputSettings2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
#include "wxgui/input/InputAPIAddWindow.h"
#include "input/ControllerFactory.h"

#ifdef HAS_BLUEZ
#include "wxgui/input/PairingDialog.h"
#endif

#include "wxgui/input/panels/VPADInputPanel.h"
#include "wxgui/input/panels/ProControllerInputPanel.h"
Expand Down Expand Up @@ -257,14 +255,12 @@ wxWindow* InputSettings2::initialize_page(size_t index)
page_data.m_controller_api_remove = remove_api;
}

#ifdef HAS_BLUEZ
auto* pairingDialog = new wxButton(page, wxID_ANY, _("Pair Wii/Wii U Controller"));
pairingDialog->Bind(wxEVT_BUTTON, [this](wxEvent&) {
PairingDialog pairing_dialog(this);
pairing_dialog.ShowModal();
});
sizer->Add(pairingDialog, wxGBPosition(5, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxALL, 5);
#endif

// controller
auto* controller_bttns = new wxBoxSizer(wxHORIZONTAL);
Expand Down
42 changes: 38 additions & 4 deletions src/gui/wxgui/input/PairingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#if BOOST_OS_WINDOWS
#include <bluetoothapis.h>
#endif
#if BOOST_OS_LINUX
#ifdef HAS_BLUEZ
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
Expand Down Expand Up @@ -157,6 +157,7 @@ void PairingDialog::WorkerThread()
DWORD result = BluetoothGetRadioInfo(radio, &radioInfo);
if (result != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::NoBluetoothAvailable);
return;
}
Expand All @@ -165,8 +166,8 @@ void PairingDialog::WorkerThread()
{
.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS),

.fReturnAuthenticated = FALSE,
.fReturnRemembered = FALSE,
.fReturnAuthenticated = TRUE,
.fReturnRemembered = TRUE,
.fReturnUnknown = TRUE,
.fReturnConnected = FALSE,

Expand All @@ -184,33 +185,64 @@ void PairingDialog::WorkerThread()
HBLUETOOTH_DEVICE_FIND deviceFind = BluetoothFindFirstDevice(&searchParams, &info);
if (deviceFind == nullptr)
{
CloseHandle(radio);
UpdateCallback(PairingState::SearchFailed);
return;
}

while (!m_threadShouldQuit)
{
if (info.szName == wiimoteName || info.szName == wiiUProControllerName)
if (wcscmp(info.szName, wiimoteName.c_str()) == 0 || wcscmp(info.szName, wiiUProControllerName.c_str()) == 0)
{
BluetoothFindDeviceClose(deviceFind);

if (info.fAuthenticated)
{
DWORD bthResult = BluetoothSetServiceState(radio, &info, &bthHidGuid, BLUETOOTH_SERVICE_ENABLE);
if (bthResult != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::PairingFailed);
return;
}
CloseHandle(radio);
UpdateCallback(PairingState::Finished);
return;
}

if (info.fRemembered && !info.fAuthenticated)
{
BluetoothRemoveDevice(&info.Address);
Sleep(500);
}

UpdateCallback(PairingState::Pairing);

wchar_t passwd[6] = {radioInfo.address.rgBytes[0], radioInfo.address.rgBytes[1], radioInfo.address.rgBytes[2], radioInfo.address.rgBytes[3], radioInfo.address.rgBytes[4], radioInfo.address.rgBytes[5]};
DWORD bthResult = BluetoothAuthenticateDevice(nullptr, radio, &info, passwd, 6);

if (bthResult != ERROR_SUCCESS)
{
wchar_t passwd2[6] = {info.Address.rgBytes[0], info.Address.rgBytes[1], info.Address.rgBytes[2], info.Address.rgBytes[3], info.Address.rgBytes[4], info.Address.rgBytes[5]};
bthResult = BluetoothAuthenticateDevice(nullptr, radio, &info, passwd2, 6);
}

if (bthResult != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::PairingFailed);
return;
}

bthResult = BluetoothSetServiceState(radio, &info, &bthHidGuid, BLUETOOTH_SERVICE_ENABLE);
if (bthResult != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::PairingFailed);
return;
}

CloseHandle(radio);
UpdateCallback(PairingState::Finished);
return;
}
Expand All @@ -224,6 +256,8 @@ void PairingDialog::WorkerThread()

BluetoothFindDeviceClose(deviceFind);
}

CloseHandle(radio);
}
#elif defined(HAS_BLUEZ)
void PairingDialog::WorkerThread()
Expand Down
Loading