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/MessageManager.h"
|
||||||
|
#include "../Core/Console.h"
|
||||||
|
#include "../Core/EmulationSettings.h"
|
||||||
#include "LinuxGameController.h"
|
#include "LinuxGameController.h"
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -10,7 +12,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <iostream>
|
#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);
|
std::string deviceName = "/dev/input/event" + std::to_string(deviceID);
|
||||||
struct stat buffer;
|
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)) ||
|
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))) {
|
(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)));
|
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 {
|
} 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)));
|
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);
|
close(fd);
|
||||||
|
@ -45,8 +47,9 @@ std::shared_ptr<LinuxGameController> LinuxGameController::GetController(int devi
|
||||||
return nullptr;
|
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;
|
_deviceID = deviceID;
|
||||||
_stopFlag = false;
|
_stopFlag = false;
|
||||||
_device = device;
|
_device = device;
|
||||||
|
@ -119,8 +122,9 @@ void LinuxGameController::Calibrate()
|
||||||
|
|
||||||
bool LinuxGameController::CheckAxis(unsigned int code, bool forPositive)
|
bool LinuxGameController::CheckAxis(unsigned int code, bool forPositive)
|
||||||
{
|
{
|
||||||
int deadZoneNegative = (_axisDefaultValue[code] - libevdev_get_abs_minimum(_device, code)) * 0.225;
|
double deadZoneRatio = _console->GetSettings()->GetControllerDeadzoneRatio();
|
||||||
int deadZonePositive = (libevdev_get_abs_maximum(_device, code) - _axisDefaultValue[code]) * 0.225;
|
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) {
|
if(forPositive) {
|
||||||
return libevdev_get_event_value(_device, EV_ABS, code) - _axisDefaultValue[code] > deadZonePositive;
|
return libevdev_get_event_value(_device, EV_ABS, code) - _axisDefaultValue[code] > deadZonePositive;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
struct libevdev;
|
struct libevdev;
|
||||||
|
class Console;
|
||||||
|
|
||||||
class LinuxGameController
|
class LinuxGameController
|
||||||
{
|
{
|
||||||
|
@ -13,16 +14,17 @@ private:
|
||||||
bool _disconnected = false;
|
bool _disconnected = false;
|
||||||
std::thread _eventThread;
|
std::thread _eventThread;
|
||||||
std::atomic<bool> _stopFlag;
|
std::atomic<bool> _stopFlag;
|
||||||
|
shared_ptr<Console> _console;
|
||||||
int _axisDefaultValue[0x100];
|
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);
|
bool CheckAxis(unsigned int code, bool forPositive);
|
||||||
void Calibrate();
|
void Calibrate();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~LinuxGameController();
|
~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();
|
bool IsDisconnected();
|
||||||
int GetDeviceID();
|
int GetDeviceID();
|
||||||
|
|
|
@ -258,7 +258,7 @@ LinuxKeyManager::LinuxKeyManager(shared_ptr<Console> console)
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 30; i++) {
|
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) {
|
if(controller) {
|
||||||
_controllers.push_back(controller);
|
_controllers.push_back(controller);
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ void LinuxKeyManager::StartUpdateDeviceThread()
|
||||||
|
|
||||||
for(int i = 0; i < 30; i++) {
|
for(int i = 0; i < 30; i++) {
|
||||||
if(std::find(connectedIDs.begin(), connectedIDs.end(), i) == connectedIDs.end()) {
|
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) {
|
if(controller) {
|
||||||
controllersToAdd.push_back(controller);
|
controllersToAdd.push_back(controller);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue