mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 19:45:20 +00:00
Input: evdev: add positive axis list yml to handle 0+ range sticks
This commit is contained in:
parent
a6208d2bd7
commit
8a3759f479
2 changed files with 100 additions and 5 deletions
|
@ -84,7 +84,29 @@ evdev_joystick_handler::~evdev_joystick_handler()
|
|||
|
||||
bool evdev_joystick_handler::Init()
|
||||
{
|
||||
if (m_is_init)
|
||||
return true;
|
||||
|
||||
m_pad_config.load();
|
||||
m_pos_axis_config.load();
|
||||
|
||||
if (!m_pos_axis_config.exist())
|
||||
m_pos_axis_config.save();
|
||||
|
||||
for (const auto& node : m_pos_axis_config.get_nodes())
|
||||
{
|
||||
if (*static_cast<cfg::_bool*>(node.second))
|
||||
{
|
||||
std::string name = node.first;
|
||||
int code = libevdev_event_code_from_name(EV_ABS, name.c_str());
|
||||
if (code < 0)
|
||||
LOG_ERROR(HLE, "Failed to read axis name from %s. [code = %d] [name = %s]", m_pos_axis_config.cfg_name, code, name);
|
||||
else
|
||||
m_positive_axis.emplace_back(code);
|
||||
}
|
||||
}
|
||||
|
||||
m_is_init = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -176,6 +198,9 @@ std::unordered_map<u64, std::pair<u16, bool>> evdev_joystick_handler::GetButtonV
|
|||
std::unordered_map<u64, std::pair<u16, bool>> button_values;
|
||||
auto& dev = device.device;
|
||||
|
||||
if (!Init())
|
||||
return button_values;
|
||||
|
||||
for (auto entry : button_list)
|
||||
{
|
||||
auto code = entry.first;
|
||||
|
@ -197,7 +222,7 @@ std::unordered_map<u64, std::pair<u16, bool>> evdev_joystick_handler::GetButtonV
|
|||
int max = libevdev_get_abs_maximum(dev, code);
|
||||
|
||||
// Triggers do not need handling of negative values
|
||||
if (min >= 0)
|
||||
if (min >= 0 && std::find(m_positive_axis.begin(), m_positive_axis.end(), code) == m_positive_axis.end())
|
||||
{
|
||||
float fvalue = ScaleStickInput(val, min, max);
|
||||
button_values.emplace(code, std::make_pair<u16, bool>(static_cast<u16>(fvalue), false));
|
||||
|
@ -276,7 +301,7 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const
|
|||
if (get_blacklist)
|
||||
{
|
||||
blacklist.emplace_back(name);
|
||||
LOG_ERROR(HLE, "Evdev Calibration: Added button [ %d = %s ] to blacklist. Value = %d", code, name, value);
|
||||
LOG_ERROR(HLE, "Evdev Calibration: Added button [ %d = %s = %s ] to blacklist. Value = %d", code, libevdev_event_code_get_name(EV_KEY, code), name, value);
|
||||
}
|
||||
else if (value > pressed_button.first)
|
||||
pressed_button = { value, name };
|
||||
|
@ -302,7 +327,7 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const
|
|||
int min = libevdev_get_abs_minimum(dev, code);
|
||||
int max = libevdev_get_abs_maximum(dev, code);
|
||||
blacklist.emplace_back(name);
|
||||
LOG_ERROR(HLE, "Evdev Calibration: Added axis [ %d = %s ] to blacklist. [ Value = %d ] [ Min = %d ] [ Max = %d ]", code, name, value, min, max);
|
||||
LOG_ERROR(HLE, "Evdev Calibration: Added axis [ %d = %s = %s ] to blacklist. [ Value = %d ] [ Min = %d ] [ Max = %d ]", code, libevdev_event_code_get_name(EV_ABS, code), name, value, min, max);
|
||||
}
|
||||
else if (value > pressed_button.first)
|
||||
pressed_button = { value, name };
|
||||
|
@ -328,7 +353,7 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const
|
|||
int min = libevdev_get_abs_minimum(dev, code);
|
||||
int max = libevdev_get_abs_maximum(dev, code);
|
||||
blacklist.emplace_back(name);
|
||||
LOG_ERROR(HLE, "Evdev Calibration: Added rev axis [ %d = %s ] to blacklist. [ Value = %d ] [ Min = %d ] [ Max = %d ]", code, name, value, min, max);
|
||||
LOG_ERROR(HLE, "Evdev Calibration: Added rev axis [ %d = %s = %s ] to blacklist. [ Value = %d ] [ Min = %d ] [ Max = %d ]", code, libevdev_event_code_get_name(EV_ABS, code), name, value, min, max);
|
||||
}
|
||||
else if (value > pressed_button.first)
|
||||
pressed_button = { value, name };
|
||||
|
@ -536,7 +561,7 @@ int evdev_joystick_handler::GetButtonInfo(const input_event& evt, const EvdevDev
|
|||
int max = libevdev_get_abs_maximum(dev, code);
|
||||
|
||||
// Triggers do not need handling of negative values
|
||||
if (min >= 0)
|
||||
if (min >= 0 && std::find(m_positive_axis.begin(), m_positive_axis.end(), code) == m_positive_axis.end())
|
||||
{
|
||||
m_is_negative = false;
|
||||
m_is_button_or_trigger = true;
|
||||
|
|
|
@ -9,6 +9,73 @@
|
|||
#include <thread>
|
||||
#include <ctime>
|
||||
|
||||
struct positive_axis : cfg::node
|
||||
{
|
||||
const std::string cfg_name = fs::get_config_dir() + "/evdev_positive_axis.yml";
|
||||
|
||||
cfg::_bool abs_x{ this, "ABS_X", false };
|
||||
cfg::_bool abs_y{ this, "ABS_Y", false };
|
||||
cfg::_bool abs_z{ this, "ABS_Z", false };
|
||||
cfg::_bool abs_rx{ this, "ABS_RX", false };
|
||||
cfg::_bool abs_ry{ this, "ABS_RY", false };
|
||||
cfg::_bool abs_rz{ this, "ABS_RZ", false };
|
||||
cfg::_bool abs_throttle{ this, "ABS_THROTTLE", false };
|
||||
cfg::_bool abs_rudder{ this, "ABS_RUDDER", false };
|
||||
cfg::_bool abs_wheel{ this, "ABS_WHEEL", false };
|
||||
cfg::_bool abs_gas{ this, "ABS_GAS", false };
|
||||
cfg::_bool abs_brake{ this, "ABS_BRAKE", false };
|
||||
cfg::_bool abs_hat0x{ this, "ABS_HAT0X", false };
|
||||
cfg::_bool abs_hat0y{ this, "ABS_HAT0Y", false };
|
||||
cfg::_bool abs_hat1x{ this, "ABS_HAT1X", false };
|
||||
cfg::_bool abs_hat1y{ this, "ABS_HAT1Y", false };
|
||||
cfg::_bool abs_hat2x{ this, "ABS_HAT2X", false };
|
||||
cfg::_bool abs_hat2y{ this, "ABS_HAT2Y", false };
|
||||
cfg::_bool abs_hat3x{ this, "ABS_HAT3X", false };
|
||||
cfg::_bool abs_hat3y{ this, "ABS_HAT3Y", false };
|
||||
cfg::_bool abs_pressure{ this, "ABS_PRESSURE", false };
|
||||
cfg::_bool abs_distance{ this, "ABS_DISTANCE", false };
|
||||
cfg::_bool abs_tilt_x{ this, "ABS_TILT_X", false };
|
||||
cfg::_bool abs_tilt_y{ this, "ABS_TILT_Y", false };
|
||||
cfg::_bool abs_tool_width{ this, "ABS_TOOL_WIDTH", false };
|
||||
cfg::_bool abs_volume{ this, "ABS_VOLUME", false };
|
||||
cfg::_bool abs_misc{ this, "ABS_MISC", false };
|
||||
cfg::_bool abs_mt_slot{ this, "ABS_MT_SLOT", false };
|
||||
cfg::_bool abs_mt_touch_major{ this, "ABS_MT_TOUCH_MAJOR", false };
|
||||
cfg::_bool abs_mt_touch_minor{ this, "ABS_MT_TOUCH_MINOR", false };
|
||||
cfg::_bool abs_mt_width_major{ this, "ABS_MT_WIDTH_MAJOR", false };
|
||||
cfg::_bool abs_mt_width_minor{ this, "ABS_MT_WIDTH_MINOR", false };
|
||||
cfg::_bool abs_mt_orientation{ this, "ABS_MT_ORIENTATION", false };
|
||||
cfg::_bool abs_mt_position_x{ this, "ABS_MT_POSITION_X", false };
|
||||
cfg::_bool abs_mt_position_y{ this, "ABS_MT_POSITION_Y", false };
|
||||
cfg::_bool abs_mt_tool_type{ this, "ABS_MT_TOOL_TYPE", false };
|
||||
cfg::_bool abs_mt_blob_id{ this, "ABS_MT_BLOB_ID", false };
|
||||
cfg::_bool abs_mt_tracking_id{ this, "ABS_MT_TRACKING_ID", false };
|
||||
cfg::_bool abs_mt_pressure{ this, "ABS_MT_PRESSURE", false };
|
||||
cfg::_bool abs_mt_distance{ this, "ABS_MT_DISTANCE", false };
|
||||
cfg::_bool abs_mt_tool_x{ this, "ABS_MT_TOOL_X", false };
|
||||
cfg::_bool abs_mt_tool_y{ this, "ABS_MT_TOOL_Y", false };
|
||||
|
||||
bool load()
|
||||
{
|
||||
if (fs::file cfg_file{ cfg_name, fs::read })
|
||||
{
|
||||
return from_string(cfg_file.to_string());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void save()
|
||||
{
|
||||
fs::file(cfg_name, fs::rewrite).write(to_string());
|
||||
}
|
||||
|
||||
bool exist()
|
||||
{
|
||||
return fs::is_file(cfg_name);
|
||||
}
|
||||
};
|
||||
|
||||
class evdev_joystick_handler final : public PadHandlerBase
|
||||
{
|
||||
// Unique button names for the config files and our pad settings dialog
|
||||
|
@ -282,10 +349,13 @@ private:
|
|||
// Search axis_orientations map for the direction by index, returns -1 if not found, 0 for positive and 1 for negative
|
||||
int FindAxisDirection(const std::unordered_map<int, bool>& map, int index);
|
||||
|
||||
positive_axis m_pos_axis_config;
|
||||
std::vector<u32> m_positive_axis;
|
||||
std::vector<std::string> blacklist;
|
||||
std::vector<EvdevDevice> devices;
|
||||
int m_pad_index = -1;
|
||||
EvdevDevice m_dev;
|
||||
bool m_is_button_or_trigger;
|
||||
bool m_is_negative;
|
||||
bool m_is_init = false;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue