Skip to content

Commit

Permalink
Input: fix MMJOY axis identification
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Oct 15, 2022
1 parent ddef371 commit 066e9a8
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 105 deletions.
53 changes: 32 additions & 21 deletions rpcs3/Emu/Io/PadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void PadHandlerBase::init_configs()
}
}

void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_callback& callback, const pad_fail_callback& fail_callback, bool get_blacklist, const std::vector<std::string>& /*buttons*/)
void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_callback& callback, const pad_fail_callback& fail_callback, bool get_blacklist, const std::vector<std::string>& buttons)
{
if (get_blacklist)
blacklist.clear();
Expand Down Expand Up @@ -357,8 +357,8 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_
if (!get_blacklist && std::find(blacklist.begin(), blacklist.end(), keycode) != blacklist.end())
continue;

const bool is_trigger = get_is_left_trigger(keycode) || get_is_right_trigger(keycode);
const bool is_stick = !is_trigger && (get_is_left_stick(keycode) || get_is_right_stick(keycode));
const bool is_trigger = get_is_left_trigger(device, keycode) || get_is_right_trigger(device, keycode);
const bool is_stick = !is_trigger && (get_is_left_stick(device, keycode) || get_is_right_stick(device, keycode));
const bool is_button = !is_trigger && !is_stick;

if ((is_trigger && (value > m_trigger_threshold)) || (is_stick && (value > m_thumb_threshold)) || (is_button && (value > 0)))
Expand All @@ -382,8 +382,8 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_
return;
}

const auto preview_values = get_preview_values(data);
const auto battery_level = get_battery_level(pad_id);
const pad_preview_values preview_values = get_preview_values(data);
const u32 battery_level = get_battery_level(pad_id);

if (callback)
{
Expand Down Expand Up @@ -451,22 +451,22 @@ void PadHandlerBase::TranslateButtonPress(const std::shared_ptr<PadDevice>& devi
return;
}

if (get_is_left_trigger(keyCode))
if (get_is_left_trigger(device, keyCode))
{
pressed = val > (ignore_trigger_threshold ? 0 : device->config->ltriggerthreshold);
val = pressed ? NormalizeTriggerInput(val, device->config->ltriggerthreshold) : 0;
}
else if (get_is_right_trigger(keyCode))
else if (get_is_right_trigger(device, keyCode))
{
pressed = val > (ignore_trigger_threshold ? 0 : device->config->rtriggerthreshold);
val = pressed ? NormalizeTriggerInput(val, device->config->rtriggerthreshold) : 0;
}
else if (get_is_left_stick(keyCode))
else if (get_is_left_stick(device, keyCode))
{
pressed = val > (ignore_stick_threshold ? 0 : device->config->lstickdeadzone);
val = pressed ? NormalizeStickInput(val, device->config->lstickdeadzone, device->config->lstickmultiplier, ignore_stick_threshold) : 0;
}
else if (get_is_right_stick(keyCode))
else if (get_is_right_stick(device, keyCode))
{
pressed = val > (ignore_stick_threshold ? 0 : device->config->rstickdeadzone);
val = pressed ? NormalizeStickInput(val, device->config->rstickdeadzone, device->config->rstickmultiplier, ignore_stick_threshold) : 0;
Expand Down Expand Up @@ -571,12 +571,23 @@ bool PadHandlerBase::bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id)
return true;
}

