summaryrefslogtreecommitdiffstats
path: root/src/input_common/gcadapter
diff options
context:
space:
mode:
authorgerman <german@thesoftwareartisans.com>2020-09-02 01:17:59 +0200
committergerman <german@thesoftwareartisans.com>2020-09-18 23:51:16 +0200
commitc5e257017f6ffb888534af1ebbc34fffd7a35a2e (patch)
tree59063b1fce2ab10ca9cbf9c3e07869921068a74e /src/input_common/gcadapter
parentMerge pull request #4684 from lioncash/desig4 (diff)
downloadyuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar
yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar.gz
yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar.bz2
yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar.lz
yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar.xz
yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar.zst
yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.zip
Diffstat (limited to 'src/input_common/gcadapter')
-rw-r--r--src/input_common/gcadapter/gc_adapter.cpp88
-rw-r--r--src/input_common/gcadapter/gc_adapter.h5
2 files changed, 93 insertions, 0 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp
index c507c9891..89c148aba 100644
--- a/src/input_common/gcadapter/gc_adapter.cpp
+++ b/src/input_common/gcadapter/gc_adapter.cpp
@@ -15,7 +15,9 @@
#endif
#include "common/logging/log.h"
+#include "common/param_package.h"
#include "input_common/gcadapter/gc_adapter.h"
+#include "input_common/settings.h"
namespace GCAdapter {
@@ -292,6 +294,92 @@ void Adapter::Reset() {
}
}
+std::vector<Common::ParamPackage> Adapter::GetInputDevices() const {
+ std::vector<Common::ParamPackage> devices;
+ for (std::size_t port = 0; port < state.size(); ++port) {
+ if (!DeviceConnected(port)) {
+ continue;
+ }
+ std::string name = fmt::format("Gamecube Controller {}", port);
+ devices.emplace_back(Common::ParamPackage{
+ {"class", "gcpad"},
+ {"display", std::move(name)},
+ {"port", std::to_string(port)},
+ });
+ }
+ return devices;
+}
+
+InputCommon::ButtonMapping Adapter::GetButtonMappingForDevice(
+ const Common::ParamPackage& params) const {
+ // This list is missing ZL/ZR since those are not considered buttons.
+ // We will add those afterwards
+ // This list also excludes any button that can't be really mapped
+ static constexpr std::array<std::pair<Settings::NativeButton::Values, PadButton>, 12>
+ switch_to_gcadapter_button = {
+ std::pair{Settings::NativeButton::A, PadButton::PAD_BUTTON_A},
+ {Settings::NativeButton::B, PadButton::PAD_BUTTON_B},
+ {Settings::NativeButton::X, PadButton::PAD_BUTTON_X},
+ {Settings::NativeButton::Y, PadButton::PAD_BUTTON_Y},
+ {Settings::NativeButton::Plus, PadButton::PAD_BUTTON_START},
+ {Settings::NativeButton::DLeft, PadButton::PAD_BUTTON_LEFT},
+ {Settings::NativeButton::DUp, PadButton::PAD_BUTTON_UP},
+ {Settings::NativeButton::DRight, PadButton::PAD_BUTTON_RIGHT},
+ {Settings::NativeButton::DDown, PadButton::PAD_BUTTON_DOWN},
+ {Settings::NativeButton::SL, PadButton::PAD_TRIGGER_L},
+ {Settings::NativeButton::SR, PadButton::PAD_TRIGGER_R},
+ {Settings::NativeButton::R, PadButton::PAD_TRIGGER_Z},
+ };
+ if (!params.Has("port")) {
+ return {};
+ }
+
+ InputCommon::ButtonMapping mapping{};
+ for (const auto& [switch_button, gcadapter_button] : switch_to_gcadapter_button) {
+ Common::ParamPackage button_params({{"engine", "gcpad"}});
+ button_params.Set("port", params.Get("port", 0));
+ button_params.Set("button", static_cast<int>(gcadapter_button));
+ mapping.insert_or_assign(switch_button, std::move(button_params));
+ }
+
+ // Add the missing bindings for ZL/ZR
+ static constexpr std::array<std::pair<Settings::NativeButton::Values, PadAxes>, 2>
+ switch_to_gcadapter_axis = {
+ std::pair{Settings::NativeButton::ZL, PadAxes::TriggerLeft},
+ {Settings::NativeButton::ZR, PadAxes::TriggerRight},
+ };
+ for (const auto& [switch_button, gcadapter_axis] : switch_to_gcadapter_axis) {
+ Common::ParamPackage button_params({{"engine", "gcpad"}});
+ button_params.Set("port", params.Get("port", 0));
+ button_params.Set("button", static_cast<int>(PadButton::PAD_STICK));
+ button_params.Set("axis", static_cast<int>(gcadapter_axis));
+ mapping.insert_or_assign(switch_button, std::move(button_params));
+ }
+ return mapping;
+}
+
+InputCommon::AnalogMapping Adapter::GetAnalogMappingForDevice(
+ const Common::ParamPackage& params) const {
+ if (!params.Has("port")) {
+ return {};
+ }
+
+ InputCommon::AnalogMapping mapping = {};
+ Common::ParamPackage left_analog_params;
+ left_analog_params.Set("engine", "gcpad");
+ left_analog_params.Set("port", params.Get("port", 0));
+ left_analog_params.Set("axis_x", static_cast<int>(PadAxes::StickX));
+ left_analog_params.Set("axis_y", static_cast<int>(PadAxes::StickY));
+ mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params));
+ Common::ParamPackage right_analog_params;
+ right_analog_params.Set("engine", "gcpad");
+ right_analog_params.Set("port", params.Get("port", 0));
+ right_analog_params.Set("axis_x", static_cast<int>(PadAxes::SubstickX));
+ right_analog_params.Set("axis_y", static_cast<int>(PadAxes::SubstickY));
+ mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params));
+ return mapping;
+}
+
bool Adapter::DeviceConnected(std::size_t port) const {
return adapter_controllers_status[port] != ControllerTypes::None;
}
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h
index 20e97d283..75bf9fe74 100644
--- a/src/input_common/gcadapter/gc_adapter.h
+++ b/src/input_common/gcadapter/gc_adapter.h
@@ -10,6 +10,7 @@
#include <unordered_map>
#include "common/common_types.h"
#include "common/threadsafe_queue.h"
+#include "input_common/main.h"
struct libusb_context;
struct libusb_device;
@@ -75,6 +76,10 @@ public:
void BeginConfiguration();
void EndConfiguration();
+ std::vector<Common::ParamPackage> GetInputDevices() const;
+ InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const;
+ InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const;
+
/// Returns true if there is a device connected to port
bool DeviceConnected(std::size_t port) const;