summaryrefslogtreecommitdiffstats
path: root/src/input_common/drivers
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2023-01-14 06:29:05 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2023-01-20 07:51:45 +0100
commit340f15d1fa79594dbe12a6e19140ba012751b533 (patch)
tree7a9ef54a17f927e4b8cf98dd32dd6d41c0d75201 /src/input_common/drivers
parentcore: hid: Only set the polling mode to the correct side (diff)
downloadyuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar
yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar.gz
yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar.bz2
yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar.lz
yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar.xz
yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar.zst
yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.zip
Diffstat (limited to 'src/input_common/drivers')
-rw-r--r--src/input_common/drivers/joycon.cpp50
-rw-r--r--src/input_common/drivers/joycon.h1
-rw-r--r--src/input_common/drivers/sdl_driver.cpp2
3 files changed, 27 insertions, 26 deletions
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp
index fff886ca8..1582def13 100644
--- a/src/input_common/drivers/joycon.cpp
+++ b/src/input_common/drivers/joycon.cpp
@@ -60,15 +60,12 @@ void Joycons::Setup() {
device = std::make_shared<Joycon::JoyconDriver>(port++);
}
- if (!scan_thread_running) {
- scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); });
- }
+ scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); });
}
void Joycons::ScanThread(std::stop_token stop_token) {
constexpr u16 nintendo_vendor_id = 0x057e;
- Common::SetCurrentThreadName("yuzu:input:JoyconScanThread");
- scan_thread_running = true;
+ Common::SetCurrentThreadName("JoyconScanThread");
while (!stop_token.stop_requested()) {
SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0);
SDL_hid_device_info* cur_dev = devs;
@@ -82,9 +79,9 @@ void Joycons::ScanThread(std::stop_token stop_token) {
cur_dev = cur_dev->next;
}
+ SDL_hid_free_enumeration(devs);
std::this_thread::sleep_for(std::chrono::seconds(5));
}
- scan_thread_running = false;
}
bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
@@ -185,19 +182,19 @@ void Joycons::RegisterNewDevice(SDL_hid_device_info* device_info) {
std::shared_ptr<Joycon::JoyconDriver> Joycons::GetNextFreeHandle(
Joycon::ControllerType type) const {
-
if (type == Joycon::ControllerType::Left) {
- for (const auto& device : left_joycons) {
- if (!device->IsConnected()) {
- return device;
- }
+ const auto unconnected_device =
+ std::ranges::find_if(left_joycons, [](auto& device) { return !device->IsConnected(); });
+ if (unconnected_device != left_joycons.end()) {
+ return *unconnected_device;
}
}
if (type == Joycon::ControllerType::Right) {
- for (const auto& device : right_joycons) {
- if (!device->IsConnected()) {
- return device;
- }
+ const auto unconnected_device = std::ranges::find_if(
+ right_joycons, [](auto& device) { return !device->IsConnected(); });
+
+ if (unconnected_device != right_joycons.end()) {
+ return *unconnected_device;
}
}
return nullptr;
@@ -391,20 +388,25 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
return false;
};
const auto type = static_cast<Joycon::ControllerType>(identifier.pad);
+
if (type == Joycon::ControllerType::Left) {
- for (const auto& device : left_joycons) {
- if (is_handle_active(device)) {
- return device;
- }
+ const auto matching_device = std::ranges::find_if(
+ left_joycons, [is_handle_active](auto& device) { return is_handle_active(device); });
+
+ if (matching_device != left_joycons.end()) {
+ return *matching_device;
}
}
+
if (type == Joycon::ControllerType::Right) {
- for (const auto& device : right_joycons) {
- if (is_handle_active(device)) {
- return device;
- }
+ const auto matching_device = std::ranges::find_if(
+ right_joycons, [is_handle_active](auto& device) { return is_handle_active(device); });
+
+ if (matching_device != right_joycons.end()) {
+ return *matching_device;
}
}
+
return nullptr;
}
@@ -676,7 +678,7 @@ std::string Joycons::JoyconName(Joycon::ControllerType type) const {
case Joycon::ControllerType::Dual:
return "Dual Joycon";
default:
- return "Unknow Joycon";
+ return "Unknown Joycon";
}
}
} // namespace InputCommon
diff --git a/src/input_common/drivers/joycon.h b/src/input_common/drivers/joycon.h
index f5cc787db..6d2e2ec78 100644
--- a/src/input_common/drivers/joycon.h
+++ b/src/input_common/drivers/joycon.h
@@ -99,7 +99,6 @@ private:
std::string JoyconName(Joycon::ControllerType type) const;
std::jthread scan_thread;
- bool scan_thread_running{};
// Joycon types are split by type to ease supporting dualjoycon configurations
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{};
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index e915ec090..a0103edde 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -321,7 +321,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
if (Settings::values.enable_joycon_driver) {
if (guid.uuid[5] == 0x05 && guid.uuid[4] == 0x7e &&
(guid.uuid[8] == 0x06 || guid.uuid[8] == 0x07)) {
- LOG_ERROR(Input, "Device black listed {}", joystick_index);
+ LOG_WARNING(Input, "Preferring joycon driver for device index {}", joystick_index);
SDL_JoystickClose(sdl_joystick);
return;
}