input: add pressure intensity toggle mode

This commit is contained in:
Megamouse 2023-06-05 21:56:01 +02:00
parent 6f834e99d2
commit 8f66c50721
10 changed files with 59 additions and 17 deletions

View File

@ -655,13 +655,13 @@ void PadHandlerBase::get_mapping(const pad_ensemble& binding)
if (!device || !pad)
return;
auto cfg = device->config;
const auto cfg = device->config;
auto button_values = get_button_values(device);
// Find out if special buttons are pressed (introduced by RPCS3).
// These buttons will have a delay of one cycle, but whatever.
const bool adjust_pressure = pad->m_pressure_intensity_button_index >= 0 && pad->m_buttons[pad->m_pressure_intensity_button_index].m_pressed;
const bool adjust_pressure = pad->get_pressure_intensity_enabled(cfg->pressure_intensity_toggle_mode.get());
// Translate any corresponding keycodes to our normal DS3 buttons and triggers
for (auto& btn : pad->m_buttons)

View File

@ -58,6 +58,7 @@ struct cfg_pad final : cfg::node
cfg::string pressure_intensity_button{ this, "Pressure Intensity Button", "" };
cfg::uint<0, 100> pressure_intensity{ this, "Pressure Intensity Percent", 50 };
cfg::_bool pressure_intensity_toggle_mode{ this, "Pressure Intensity Toggle Mode", false };
cfg::uint<0, 200> lstickmultiplier{ this, "Left Stick Multiplier", 100 };
cfg::uint<0, 200> rstickmultiplier{ this, "Right Stick Multiplier", 100 };

View File

@ -131,3 +131,30 @@ u32 get_axis_keycode(u32 offset, u16 value)
default: return static_cast<u32>(axis_direction::both);
}
}
bool Pad::get_pressure_intensity_enabled(bool is_toggle_mode)
{
if (m_pressure_intensity_button_index < 0)
{
return false;
}
const Button& pressure_intensity_button = m_buttons[m_pressure_intensity_button_index];
if (is_toggle_mode)
{
const bool pressed = pressure_intensity_button.m_pressed;
if (std::exchange(m_pressure_intensity_button_pressed, pressed) != pressed)
{
if (pressed)
{
m_pressure_intensity_toggled = !m_pressure_intensity_toggled;
}
}
return m_pressure_intensity_toggled;
}
return pressure_intensity_button.m_pressed;
}

View File

@ -334,7 +334,10 @@ struct Pad
u16 m_product_id{0};
s32 m_pressure_intensity_button_index{-1}; // Special button index. -1 if not set.
bool m_pressure_intensity_button_pressed{}; // Last sensitivity button press state, used for toggle.
bool m_pressure_intensity_toggled{}; // Whether the sensitivity is toggled on or off.
u8 m_pressure_intensity{127}; // 0-255
bool get_pressure_intensity_enabled(bool is_toggle_mode);
// Cable State: 0 - 1 plugged in ?
u8 m_cable_state{0};

View File

