From 8a3759f479e0f19610495f47a891516a14192b72 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 23 Dec 2017 12:28:10 +0100 Subject: [PATCH] Input: evdev: add positive axis list yml to handle 0+ range sticks --- rpcs3/evdev_joystick_handler.cpp | 35 +++++++++++++--- rpcs3/evdev_joystick_handler.h | 70 ++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 5 deletions(-) diff --git a/rpcs3/evdev_joystick_handler.cpp b/rpcs3/evdev_joystick_handler.cpp index 71ec59f8a6..701ba76556 100644 --- a/rpcs3/evdev_joystick_handler.cpp +++ b/rpcs3/evdev_joystick_handler.cpp @@ -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(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> evdev_joystick_handler::GetButtonV std::unordered_map> 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> 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(static_cast(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; diff --git a/rpcs3/evdev_joystick_handler.h b/rpcs3/evdev_joystick_handler.h index 55afce6863..4e554ba947 100644 --- a/rpcs3/evdev_joystick_handler.h +++ b/rpcs3/evdev_joystick_handler.h @@ -9,6 +9,73 @@ #include #include +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& map, int index); + positive_axis m_pos_axis_config; + std::vector m_positive_axis; std::vector blacklist; std::vector devices; int m_pad_index = -1; EvdevDevice m_dev; bool m_is_button_or_trigger; bool m_is_negative; + bool m_is_init = false; };