From 82512b3ca03d85ea115bafac070976ec1f7b6478 Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 27 Jan 2019 10:28:33 -0500 Subject: [PATCH] Linux: Fixed deadzone option having no effect --- Linux/LinuxGameController.cpp | 14 +++++++++----- Linux/LinuxGameController.h | 6 ++++-- Linux/LinuxKeyManager.cpp | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Linux/LinuxGameController.cpp b/Linux/LinuxGameController.cpp index dc0a36c0..a1ea3b16 100644 --- a/Linux/LinuxGameController.cpp +++ b/Linux/LinuxGameController.cpp @@ -1,4 +1,6 @@ #include "../Core/MessageManager.h" +#include "../Core/Console.h" +#include "../Core/EmulationSettings.h" #include "LinuxGameController.h" #include #include @@ -10,7 +12,7 @@ #include #include -std::shared_ptr LinuxGameController::GetController(int deviceID, bool logInformation) +std::shared_ptr LinuxGameController::GetController(shared_ptr console, int deviceID, bool logInformation) { std::string deviceName = "/dev/input/event" + std::to_string(deviceID); struct stat buffer; @@ -36,7 +38,7 @@ std::shared_ptr LinuxGameController::GetController(int devi if((libevdev_has_event_type(device, EV_KEY) && libevdev_has_event_code(device, EV_KEY, BTN_GAMEPAD)) || (libevdev_has_event_type(device, EV_ABS) && libevdev_has_event_code(device, EV_ABS, ABS_X))) { MessageManager::Log(std::string("[Input Connected] Name: ") + libevdev_get_name(device) + " Vendor: " + std::to_string(libevdev_get_id_vendor(device)) + " Product: " + std::to_string(libevdev_get_id_product(device))); - return std::shared_ptr(new LinuxGameController(deviceID, fd, device)); + return std::shared_ptr(new LinuxGameController(console, deviceID, fd, device)); } else { MessageManager::Log(std::string("[Input] Device ignored (Not a gamepad) - Name: ") + libevdev_get_name(device) + " Vendor: " + std::to_string(libevdev_get_id_vendor(device)) + " Product: " + std::to_string(libevdev_get_id_product(device))); close(fd); @@ -45,8 +47,9 @@ std::shared_ptr LinuxGameController::GetController(int devi return nullptr; } -LinuxGameController::LinuxGameController(int deviceID, int fileDescriptor, libevdev* device) +LinuxGameController::LinuxGameController(shared_ptr console, int deviceID, int fileDescriptor, libevdev* device) { + _console = console; _deviceID = deviceID; _stopFlag = false; _device = device; @@ -119,8 +122,9 @@ void LinuxGameController::Calibrate() bool LinuxGameController::CheckAxis(unsigned int code, bool forPositive) { - int deadZoneNegative = (_axisDefaultValue[code] - libevdev_get_abs_minimum(_device, code)) * 0.225; - int deadZonePositive = (libevdev_get_abs_maximum(_device, code) - _axisDefaultValue[code]) * 0.225; + double deadZoneRatio = _console->GetSettings()->GetControllerDeadzoneRatio(); + int deadZoneNegative = (_axisDefaultValue[code] - libevdev_get_abs_minimum(_device, code)) * 0.400 * deadZoneRatio; + int deadZonePositive = (libevdev_get_abs_maximum(_device, code) - _axisDefaultValue[code]) * 0.400 * deadZoneRatio; if(forPositive) { return libevdev_get_event_value(_device, EV_ABS, code) - _axisDefaultValue[code] > deadZonePositive; diff --git a/Linux/LinuxGameController.h b/Linux/LinuxGameController.h index 7dce6ed7..7e2d3215 100644 --- a/Linux/LinuxGameController.h +++ b/Linux/LinuxGameController.h @@ -3,6 +3,7 @@ #include struct libevdev; +class Console; class LinuxGameController { @@ -13,16 +14,17 @@ private: bool _disconnected = false; std::thread _eventThread; std::atomic _stopFlag; + shared_ptr _console; int _axisDefaultValue[0x100]; - LinuxGameController(int deviceID, int fileDescriptor, libevdev *device); + LinuxGameController(shared_ptr console, int deviceID, int fileDescriptor, libevdev *device); bool CheckAxis(unsigned int code, bool forPositive); void Calibrate(); public: ~LinuxGameController(); - static std::shared_ptr GetController(int deviceID, bool logInformation); + static std::shared_ptr GetController(shared_ptr console, int deviceID, bool logInformation); bool IsDisconnected(); int GetDeviceID(); diff --git a/Linux/LinuxKeyManager.cpp b/Linux/LinuxKeyManager.cpp index 13b75f05..224f8623 100755 --- a/Linux/LinuxKeyManager.cpp +++ b/Linux/LinuxKeyManager.cpp @@ -258,7 +258,7 @@ LinuxKeyManager::LinuxKeyManager(shared_ptr console) } for(int i = 0; i < 30; i++) { - std::shared_ptr controller = LinuxGameController::GetController(i, true); + std::shared_ptr controller = LinuxGameController::GetController(_console, i, true); if(controller) { _controllers.push_back(controller); } @@ -372,7 +372,7 @@ void LinuxKeyManager::StartUpdateDeviceThread() for(int i = 0; i < 30; i++) { if(std::find(connectedIDs.begin(), connectedIDs.end(), i) == connectedIDs.end()) { - std::shared_ptr controller = LinuxGameController::GetController(i, false); + std::shared_ptr controller = LinuxGameController::GetController(_console, i, false); if(controller) { controllersToAdd.push_back(controller); }