Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: Add stick multipliers to the pad dialog #8553

Merged
merged 5 commits into from Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions rpcs3/Emu/Io/PadHandler.cpp
Expand Up @@ -135,7 +135,7 @@ u16 PadHandlerBase::NormalizeTriggerInput(u16 value, int threshold)

// normalizes a directed input, meaning it will correspond to a single "button" and not an axis with two directions
// the input values must lie in 0+
u16 PadHandlerBase::NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum)
u16 PadHandlerBase::NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum) const
{
if (threshold >= maximum || maximum <= 0)
{
Expand All @@ -155,7 +155,7 @@ u16 PadHandlerBase::NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 max
}
}

u16 PadHandlerBase::NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold)
u16 PadHandlerBase::NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold) const
{
const s32 scaled_value = (multiplier * raw_value) / 100;

Expand Down Expand Up @@ -328,7 +328,11 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_

const auto status = update_connection(device);
if (status == connection::disconnected)
return fail_callback(pad_id);
{
if (fail_callback)
fail_callback(pad_id);
return;
}
else if (status == connection::no_data)
return;

Expand Down Expand Up @@ -373,10 +377,13 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_
const auto preview_values = get_preview_values(data);
const auto battery_level = get_battery_level(pad_id);

if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, pad_id, battery_level, preview_values);
else
return callback(0, "", pad_id, battery_level, preview_values);
if (callback)
{
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, pad_id, battery_level, preview_values);
else
return callback(0, "", pad_id, battery_level, preview_values);
}

return;
}
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Io/PadHandler.h
Expand Up @@ -99,9 +99,9 @@ class PadHandlerBase

// normalizes a directed input, meaning it will correspond to a single "button" and not an axis with two directions
// the input values must lie in 0+
u16 NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum);
u16 NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum) const;

u16 NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold = false);
u16 NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold = false) const;

// This function normalizes stick deadzone based on the DS3's deadzone, which is ~13%
// X and Y is expected to be in (-255) to 255 range, deadzone should be in terms of thumb stick range
Expand Down
23 changes: 17 additions & 6 deletions rpcs3/Input/evdev_joystick_handler.cpp
Expand Up @@ -281,7 +281,11 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
// Get our evdev device
auto device = get_evdev_device(padId);
if (!device || device->device == nullptr)
return fail_callback(padId);
{
if (fail_callback)
fail_callback(padId);
return;
}
libevdev* dev = device->device;

// Try to query the latest event from the joystick.
Expand Down Expand Up @@ -320,7 +324,11 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con

// return if nothing new has happened. ignore this to get the current state for blacklist
if (!get_blacklist && ret < 0)
return callback(0, "", padId, 0, preview_values);
{
if (callback)
callback(0, "", padId, 0, preview_values);
return;
}

std::pair<u16, std::string> pressed_button = { 0, "" };

Expand Down Expand Up @@ -401,10 +409,13 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
return;
}

if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
if (callback)
{
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
}
}

// https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
Expand Down
25 changes: 18 additions & 7 deletions rpcs3/Input/mm_joystick_handler.cpp
Expand Up @@ -182,7 +182,11 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
blacklist.clear();

if (!Init())
return fail_callback(padId);
{
if (fail_callback)
fail_callback(padId);
return;
}

static std::string cur_pad = "";
static int id = -1;
Expand All @@ -194,7 +198,9 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
if (id < 0)
{
input_log.error("MMJOY get_next_button_press for device [%s] failed with id = %d", padId, id);
return fail_callback(padId);
if (fail_callback)
fail_callback(padId);
return;
}
}

Expand All @@ -210,7 +216,9 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
{
case JOYERR_UNPLUGGED:
{
return fail_callback(padId);
if (fail_callback)
fail_callback(padId);
return;
}
case JOYERR_NOERROR:
{
Expand Down Expand Up @@ -309,10 +317,13 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
preview_values[5] = data[find_key(buttons[9])] - data[find_key(buttons[8])];
}

if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
if (callback)
{
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
}

break;
}
Expand Down