std::array<u32, PadHandlerBase::button::button_count> PadHandlerBase::get_mapped_key_codes(const std::shared_ptr<PadDevice>& /*device*/, const cfg_pad* cfg)
std::array<u32, PadHandlerBase::button::button_count> PadHandlerBase::get_mapped_key_codes(const std::shared_ptr<PadDevice>& device, const cfg_pad* cfg)
{
std::array<u32, button::button_count> mapping{};
if (!cfg)
if (!device || !cfg)
return mapping;

device->trigger_code_left = FindKeyCode(button_list, cfg->l2);
device->trigger_code_right = FindKeyCode(button_list, cfg->r2);
device->axis_code_left[0] = FindKeyCode(button_list, cfg->ls_left);
device->axis_code_left[1] = FindKeyCode(button_list, cfg->ls_right);
device->axis_code_left[2] = FindKeyCode(button_list, cfg->ls_down);
device->axis_code_left[3] = FindKeyCode(button_list, cfg->ls_up);
device->axis_code_right[0] = FindKeyCode(button_list, cfg->rs_left);
device->axis_code_right[1] = FindKeyCode(button_list, cfg->rs_right);
device->axis_code_right[2] = FindKeyCode(button_list, cfg->rs_down);
device->axis_code_right[3] = FindKeyCode(button_list, cfg->rs_up);

mapping[button::up] = FindKeyCode(button_list, cfg->up);
mapping[button::down] = FindKeyCode(button_list, cfg->down);
mapping[button::left] = FindKeyCode(button_list, cfg->left);
Expand All @@ -588,19 +599,19 @@ std::array<u32, PadHandlerBase::button::button_count> PadHandlerBase::get_mapped
mapping[button::start] = FindKeyCode(button_list, cfg->start);
mapping[button::select] = FindKeyCode(button_list, cfg->select);
mapping[button::l1] = FindKeyCode(button_list, cfg->l1);
mapping[button::l2] = FindKeyCode(button_list, cfg->l2);
mapping[button::l2] = ::narrow<u32>(device->trigger_code_left);
mapping[button::l3] = FindKeyCode(button_list, cfg->l3);
mapping[button::r1] = FindKeyCode(button_list, cfg->r1);
mapping[button::r2] = FindKeyCode(button_list, cfg->r2);
mapping[button::r2] = ::narrow<u32>(device->trigger_code_right);
mapping[button::r3] = FindKeyCode(button_list, cfg->r3);
mapping[button::ls_left] = FindKeyCode(button_list, cfg->ls_left);
mapping[button::ls_right] = FindKeyCode(button_list, cfg->ls_right);
mapping[button::ls_down] = FindKeyCode(button_list, cfg->ls_down);
mapping[button::ls_up] = FindKeyCode(button_list, cfg->ls_up);
mapping[button::rs_left] = FindKeyCode(button_list, cfg->rs_left);
mapping[button::rs_right] = FindKeyCode(button_list, cfg->rs_right);
mapping[button::rs_down] = FindKeyCode(button_list, cfg->rs_down);
mapping[button::rs_up] = FindKeyCode(button_list, cfg->rs_up);
mapping[button::ls_left] = ::narrow<u32>(device->axis_code_left[0]);
mapping[button::ls_right] = ::narrow<u32>(device->axis_code_left[1]);
mapping[button::ls_down] = ::narrow<u32>(device->axis_code_left[2]);
mapping[button::ls_up] = ::narrow<u32>(device->axis_code_left[3]);
mapping[button::rs_left] = ::narrow<u32>(device->axis_code_right[0]);
mapping[button::rs_right] = ::narrow<u32>(device->axis_code_right[1]);
mapping[button::rs_down] = ::narrow<u32>(device->axis_code_right[2]);
mapping[button::rs_up] = ::narrow<u32>(device->axis_code_right[3]);
mapping[button::ps] = FindKeyCode(button_list, cfg->ps);

mapping[button::pressure_intensity_button] = FindKeyCode(button_list, cfg->pressure_intensity_button);
Expand Down
12 changes: 8 additions & 4 deletions rpcs3/Emu/Io/PadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class PadDevice
virtual ~PadDevice() = default;
cfg_pad* config{ nullptr };
u8 player_id{0};
u64 trigger_code_left = 0;
u64 trigger_code_right = 0;
std::array<u64, 4> axis_code_left{};
std::array<u64, 4> axis_code_right{};
};

