From c077426e95cd217ffad01cd60d9771f7fda30b94 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 1 Dec 2017 00:06:31 +0100 Subject: [PATCH] Input: Fix filter button for evdev and DS4 --- rpcs3/ds4_pad_handler.cpp | 38 +++++++++++++------------------- rpcs3/ds4_pad_handler.h | 1 - rpcs3/evdev_joystick_handler.cpp | 13 ++++++----- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/rpcs3/ds4_pad_handler.cpp b/rpcs3/ds4_pad_handler.cpp index aec8b8f6e8..16c2ea5aa4 100644 --- a/rpcs3/ds4_pad_handler.cpp +++ b/rpcs3/ds4_pad_handler.cpp @@ -153,8 +153,22 @@ void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::fu blacklist.clear(); std::shared_ptr device = GetDevice(padId); + if (device == nullptr || device->hidDevice == nullptr) + return; - if (CheckDeviceState(device) == false) + // Now that we have found a device, get its status + DS4DataStatus status = GetRawData(device); + + if (status == DS4DataStatus::ReadError) + { + // this also can mean disconnected, either way deal with it on next loop and reconnect + hid_close(device->hidDevice); + device->hidDevice = nullptr; + return; + } + + // return if nothing new has happened. ignore this to get the current state for blacklist + if (!get_blacklist && status != DS4DataStatus::NewData) return; // Get the current button values @@ -241,28 +255,6 @@ std::shared_ptr ds4_pad_handler::GetDevice(const std return device; } -bool ds4_pad_handler::CheckDeviceState(std::shared_ptr device) -{ - if (device == nullptr || device->hidDevice == nullptr) - return false; - - // Now that we have found a device, get its status - DS4DataStatus status = GetRawData(device); - - if (status == DS4DataStatus::ReadError) - { - // this also can mean disconnected, either way deal with it on next loop and reconnect - hid_close(device->hidDevice); - device->hidDevice = nullptr; - return false; - } - - if (status != DS4DataStatus::NewData) - return false; - - return true; -} - void ds4_pad_handler::TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold) { // Update the pad button values based on their type and thresholds. diff --git a/rpcs3/ds4_pad_handler.h b/rpcs3/ds4_pad_handler.h index 1d979c8b33..ef8adda825 100644 --- a/rpcs3/ds4_pad_handler.h +++ b/rpcs3/ds4_pad_handler.h @@ -154,7 +154,6 @@ private: private: std::shared_ptr GetDevice(const std::string& padId); - bool CheckDeviceState(std::shared_ptr device); void TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold = false) override; void ProcessDataToPad(const std::shared_ptr& ds4Device, const std::shared_ptr& pad); // Copies data into padData if status is NewData, otherwise buffer is untouched diff --git a/rpcs3/evdev_joystick_handler.cpp b/rpcs3/evdev_joystick_handler.cpp index 2291c27345..36c9c51445 100644 --- a/rpcs3/evdev_joystick_handler.cpp +++ b/rpcs3/evdev_joystick_handler.cpp @@ -221,12 +221,14 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const // Add device if not yet present m_pad_index = add_device(padId, true); - if (m_pad_index < 0) return; + if (m_pad_index < 0) + return; EvdevDevice& device = devices[m_pad_index]; // Check if our device is connected - if (!update_device(device, false)) return; + if (!update_device(device, false)) + return; auto& dev = device.device; @@ -236,10 +238,11 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const // Grab any pending sync event. if (ret == LIBEVDEV_READ_STATUS_SYNC) - { ret = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL | LIBEVDEV_READ_FLAG_SYNC, &evt); - } - if (ret < 0) return; + + // return if nothing new has happened. ignore this to get the current state for blacklist + if (!get_blacklist && ret < 0) + return; auto data = GetButtonValues(dev);