Input: Fix filter button for evdev and DS4

This commit is contained in:
Unknown 2017-12-01 00:06:31 +01:00 committed by Ani
parent c870bbb885
commit c077426e95
3 changed files with 23 additions and 29 deletions

View File

@ -153,8 +153,22 @@ void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::fu
blacklist.clear();
std::shared_ptr<DS4Device> 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::DS4Device> ds4_pad_handler::GetDevice(const std
return device;
}
bool ds4_pad_handler::CheckDeviceState(std::shared_ptr<DS4Device> 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.

View File

@ -154,7 +154,6 @@ private:
private:
std::shared_ptr<DS4Device> GetDevice(const std::string& padId);
bool CheckDeviceState(std::shared_ptr<DS4Device> device);
void TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold = false) override;
void ProcessDataToPad(const std::shared_ptr<DS4Device>& ds4Device, const std::shared_ptr<Pad>& pad);
// Copies data into padData if status is NewData, otherwise buffer is untouched

View File

@ -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);