@ -1011,11 +1011,15 @@ void evdev_joystick_handler::handle_input_event(const input_event& evt, const st
if (button_code == NO_BUTTON || value < 0)
return;
const auto cfg = m_dev->config;
if (!cfg)
return;
auto axis_orientations = m_dev->axis_orientations;
// Find out if special buttons are pressed (introduced by RPCS3).
// These buttons will have a delay of one cycle, but whatever.
const bool adjust_pressure = pad->m_pressure_intensity_button_index >= 0 && pad->m_buttons[pad->m_pressure_intensity_button_index].m_pressed;
const bool adjust_pressure = pad->get_pressure_intensity_enabled(cfg->pressure_intensity_toggle_mode.get());
// Translate any corresponding keycodes to our normal DS3 buttons and triggers
for (int i = 0; i < static_cast<int>(pad->m_buttons.size()); i++)
@ -1128,10 +1132,6 @@ void evdev_joystick_handler::handle_input_event(const input_event& evt, const st
m_dev->stick_val[idx] = m_dev->val_max[idx] - m_dev->val_min[idx];
}
const auto cfg = m_dev->config;
if (!cfg)
return;
u16 lx, ly, rx, ry;
// Normalize and apply pad squircling

View File

@ -81,8 +81,6 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value)
{
// Find out if special buttons are pressed (introduced by RPCS3).
// Activate the buttons here if possible since keys don't auto-repeat. This ensures that they are already pressed in the following loop.
bool adjust_pressure = false;
if (pad.m_pressure_intensity_button_index >= 0)
{
Button& pressure_intensity_button = pad.m_buttons[pad.m_pressure_intensity_button_index];
@ -92,10 +90,10 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value)
pressure_intensity_button.m_pressed = pressed;
pressure_intensity_button.m_value = value;
}
adjust_pressure = pressure_intensity_button.m_pressed;
}
const bool adjust_pressure = pad.get_pressure_intensity_enabled(m_pressure_intensity_toggle_mode);
// Handle buttons
for (Button& button : pad.m_buttons)
{
@ -795,7 +793,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_i
return false;
m_pad_configs[player_id].from_string(player_config->config.to_string());
cfg_pad* cfg = &m_pad_configs[player_id];
const cfg_pad* cfg = &m_pad_configs[player_id];
if (cfg == nullptr)
return false;
@ -812,6 +810,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_i
m_trigger_lerp_factor = cfg->trigger_lerp_factor / 100.0f;
m_l_stick_multiplier = cfg->lstickmultiplier;
m_r_stick_multiplier = cfg->rstickmultiplier;
m_pressure_intensity_toggle_mode = cfg->pressure_intensity_toggle_mode.get();
const auto find_key = [this](const cfg::string& name)
{

View File

@ -116,6 +116,7 @@ private:
steady_clock::time_point m_button_time;
f32 m_analog_lerp_factor = 1.0f;
f32 m_trigger_lerp_factor = 1.0f;
bool m_pressure_intensity_toggle_mode{};
// Stick Movements
steady_clock::time_point m_stick_time;

View File

@ -1076,9 +1076,9 @@ void pad_settings_dialog::UpdateLabels(bool is_reset)
}
}
ui->chb_vibration_large->setChecked(static_cast<bool>(cfg.enable_vibration_motor_large));
ui->chb_vibration_small->setChecked(static_cast<bool>(cfg.enable_vibration_motor_small));
ui->chb_vibration_switch->setChecked(static_cast<bool>(cfg.switch_vibration_motors));
ui->chb_vibration_large->setChecked(cfg.enable_vibration_motor_large.get());
ui->chb_vibration_small->setChecked(cfg.enable_vibration_motor_small.get());
ui->chb_vibration_switch->setChecked(cfg.switch_vibration_motors.get());
// Update Trigger Thresholds
ui->preview_trigger_left->setRange(0, m_handler->trigger_max);
@ -1160,6 +1160,9 @@ void pad_settings_dialog::UpdateLabels(bool is_reset)
ui->sb_pressure_intensity->setRange(std::stoi(range.front()), std::stoi(range.back()));
ui->sb_pressure_intensity->setValue(cfg.pressure_intensity);
// Update pressure sensitivity toggle mode
ui->cb_pressure_intensity_toggle_mode->setChecked(cfg.pressure_intensity_toggle_mode.get());
// Apply stored/default LED settings to the device
m_enable_led = m_handler->has_led();
SetPadData(0, 0);
@ -1778,6 +1781,7 @@ void pad_settings_dialog::ApplyCurrentPlayerConfig(int new_player_id)
if (m_handler->has_pressure_intensity_button())
{
cfg.pressure_intensity.set(ui->sb_pressure_intensity->value());
cfg.pressure_intensity_toggle_mode.set(ui->cb_pressure_intensity_toggle_mode->isChecked());
}
if (m_handler->m_type == pad_handler::keyboard)

View File

@ -674,7 +674,7 @@
<property name="title">
<string>Pressure Sensitivity Mode</string>
</property>
<layout class="QHBoxLayout" name="pressure_intensity_layout">
<layout class="QHBoxLayout" name="pressure_intensity_layout" stretch="2,1,1">
<property name="leftMargin">
<number>5</number>
</property>
@ -707,6 +707,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_pressure_intensity_toggle_mode">
<property name="text">
<string>Toggle</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -265,7 +265,7 @@ public:
const QString mmjoy = tr("The MMJoystick handler should work with almost any controller recognized by Windows. However, it is recommended that you use the more specific handlers if you have a controller that supports them.");
const QString sdl = tr("The SDL handler supports a variety of controllers across different platforms.");
const QString pressure_intensity = tr("Controls the intensity of pressure sensitive buttons while this special button is pressed.<br>Use the percentage to change how hard you want to press a button.");
const QString pressure_intensity = tr("Controls the intensity of pressure sensitive buttons while this special button is pressed.<br>Enable \"Toggle\" if you want to toggle the intensity on button press instead.<br>Use the percentage to change how hard you want to press a button.");
const QString squircle_factor = tr("The actual DualShock 3's stick range is not circular but formed like a rounded square (or squircle) which represents the maximum range of the emulated sticks. You can use the squircle values to modify the stick input if your sticks can't reach the corners of that range. A value of 0 does not apply any so called squircling. A value of 8000 is usually recommended.");
const QString stick_multiplier = tr("The stick multipliers can be used to change the sensitivity of your stick movements.<br>The default setting is 1 and represents normal input.");
const QString stick_deadzones = tr("A stick's deadzone determines how far the stick has to be moved until it is fully recognized by the game. The resulting range will be projected onto the full input range in order to give you a smooth experience. Movement inside the deadzone is actually simulated as a real DualShock 3's deadzone of ~13%, so don't worry if there is still movement shown in the emulated stick preview.");