struct pad_ensemble
Expand Down Expand Up @@ -206,10 +210,10 @@ class PadHandlerBase

private:
virtual std::shared_ptr<PadDevice> get_device(const std::string& /*device*/) { return nullptr; }
virtual bool get_is_left_trigger(u64 /*keyCode*/) { return false; }
virtual bool get_is_right_trigger(u64 /*keyCode*/) { return false; }
virtual bool get_is_left_stick(u64 /*keyCode*/) { return false; }
virtual bool get_is_right_stick(u64 /*keyCode*/) { return false; }
virtual bool get_is_left_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; }
virtual bool get_is_right_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; }
virtual bool get_is_left_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; }
virtual bool get_is_right_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; }
virtual PadHandlerBase::connection update_connection(const std::shared_ptr<PadDevice>& /*device*/) { return connection::disconnected; }
virtual void get_extended_info(const pad_ensemble& /*binding*/) {}
virtual void apply_pad_data(const pad_ensemble& /*binding*/) {}
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/ds3_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,17 @@ void ds3_pad_handler::get_extended_info(const pad_ensemble& binding)
//pad->m_sensors[3].m_value = polish_value(pad->m_sensors[3].m_value, 1, 1, 512, 512, 0, 1023);
}

bool ds3_pad_handler::get_is_left_trigger(u64 keyCode)
bool ds3_pad_handler::get_is_left_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return keyCode == DS3KeyCodes::L2;
}

bool ds3_pad_handler::get_is_right_trigger(u64 keyCode)
bool ds3_pad_handler::get_is_right_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return keyCode == DS3KeyCodes::R2;
}

bool ds3_pad_handler::get_is_left_stick(u64 keyCode)
bool ds3_pad_handler::get_is_left_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
switch (keyCode)
{
Expand All @@ -516,7 +516,7 @@ bool ds3_pad_handler::get_is_left_stick(u64 keyCode)
}
}

bool ds3_pad_handler::get_is_right_stick(u64 keyCode)
bool ds3_pad_handler::get_is_right_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
switch (keyCode)
{
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/ds3_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class ds3_pad_handler final : public hid_pad_handler<ds3_device>
int send_output_report(ds3_device* ds3dev) override;
void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view serial) override;

bool get_is_left_trigger(u64 keyCode) override;
bool get_is_right_trigger(u64 keyCode) override;
bool get_is_left_stick(u64 keyCode) override;
bool get_is_right_stick(u64 keyCode) override;
bool get_is_left_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_left_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
PadHandlerBase::connection update_connection(const std::shared_ptr<PadDevice>& device) override;
void get_extended_info(const pad_ensemble& binding) override;
void apply_pad_data(const pad_ensemble& binding) override;
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/ds4_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,17 +755,17 @@ ds4_pad_handler::DataStatus ds4_pad_handler::get_data(DS4Device* device)
return DataStatus::NewData;
}

bool ds4_pad_handler::get_is_left_trigger(u64 keyCode)
bool ds4_pad_handler::get_is_left_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return keyCode == DS4KeyCodes::L2;
}

bool ds4_pad_handler::get_is_right_trigger(u64 keyCode)
bool ds4_pad_handler::get_is_right_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return keyCode == DS4KeyCodes::R2;
}

bool ds4_pad_handler::get_is_left_stick(u64 keyCode)
bool ds4_pad_handler::get_is_left_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
switch (keyCode)
{
Expand All @@ -779,7 +779,7 @@ bool ds4_pad_handler::get_is_left_stick(u64 keyCode)
}
}

bool ds4_pad_handler::get_is_right_stick(u64 keyCode)
bool ds4_pad_handler::get_is_right_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
switch (keyCode)
{
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/ds4_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class ds4_pad_handler final : public hid_pad_handler<DS4Device>
int send_output_report(DS4Device* device) override;
void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view serial) override;

