summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/drivers/gc_adapter.cpp75
-rw-r--r--src/input_common/drivers/gc_adapter.h6
-rw-r--r--src/input_common/drivers/keyboard.cpp2
-rw-r--r--src/input_common/drivers/sdl_driver.cpp22
-rw-r--r--src/input_common/drivers/tas_input.cpp2
5 files changed, 84 insertions, 23 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 4a56abb99..4fb6ab5af 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -150,7 +150,10 @@ void GCAdapter::UpdatePadType(std::size_t port, ControllerTypes pad_type) {
return;
}
// Device changed reset device and set new type
- pads[port] = {};
+ pads[port].axis_origin = {};
+ pads[port].reset_origin_counter = {};
+ pads[port].enable_vibration = {};
+ pads[port].rumble_amplitude = {};
pads[port].type = pad_type;
}
@@ -396,12 +399,11 @@ std::vector<Common::ParamPackage> GCAdapter::GetInputDevices() const {
if (!DeviceConnected(port)) {
continue;
}
- const std::string name = fmt::format("Gamecube Controller {}", port + 1);
- devices.emplace_back(Common::ParamPackage{
- {"engine", "gcpad"},
- {"display", std::move(name)},
- {"port", std::to_string(port)},
- });
+ Common::ParamPackage identifier{};
+ identifier.Set("engine", GetEngineName());
+ identifier.Set("display", fmt::format("Gamecube Controller {}", port + 1));
+ identifier.Set("port", static_cast<int>(port));
+ devices.emplace_back(identifier);
}
return devices;
}
@@ -431,7 +433,8 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p
ButtonMapping mapping{};
for (const auto& [switch_button, gcadapter_button] : switch_to_gcadapter_button) {
- Common::ParamPackage button_params({{"engine", "gcpad"}});
+ Common::ParamPackage button_params{};
+ button_params.Set("engine", GetEngineName());
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));
@@ -444,7 +447,8 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p
{Settings::NativeButton::ZR, PadButton::TriggerR, PadAxes::TriggerRight},
};
for (const auto& [switch_button, gcadapter_buton, gcadapter_axis] : switch_to_gcadapter_axis) {
- Common::ParamPackage button_params({{"engine", "gcpad"}});
+ Common::ParamPackage button_params{};
+ button_params.Set("engine", GetEngineName());
button_params.Set("port", params.Get("port", 0));
button_params.Set("button", static_cast<s32>(gcadapter_buton));
button_params.Set("axis", static_cast<s32>(gcadapter_axis));
@@ -463,13 +467,13 @@ AnalogMapping GCAdapter::GetAnalogMappingForDevice(const Common::ParamPackage& p
AnalogMapping mapping = {};
Common::ParamPackage left_analog_params;
- left_analog_params.Set("engine", "gcpad");
+ left_analog_params.Set("engine", GetEngineName());
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("engine", GetEngineName());
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));
@@ -477,9 +481,56 @@ AnalogMapping GCAdapter::GetAnalogMappingForDevice(const Common::ParamPackage& p
return mapping;
}
+std::string GCAdapter::GetUIButtonName(const Common::ParamPackage& params) const {
+ PadButton button = static_cast<PadButton>(params.Get("button", 0));
+ switch (button) {
+ case PadButton::ButtonLeft:
+ return "left";
+ break;
+ case PadButton::ButtonRight:
+ return "right";
+ break;
+ case PadButton::ButtonDown:
+ return "down";
+ break;
+ case PadButton::ButtonUp:
+ return "up";
+ break;
+ case PadButton::TriggerZ:
+ return "Z";
+ break;
+ case PadButton::TriggerR:
+ return "R";
+ break;
+ case PadButton::TriggerL:
+ return "L";
+ break;
+ case PadButton::ButtonA:
+ return "A";
+ break;
+ case PadButton::ButtonB:
+ return "B";
+ break;
+ case PadButton::ButtonX:
+ return "X";
+ break;
+ case PadButton::ButtonY:
+ return "Y";
+ break;
+ case PadButton::ButtonStart:
+ return "start";
+ break;
+ default:
+ return "Unkown GC";
+ }
+}
+
std::string GCAdapter::GetUIName(const Common::ParamPackage& params) const {
if (params.Has("button")) {
- return fmt::format("Button {}", params.Get("button", 0));
+ return fmt::format("Button {}", GetUIButtonName(params));
+ }
+ if (params.Has("axis")) {
+ return fmt::format("Axis {}", params.Get("axis",0));
}
return "Bad GC Adapter";
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index dd0e4aa1d..b82e4803d 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -105,8 +105,12 @@ private:
void Reset();
void UpdateVibrations();
- // Updates vibration state of all controllers
+
+ /// Updates vibration state of all controllers
void SendVibrations();
+
+ std::string GetUIButtonName(const Common::ParamPackage& params) const;
+
std::unique_ptr<LibUSBDeviceHandle> usb_adapter_handle;
std::array<GCController, 4> pads;
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp
index b00a4b8d9..85a781a30 100644
--- a/src/input_common/drivers/keyboard.cpp
+++ b/src/input_common/drivers/keyboard.cpp
@@ -26,7 +26,7 @@ void Keyboard::ReleaseAllKeys() {
std::vector<Common::ParamPackage> Keyboard::GetInputDevices() const {
std::vector<Common::ParamPackage> devices;
devices.emplace_back(Common::ParamPackage{
- {"engine", "keyboard"},
+ {"engine", GetEngineName()},
{"display", "Keyboard Only"},
});
return devices;
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index f7f03c5f2..cee2d965f 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -305,6 +305,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
if (joystick_map.find(guid) == joystick_map.end()) {
auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick, sdl_gamecontroller);
PreSetController(joystick->GetPadIdentifier());
+ SetBattery(joystick->GetPadIdentifier(), joystick->GetBatteryLevel());
joystick_map[guid].emplace_back(std::move(joystick));
return;
}
@@ -322,6 +323,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
const int port = static_cast<int>(joystick_guid_list.size());
auto joystick = std::make_shared<SDLJoystick>(guid, port, sdl_joystick, sdl_gamecontroller);
PreSetController(joystick->GetPadIdentifier());
+ SetBattery(joystick->GetPadIdentifier(), joystick->GetBatteryLevel());
joystick_guid_list.emplace_back(std::move(joystick));
}
@@ -472,7 +474,7 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
const std::string name =
fmt::format("{} {}", joystick->GetControllerName(), joystick->GetPort());
devices.emplace_back(Common::ParamPackage{
- {"engine", "sdl"},
+ {"engine", GetEngineName()},
{"display", std::move(name)},
{"guid", joystick->GetGUID()},
{"port", std::to_string(joystick->GetPort())},
@@ -495,7 +497,7 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
const std::string name =
fmt::format("{} {}", "Nintendo Dual Joy-Con", joystick->GetPort());
devices.emplace_back(Common::ParamPackage{
- {"engine", "sdl"},
+ {"engine", GetEngineName()},
{"display", std::move(name)},
{"guid", joystick->GetGUID()},
{"guid2", joystick2->GetGUID()},
@@ -527,7 +529,8 @@ Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
}
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
s32 axis, float value) const {
- Common::ParamPackage params({{"engine", "sdl"}});
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
params.Set("port", port);
params.Set("guid", std::move(guid));
params.Set("axis", axis);
@@ -538,7 +541,8 @@ Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::
Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, std::string guid,
s32 button) const {
- Common::ParamPackage params({{"engine", "sdl"}});
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
params.Set("port", port);
params.Set("guid", std::move(guid));
params.Set("button", button);
@@ -547,8 +551,8 @@ Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, std::
Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, std::string guid, s32 hat,
u8 value) const {
- Common::ParamPackage params({{"engine", "sdl"}});
-
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
params.Set("port", port);
params.Set("guid", std::move(guid));
params.Set("hat", hat);
@@ -557,7 +561,9 @@ Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, std::str
}
Common::ParamPackage SDLDriver::BuildMotionParam(int port, std::string guid) const {
- Common::ParamPackage params({{"engine", "sdl"}, {"motion", "0"}});
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
+ params.Set("motion", 0);
params.Set("port", port);
params.Set("guid", std::move(guid));
return params;
@@ -583,7 +589,7 @@ Common::ParamPackage SDLDriver::BuildParamPackageForAnalog(PadIdentifier identif
int axis_y, float offset_x,
float offset_y) const {
Common::ParamPackage params;
- params.Set("engine", "sdl");
+ params.Set("engine", GetEngineName());
params.Set("port", static_cast<int>(identifier.port));
params.Set("guid", identifier.guid.Format());
params.Set("axis_x", axis_x);
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index 5e2101b27..7e7a1d58f 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -127,7 +127,7 @@ void Tas::WriteTasFile(std::u8string file_name) {
std::string output_text;
for (size_t frame = 0; frame < record_commands.size(); frame++) {
const TASCommand& line = record_commands[frame];
- output_text += fmt::format("{} {} {} {} {}\n", frame, WriteCommandButtons(line.buttons),
+ output_text += fmt::format("{} {} {} {}\n", frame, WriteCommandButtons(line.buttons),
WriteCommandAxis(line.l_axis), WriteCommandAxis(line.r_axis));
}
const auto bytes_written = Common::FS::WriteStringToFile(