[Linux/MacOS] Further Wiimote changes for parity with Windows (#945)

This commit is contained in:
capitalistspz 2023-08-31 01:29:12 +00:00 committed by GitHub
parent d8b9a74d86
commit 5e84862e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 19 deletions

View File

@ -976,7 +976,7 @@ void InputSettings2::on_controller_settings(wxCommandEvent& event)
case InputAPI::Keyboard: break; case InputAPI::Keyboard: break;
#if BOOST_OS_WINDOWS #ifdef SUPPORTS_WIIMOTE
case InputAPI::Wiimote: { case InputAPI::Wiimote: {
const auto wiimote = std::dynamic_pointer_cast<NativeWiimoteController>(controller); const auto wiimote = std::dynamic_pointer_cast<NativeWiimoteController>(controller);
wxASSERT(wiimote); wxASSERT(wiimote);

View File

@ -14,7 +14,7 @@
#include "gui/components/wxInputDraw.h" #include "gui/components/wxInputDraw.h"
#include "gui/input/InputAPIAddWindow.h" #include "gui/input/InputAPIAddWindow.h"
#if BOOST_OS_WINDOWS #ifdef SUPPORTS_WIIMOTE
WiimoteControllerSettings::WiimoteControllerSettings(wxWindow* parent, const wxPoint& position, std::shared_ptr<NativeWiimoteController> controller) WiimoteControllerSettings::WiimoteControllerSettings(wxWindow* parent, const wxPoint& position, std::shared_ptr<NativeWiimoteController> controller)
: wxDialog(parent, wxID_ANY, _("Controller settings"), position, wxDefaultSize, : wxDialog(parent, wxID_ANY, _("Controller settings"), position, wxDefaultSize,
@ -56,6 +56,7 @@ WiimoteControllerSettings::WiimoteControllerSettings(wxWindow* parent, const wxP
// Motion // Motion
m_use_motion = new wxCheckBox(box, wxID_ANY, _("Use motion")); m_use_motion = new wxCheckBox(box, wxID_ANY, _("Use motion"));
m_use_motion->SetValue(m_settings.motion); m_use_motion->SetValue(m_settings.motion);
m_use_motion->SetValue(m_settings.motion);
m_use_motion->Enable(m_controller->has_motion()); m_use_motion->Enable(m_controller->has_motion());
row_sizer->Add(m_use_motion, 0, wxALL, 5); row_sizer->Add(m_use_motion, 0, wxALL, 5);

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#if BOOST_OS_WINDOWS #ifdef SUPPORTS_WIIMOTE
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/timer.h> #include <wx/timer.h>

View File

@ -62,6 +62,7 @@ if(WIN32)
endif() endif()
if (ENABLE_WIIMOTE) if (ENABLE_WIIMOTE)
target_compile_definitions(CemuInput PUBLIC SUPPORTS_WIIMOTE)
target_sources(CemuInput PRIVATE target_sources(CemuInput PRIVATE
api/Wiimote/WiimoteControllerProvider.h api/Wiimote/WiimoteControllerProvider.h
api/Wiimote/WiimoteControllerProvider.cpp api/Wiimote/WiimoteControllerProvider.cpp

View File

@ -5,7 +5,7 @@
#include "input/api/XInput/XInputControllerProvider.h" #include "input/api/XInput/XInputControllerProvider.h"
#endif #endif
#if defined(HAS_HIDAPI) || BOOST_OS_WINDOWS #ifdef SUPPORTS_WIIMOTE
#include "input/api/Wiimote/WiimoteControllerProvider.h" #include "input/api/Wiimote/WiimoteControllerProvider.h"
#endif #endif

View File

@ -5,8 +5,8 @@ static constexpr uint16 WIIMOTE_PRODUCT_ID = 0x0306;
static constexpr uint16 WIIMOTE_MP_PRODUCT_ID = 0x0330; static constexpr uint16 WIIMOTE_MP_PRODUCT_ID = 0x0330;
static constexpr uint16 WIIMOTE_MAX_INPUT_REPORT_LENGTH = 22; static constexpr uint16 WIIMOTE_MAX_INPUT_REPORT_LENGTH = 22;
HidapiWiimote::HidapiWiimote(hid_device* dev, uint64_t identifier) HidapiWiimote::HidapiWiimote(hid_device* dev, uint64_t identifier, std::string_view path)
: m_handle(dev), m_identifier(identifier) { : m_handle(dev), m_identifier(identifier), m_path(path) {
} }
@ -35,11 +35,12 @@ std::vector<WiimoteDevicePtr> HidapiWiimote::get_devices() {
cemuLog_logDebug(LogType::Force, "Unable to open Wiimote device at {}: {}", it->path, boost::nowide::narrow(hid_error(nullptr))); cemuLog_logDebug(LogType::Force, "Unable to open Wiimote device at {}: {}", it->path, boost::nowide::narrow(hid_error(nullptr)));
} }
else { else {
hid_set_nonblocking(dev, true);
// Enough to have a unique id for each device within a session // Enough to have a unique id for each device within a session
uint64_t id = (static_cast<uint64>(it->interface_number) << 32) | uint64_t id = (static_cast<uint64>(it->interface_number) << 32) |
(static_cast<uint64>(it->usage_page) << 16) | (static_cast<uint64>(it->usage_page) << 16) |
(it->usage); (it->usage);
wiimote_devices.push_back(std::make_shared<HidapiWiimote>(dev, id)); wiimote_devices.push_back(std::make_shared<HidapiWiimote>(dev, id, it->path));
} }
} }
hid_free_enumeration(device_enumeration); hid_free_enumeration(device_enumeration);
@ -47,7 +48,8 @@ std::vector<WiimoteDevicePtr> HidapiWiimote::get_devices() {
} }
bool HidapiWiimote::operator==(WiimoteDevice& o) const { bool HidapiWiimote::operator==(WiimoteDevice& o) const {
return m_identifier == static_cast<HidapiWiimote&>(o).m_identifier; auto const& other_mote = static_cast<HidapiWiimote const&>(o);
return m_identifier == other_mote.m_identifier && other_mote.m_path == m_path;
} }
HidapiWiimote::~HidapiWiimote() { HidapiWiimote::~HidapiWiimote() {

View File

@ -5,7 +5,7 @@
class HidapiWiimote : public WiimoteDevice { class HidapiWiimote : public WiimoteDevice {
public: public:
HidapiWiimote(hid_device* dev, uint64_t identifier); HidapiWiimote(hid_device* dev, uint64_t identifier, std::string_view path);
~HidapiWiimote() override; ~HidapiWiimote() override;
bool write_data(const std::vector<uint8> &data) override; bool write_data(const std::vector<uint8> &data) override;
@ -16,7 +16,8 @@ public:
private: private:
hid_device* m_handle; hid_device* m_handle;
uint64_t m_identifier; const uint64_t m_identifier;
const std::string m_path;
}; };

View File

@ -2,7 +2,7 @@
#include "input/api/Controller.h" #include "input/api/Controller.h"
#if BOOST_OS_WINDOWS #ifdef SUPPORTS_WIIMOTE
#include "input/api/Wiimote/NativeWiimoteController.h" #include "input/api/Wiimote/NativeWiimoteController.h"
#endif #endif
@ -131,7 +131,7 @@ bool EmulatedController::has_second_motion() const
if(controller->use_motion()) if(controller->use_motion())
{ {
// if wiimote has nunchuck connected, we use its acceleration // if wiimote has nunchuck connected, we use its acceleration
#if BOOST_OS_WINDOWS #if SUPPORTS_WIIMOTE
if(controller->api() == InputAPI::Wiimote) if(controller->api() == InputAPI::Wiimote)
{ {
if(((NativeWiimoteController*)controller.get())->get_extension() == NativeWiimoteController::Nunchuck) if(((NativeWiimoteController*)controller.get())->get_extension() == NativeWiimoteController::Nunchuck)
@ -156,7 +156,7 @@ MotionSample EmulatedController::get_second_motion_data() const
if (controller->use_motion()) if (controller->use_motion())
{ {
// if wiimote has nunchuck connected, we use its acceleration // if wiimote has nunchuck connected, we use its acceleration
#if BOOST_OS_WINDOWS #ifdef SUPPORTS_WIIMOTE
if (controller->api() == InputAPI::Wiimote) if (controller->api() == InputAPI::Wiimote)
{ {
if (((NativeWiimoteController*)controller.get())->get_extension() == NativeWiimoteController::Nunchuck) if (((NativeWiimoteController*)controller.get())->get_extension() == NativeWiimoteController::Nunchuck)
@ -211,12 +211,11 @@ void EmulatedController::add_controller(std::shared_ptr<ControllerBase> controll
{ {
controller->connect(); controller->connect();
#if BOOST_OS_WINDOWS #ifdef SUPPORTS_WIIMOTE
if (const auto wiimote = std::dynamic_pointer_cast<NativeWiimoteController>(controller)) { if (const auto wiimote = std::dynamic_pointer_cast<NativeWiimoteController>(controller)) {
wiimote->set_player_index(m_player_index); wiimote->set_player_index(m_player_index);
} }
#endif #endif
std::scoped_lock lock(m_mutex); std::scoped_lock lock(m_mutex);
m_controllers.emplace_back(std::move(controller)); m_controllers.emplace_back(std::move(controller));
} }