bool get_is_left_trigger(u64 keyCode) override;
bool get_is_right_trigger(u64 keyCode) override;
bool get_is_left_stick(u64 keyCode) override;
bool get_is_right_stick(u64 keyCode) override;
bool get_is_left_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_left_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
PadHandlerBase::connection update_connection(const std::shared_ptr<PadDevice>& device) override;
void get_extended_info(const pad_ensemble& binding) override;
void apply_pad_data(const pad_ensemble& binding) override;
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/dualsense_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,17 @@ bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_devi
return true;
}

bool dualsense_pad_handler::get_is_left_trigger(u64 keyCode)
bool dualsense_pad_handler::get_is_left_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return keyCode == DualSenseKeyCodes::L2;
}

bool dualsense_pad_handler::get_is_right_trigger(u64 keyCode)
bool dualsense_pad_handler::get_is_right_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return keyCode == DualSenseKeyCodes::R2;
}

bool dualsense_pad_handler::get_is_left_stick(u64 keyCode)
bool dualsense_pad_handler::get_is_left_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
switch (keyCode)
{
Expand All @@ -573,7 +573,7 @@ bool dualsense_pad_handler::get_is_left_stick(u64 keyCode)
}
}

bool dualsense_pad_handler::get_is_right_stick(u64 keyCode)
bool dualsense_pad_handler::get_is_right_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
switch (keyCode)
{
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/dualsense_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class dualsense_pad_handler final : public hid_pad_handler<DualSenseDevice>
void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view wide_serial) override;
int send_output_report(DualSenseDevice* device) override;

bool get_is_left_trigger(u64 keyCode) override;
bool get_is_right_trigger(u64 keyCode) override;
bool get_is_left_stick(u64 keyCode) override;
bool get_is_right_stick(u64 keyCode) override;
bool get_is_left_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_left_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
PadHandlerBase::connection update_connection(const std::shared_ptr<PadDevice>& device) override;
std::unordered_map<u64, u16> get_button_values(const std::shared_ptr<PadDevice>& device) override;
pad_preview_values get_preview_values(const std::unordered_map<u64, u16>& data) override;
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/evdev_joystick_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,22 +1349,22 @@ bool evdev_joystick_handler::check_buttons(const std::array<EvdevButton, 4>& b,
return std::any_of(b.begin(), b.end(), [this, code](const EvdevButton& b) { return check_button(b, code); });
};

bool evdev_joystick_handler::get_is_left_trigger(u64 keyCode)
bool evdev_joystick_handler::get_is_left_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return check_button(m_dev->trigger_left, static_cast<u32>(keyCode));
}

bool evdev_joystick_handler::get_is_right_trigger(u64 keyCode)
bool evdev_joystick_handler::get_is_right_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return check_button(m_dev->trigger_right, static_cast<u32>(keyCode));
}

bool evdev_joystick_handler::get_is_left_stick(u64 keyCode)
bool evdev_joystick_handler::get_is_left_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return check_buttons(m_dev->axis_left, static_cast<u32>(keyCode));
}

bool evdev_joystick_handler::get_is_right_stick(u64 keyCode)
bool evdev_joystick_handler::get_is_right_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 keyCode)
{
return check_buttons(m_dev->axis_right, static_cast<u32>(keyCode));
}
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/evdev_joystick_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ class evdev_joystick_handler final : public PadHandlerBase
void get_mapping(const pad_ensemble& binding) override;
void get_extended_info(const pad_ensemble& binding) override;
void apply_pad_data(const pad_ensemble& binding) override;
bool get_is_left_trigger(u64 keyCode) override;
bool get_is_right_trigger(u64 keyCode) override;
bool get_is_left_stick(u64 keyCode) override;
bool get_is_right_stick(u64 keyCode) override;
bool get_is_left_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_left_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
};

#endif

0 comments on commit 066e9a8

Please sign in to comment.