1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

input: fix pressure sensitivity button

This commit is contained in:
Megamouse 2021-08-08 16:45:45 +02:00
parent 430fd759fe
commit 2b18813115
14 changed files with 78 additions and 57 deletions

View File

@ -474,7 +474,7 @@ bool PadHandlerBase::bindPadToDevice(std::shared_ptr<Pad> pad, const std::string
u32 pclass_profile = 0x0;
for (const auto product : input::get_products_by_class(profile->device_class_type))
for (const auto& product : input::get_products_by_class(profile->device_class_type))
{
if (product.vendor_id == profile->vendor_id && product.product_id == profile->product_id)
{

View File

@ -49,6 +49,7 @@ ds3_pad_handler::ds3_pad_handler()
{
button_list =
{
{ DS3KeyCodes::None, "" },
{ DS3KeyCodes::Triangle, "Triangle" },
{ DS3KeyCodes::Circle, "Circle" },
{ DS3KeyCodes::Cross, "Cross" },
@ -229,7 +230,7 @@ void ds3_pad_handler::init_config(pad_config* cfg, const std::string& name)
cfg->l2.def = button_list.at(DS3KeyCodes::L2);
cfg->l3.def = button_list.at(DS3KeyCodes::L3);
cfg->pressure_intensity_button.def = "";
cfg->pressure_intensity_button.def = button_list.at(DS3KeyCodes::None);
// Set default misc variables
cfg->lstickdeadzone.def = 40; // between 0 and 255

View File

@ -16,7 +16,9 @@ class ds3_pad_handler final : public hid_pad_handler<ds3_device>
{
enum DS3KeyCodes
{
Triangle = 0,
None = 0,
Triangle,
Circle,
Cross,
Square,
@ -42,9 +44,7 @@ class ds3_pad_handler final : public hid_pad_handler<ds3_device>
RSXNeg,
RSXPos,
RSYNeg,
RSYPos,
KeyCodeCount
RSYPos
};
enum HidRequest

View File

@ -76,6 +76,7 @@ ds4_pad_handler::ds4_pad_handler()
// Unique names for the config files and our pad settings dialog
button_list =
{
{ DS4KeyCodes::None, "" },
{ DS4KeyCodes::Triangle, "Triangle" },
{ DS4KeyCodes::Circle, "Circle" },
{ DS4KeyCodes::Cross, "Cross" },
@ -162,7 +163,7 @@ void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name)
cfg->l2.def = button_list.at(DS4KeyCodes::L2);
cfg->l3.def = button_list.at(DS4KeyCodes::L3);
cfg->pressure_intensity_button.def = "";
cfg->pressure_intensity_button.def = button_list.at(DS4KeyCodes::None);
// Set default misc variables
cfg->lstickdeadzone.def = 40; // between 0 and 255

View File

@ -18,7 +18,9 @@ class ds4_pad_handler final : public hid_pad_handler<DS4Device>
// The touchpad is restricted to its button for now (or forever?)
enum DS4KeyCodes
{
Triangle = 0,
None = 0,
Triangle,
Circle,
Cross,
Square,
@ -47,9 +49,7 @@ class ds4_pad_handler final : public hid_pad_handler<DS4Device>
RSXNeg,
RSXPos,
RSYNeg,
RSYPos,
KeyCodeCount
RSYPos
};
public:

View File

@ -95,6 +95,7 @@ dualsense_pad_handler::dualsense_pad_handler()
// Unique names for the config files and our pad settings dialog
button_list =
{
{ DualSenseKeyCodes::None, "" },
{ DualSenseKeyCodes::Triangle, "Triangle" },
{ DualSenseKeyCodes::Circle, "Circle" },
{ DualSenseKeyCodes::Cross, "Cross" },
@ -273,7 +274,7 @@ void dualsense_pad_handler::init_config(pad_config* cfg, const std::string& name
cfg->l2.def = button_list.at(DualSenseKeyCodes::L2);
cfg->l3.def = button_list.at(DualSenseKeyCodes::L3);
cfg->pressure_intensity_button.def = "";
cfg->pressure_intensity_button.def = button_list.at(DualSenseKeyCodes::None);
// Set default misc variables
cfg->lstickdeadzone.def = 40; // between 0 and 255

View File

@ -32,7 +32,9 @@ class dualsense_pad_handler final : public hid_pad_handler<DualSenseDevice>
{
enum DualSenseKeyCodes
{
Triangle = 0,
None = 0,
Triangle,
Circle,
Cross,
Square,
@ -60,9 +62,7 @@ class dualsense_pad_handler final : public hid_pad_handler<DualSenseDevice>
RSXNeg,
RSXPos,
RSYNeg,
RSYPos,
KeyCodeCount
RSYPos
};
public:

View File

@ -81,7 +81,7 @@ void evdev_joystick_handler::init_config(pad_config* cfg, const std::string& nam
cfg->l2.def = axis_list.at(ABS_Z);
cfg->l3.def = button_list.at(BTN_THUMBL);
cfg->pressure_intensity_button.def = "";
cfg->pressure_intensity_button.def = button_list.at(NO_BUTTON);
// Set default misc variables
cfg->lstickdeadzone.def = 30; // between 0 and 255
@ -225,7 +225,11 @@ std::unordered_map<u64, std::pair<u16, bool>> evdev_joystick_handler::GetButtonV
for (const auto& entry : button_list)
{
const auto code = entry.first;
int val = 0;
if (code == NO_BUTTON)
continue;
int val = 0;
if (libevdev_fetch_event_value(dev, EV_KEY, code, &val) == 0)
continue;
@ -340,6 +344,8 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
for (const auto& [code, name] : button_list)
{
// Handle annoying useless buttons
if (code == NO_BUTTON)
continue;
if (padId.find("Xbox 360") != umax && code >= BTN_TRIGGER_HAPPY)
continue;
if (padId.find("Sony") != umax && (code == BTN_TL2 || code == BTN_TR2))
@ -522,9 +528,9 @@ void evdev_joystick_handler::SetPadData(const std::string& padId, u32 largeMotor
SetRumble(static_cast<EvdevDevice*>(dev.get()), largeMotor, smallMotor);
}
int evdev_joystick_handler::GetButtonInfo(const input_event& evt, const std::shared_ptr<EvdevDevice>& device, int& value)
u32 evdev_joystick_handler::GetButtonInfo(const input_event& evt, const std::shared_ptr<EvdevDevice>& device, int& value)
{
const int code = evt.code;
const u32 code = evt.code;
const int val = evt.value;
m_is_button_or_trigger = false;
@ -744,8 +750,8 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr<PadDevice>& devic
m_dev->cur_type = evt.type;
int value;
const int button_code = GetButtonInfo(evt, m_dev, value);
if (button_code < 0 || value < 0)
const u32 button_code = GetButtonInfo(evt, m_dev, value);
if (button_code == NO_BUTTON || value < 0)
return;
auto axis_orientations = m_dev->axis_orientations;
@ -753,7 +759,9 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr<PadDevice>& devic
// Translate any corresponding keycodes to our normal DS3 buttons and triggers
for (int i = 0; i < static_cast<int>(pad->m_buttons.size()); i++)
{
if (pad->m_buttons[i].m_keyCode != button_code + 0u)
auto& button = pad->m_buttons[i];
if (button.m_keyCode != button_code)
continue;
// Be careful to handle mapped axis specially
@ -771,14 +779,14 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr<PadDevice>& devic
}
else if (direction != (m_is_negative ? 1 : 0))
{
pad->m_buttons[i].m_value = 0;
pad->m_buttons[i].m_pressed = 0;
button.m_value = 0;
button.m_pressed = 0;
continue;
}
}
pad->m_buttons[i].m_value = static_cast<u16>(value);
TranslateButtonPress(m_dev, button_code, pad->m_buttons[i].m_pressed, pad->m_buttons[i].m_value);
button.m_value = static_cast<u16>(value);
TranslateButtonPress(m_dev, button_code, button.m_pressed, button.m_value);
}
// Translate any corresponding keycodes to our two sticks. (ignoring thresholds for now)
@ -788,7 +796,7 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr<PadDevice>& devic
bool pressed_max = false;
// m_keyCodeMin is the mapped key for left or down
if (pad->m_sticks[idx].m_keyCodeMin == button_code + 0u)
if (pad->m_sticks[idx].m_keyCodeMin == button_code)
{
bool is_direction_min = false;
@ -814,7 +822,7 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr<PadDevice>& devic
}
// m_keyCodeMax is the mapped key for right or up
if (pad->m_sticks[idx].m_keyCodeMax == button_code + 0u)
if (pad->m_sticks[idx].m_keyCodeMax == button_code)
{
bool is_direction_max = false;

View File

@ -80,9 +80,12 @@ struct positive_axis : cfg::node
class evdev_joystick_handler final : public PadHandlerBase
{
static constexpr u32 NO_BUTTON = u32{umax}; // Some event code that doesn't exist in evdev (code type is U16)
// Unique button names for the config files and our pad settings dialog
const std::unordered_map<u32, std::string> button_list =
{
{ NO_BUTTON , "" },
// Xbox One S Controller returns some buttons as key when connected through bluetooth
{ KEY_BACK , "Back Key" },
{ KEY_HOMEPAGE , "Homepage Key"},
@ -372,7 +375,7 @@ private:
bool update_device(const std::shared_ptr<PadDevice>& device);
void update_devs();
int add_device(const std::string& device, const std::shared_ptr<Pad>& pad, bool in_settings = false);
int GetButtonInfo(const input_event& evt, const std::shared_ptr<EvdevDevice>& device, int& button_code);
u32 GetButtonInfo(const input_event& evt, const std::shared_ptr<EvdevDevice>& device, int& button_code);
std::unordered_map<u64, std::pair<u16, bool>> GetButtonValues(const std::shared_ptr<EvdevDevice>& device);
void SetRumble(EvdevDevice* device, u16 large, u16 small);

View File

@ -65,7 +65,7 @@ void keyboard_pad_handler::init_config(pad_config* cfg, const std::string& name)
cfg->l2.def = GetKeyName(Qt::Key_R);
cfg->l3.def = GetKeyName(Qt::Key_F);
cfg->pressure_intensity_button.def = "";
cfg->pressure_intensity_button.def = GetKeyName(Qt::NoButton);
// apply defaults
cfg->from_default();

View File

@ -60,7 +60,7 @@ void mm_joystick_handler::init_config(pad_config* cfg, const std::string& name)
cfg->l2.def = button_list.at(JOY_BUTTON5);
cfg->l3.def = button_list.at(JOY_BUTTON11);
cfg->pressure_intensity_button.def = "";
cfg->pressure_intensity_button.def = button_list.at(NO_BUTTON);
// Set default misc variables
cfg->lstickdeadzone.def = 0; // between 0 and 255
@ -119,6 +119,16 @@ std::vector<std::string> mm_joystick_handler::ListDevices()
return devices;
}
u64 mm_joystick_handler::find_key(const std::string& name) const
{
long key = FindKeyCodeByString(axis_list, name, false);
if (key < 0)
key = FindKeyCodeByString(pov_list, name, false);
if (key < 0)
key = FindKeyCodeByString(button_list, name);
return static_cast<u64>(key);
}
std::array<u32, PadHandlerBase::button::button_count> mm_joystick_handler::get_mapped_key_codes(const std::shared_ptr<PadDevice>& device, const pad_config* profile)
{
std::array<u32, button::button_count> mapping{ 0 };
@ -127,16 +137,6 @@ std::array<u32, PadHandlerBase::button::button_count> mm_joystick_handler::get_m
if (!joy_device)
return mapping;
auto find_key = [this](const cfg::string& name)
{
long key = FindKeyCode(button_list, name, false);
if (key < 0)
key = FindKeyCode(pov_list, name, false);
if (key < 0)
key = FindKeyCode(axis_list, name);
return static_cast<u64>(key);
};
joy_device->trigger_left = find_key(profile->l2);
joy_device->trigger_right = find_key(profile->r2);
joy_device->axis_left[0] = find_key(profile->ls_left);
@ -174,6 +174,8 @@ std::array<u32, PadHandlerBase::button::button_count> mm_joystick_handler::get_m
mapping[button::rs_down] = static_cast<u32>(joy_device->axis_right[2]);
mapping[button::rs_up] = static_cast<u32>(joy_device->axis_right[3]);
mapping[button::pressure_intensity_button] = static_cast<u32>(find_key(profile->pressure_intensity_button));
return mapping;
}
@ -272,12 +274,16 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
for (const auto& button : button_list)
{
u64 keycode = button.first;
u16 value = data[keycode];
const u64 keycode = button.first;
if (keycode == NO_BUTTON)
continue;
if (!get_blacklist && std::find(blacklist.begin(), blacklist.end(), keycode) != blacklist.end())
continue;
const u16 value = data[keycode];
if (value > 0)
{
if (get_blacklist)
@ -297,16 +303,6 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
return;
}
auto find_key = [this](const std::string& name)
{
long key = FindKeyCodeByString(axis_list, name, false);
if (key < 0)
key = FindKeyCodeByString(pov_list, name, false);
if (key < 0)
key = FindKeyCodeByString(button_list, name);
return static_cast<u64>(key);
};
pad_preview_values preview_values = { 0, 0, 0, 0, 0, 0 };
if (buttons.size() == 10)
{
@ -339,6 +335,9 @@ std::unordered_map<u64, u16> mm_joystick_handler::GetButtonValues(const JOYINFOE
for (const auto& entry : button_list)
{
if (entry.first == NO_BUTTON)
continue;
button_values.emplace(entry.first, js_info.dwButtons & entry.first ? 255 : 0);
}

View File

@ -16,9 +16,12 @@
class mm_joystick_handler final : public PadHandlerBase
{
static constexpr u64 NO_BUTTON = 0;
// Unique names for the config files and our pad settings dialog
const std::unordered_map<u64, std::string> button_list =
{
{ NO_BUTTON , "" },
{ JOY_BUTTON1 , "Button 1" },
{ JOY_BUTTON2 , "Button 2" },
{ JOY_BUTTON3 , "Button 3" },
@ -128,6 +131,8 @@ private:
std::shared_ptr<MMJOYDevice> m_dev;
std::unordered_map<int, MMJOYDevice> m_devices;
u64 find_key(const std::string& name) const;
std::array<u32, PadHandlerBase::button::button_count> get_mapped_key_codes(const std::shared_ptr<PadDevice>& device, const pad_config* profile) override;
std::shared_ptr<PadDevice> get_device(const std::string& device) override;
bool get_is_left_trigger(u64 keyCode) override;

View File

@ -19,6 +19,7 @@ xinput_pad_handler::xinput_pad_handler() : PadHandlerBase(pad_handler::xinput)
// Unique names for the config files and our pad settings dialog
button_list =
{
{ XInputKeyCodes::None, "" },
{ XInputKeyCodes::A, "A" },
{ XInputKeyCodes::B, "B" },
{ XInputKeyCodes::X, "X" },
@ -116,6 +117,8 @@ void xinput_pad_handler::init_config(pad_config* cfg, const std::string& name)
cfg->l2.def = button_list.at(XInputKeyCodes::LT);
cfg->l3.def = button_list.at(XInputKeyCodes::LS);
cfg->pressure_intensity_button.def = button_list.at(XInputKeyCodes::None);
// Set default misc variables
cfg->lstickdeadzone.def = XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE; // between 0 and 32767
cfg->rstickdeadzone.def = XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE; // between 0 and 32767

View File

@ -57,6 +57,8 @@ class xinput_pad_handler final : public PadHandlerBase
// These are all the possible buttons on a standard xbox 360 or xbox one controller
enum XInputKeyCodes
{
None = 0,
A,
B,
X,
@ -83,9 +85,7 @@ class xinput_pad_handler final : public PadHandlerBase
RSXNeg,
RSXPos,
RSYNeg,
RSYPos,
KeyCodeCount
RSYPos
};
using PadButtonValues = std::unordered_map<u64, u16>;