Linux: Fixed deadzone option having no effect
This commit is contained in:
parent
ac45747a00
commit
82512b3ca0
3 changed files with 15 additions and 9 deletions
|
@ -1,4 +1,6 @@
|
|||
#include "../Core/MessageManager.h"
|
||||
#include "../Core/Console.h"
|
||||
#include "../Core/EmulationSettings.h"
|
||||
#include "LinuxGameController.h"
|
||||
#include <libevdev/libevdev.h>
|
||||
#include <unistd.h>
|
||||
|
@ -10,7 +12,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
|
||||
std::shared_ptr<LinuxGameController> LinuxGameController::GetController(int deviceID, bool logInformation)
|
||||
std::shared_ptr<LinuxGameController> LinuxGameController::GetController(shared_ptr<Console> 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> 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<LinuxGameController>(new LinuxGameController(deviceID, fd, device));
|
||||
return std::shared_ptr<LinuxGameController>(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> LinuxGameController::GetController(int devi
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
LinuxGameController::LinuxGameController(int deviceID, int fileDescriptor, libevdev* device)
|
||||
LinuxGameController::LinuxGameController(shared_ptr<Console> 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;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <atomic>
|
||||
|
||||
struct libevdev;
|
||||
class Console;
|
||||
|
||||
class LinuxGameController
|
||||
{
|
||||
|
@ -13,16 +14,17 @@ private:
|
|||
bool _disconnected = false;
|
||||
std::thread _eventThread;
|
||||
std::atomic<bool> _stopFlag;
|
||||
shared_ptr<Console> _console;
|
||||
int _axisDefaultValue[0x100];
|
||||
|
||||
LinuxGameController(int deviceID, int fileDescriptor, libevdev *device);
|
||||
LinuxGameController(shared_ptr<Console> console, int deviceID, int fileDescriptor, libevdev *device);
|
||||
bool CheckAxis(unsigned int code, bool forPositive);
|
||||
void Calibrate();
|
||||
|
||||
public:
|
||||
~LinuxGameController();
|
||||
|
||||
static std::shared_ptr<LinuxGameController> GetController(int deviceID, bool logInformation);
|
||||
static std::shared_ptr<LinuxGameController> GetController(shared_ptr<Console> console, int deviceID, bool logInformation);
|
||||
|
||||
bool IsDisconnected();
|
||||
int GetDeviceID();
|
||||
|
|
|
@ -258,7 +258,7 @@ LinuxKeyManager::LinuxKeyManager(shared_ptr<Console> console)
|
|||
}
|
||||
|
||||
for(int i = 0; i < 30; i++) {
|
||||
std::shared_ptr<LinuxGameController> controller = LinuxGameController::GetController(i, true);
|
||||
std::shared_ptr<LinuxGameController> 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<LinuxGameController> controller = LinuxGameController::GetController(i, false);
|
||||
std::shared_ptr<LinuxGameController> controller = LinuxGameController::GetController(_console, i, false);
|
||||
if(controller) {
|
||||
controllersToAdd.push_back(controller);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue