summaryrefslogtreecommitdiff
path: root/src/core/hid/emulated_controller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid/emulated_controller.cpp')
-rw-r--r--src/core/hid/emulated_controller.cpp50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 48add394b..83ced5635 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -87,11 +87,23 @@ void EmulatedController::ReloadFromSettings() {
87 87
88 ReloadInput(); 88 ReloadInput();
89} 89}
90void EmulatedController::LoadDevices() {
91 const auto left_joycon = button_params[Settings::NativeButton::ZL];
92 const auto right_joycon = button_params[Settings::NativeButton::ZR];
90 93
91void EmulatedController::ReloadInput() { 94 // Triggers for GC controllers
92 // If you load any device here add the equivalent to the UnloadInput() function 95 trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL];
93 const auto left_side = button_params[Settings::NativeButton::ZL]; 96 trigger_params[RightIndex] = button_params[Settings::NativeButton::ZR];
94 const auto right_side = button_params[Settings::NativeButton::ZR]; 97
98 battery_params[LeftIndex] = left_joycon;
99 battery_params[RightIndex] = right_joycon;
100 battery_params[LeftIndex].Set("battery", true);
101 battery_params[RightIndex].Set("battery", true);
102
103 output_params[LeftIndex] = left_joycon;
104 output_params[RightIndex] = right_joycon;
105 output_params[LeftIndex].Set("output", true);
106 output_params[RightIndex].Set("output", true);
95 107
96 std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, 108 std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
97 button_params.begin() + Settings::NativeButton::BUTTON_NS_END, 109 button_params.begin() + Settings::NativeButton::BUTTON_NS_END,
@@ -102,19 +114,17 @@ void EmulatedController::ReloadInput() {
102 std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, 114 std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN,
103 motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, 115 motion_params.begin() + Settings::NativeMotion::MOTION_HID_END,
104 motion_devices.begin(), Input::CreateDevice<Input::InputDevice>); 116 motion_devices.begin(), Input::CreateDevice<Input::InputDevice>);
117 std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(),
118 Input::CreateDevice<Input::InputDevice>);
119 std::transform(battery_params.begin(), battery_params.begin(), battery_devices.end(),
120 Input::CreateDevice<Input::InputDevice>);
121 std::transform(output_params.begin(), output_params.end(), output_devices.begin(),
122 Input::CreateDevice<Input::OutputDevice>);
123}
105 124
106 trigger_devices[0] = 125void EmulatedController::ReloadInput() {
107 Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZL]); 126 // If you load any device here add the equivalent to the UnloadInput() function
108 trigger_devices[1] = 127 LoadDevices();
109 Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZR]);
110
111 battery_devices[0] = Input::CreateDevice<Input::InputDevice>(left_side);
112 battery_devices[1] = Input::CreateDevice<Input::InputDevice>(right_side);
113
114 button_params[Settings::NativeButton::ZL].Set("output", true);
115 output_devices[0] =
116 Input::CreateDevice<Input::OutputDevice>(button_params[Settings::NativeButton::ZL]);
117
118 for (std::size_t index = 0; index < button_devices.size(); ++index) { 128 for (std::size_t index = 0; index < button_devices.size(); ++index) {
119 if (!button_devices[index]) { 129 if (!button_devices[index]) {
120 continue; 130 continue;
@@ -241,7 +251,7 @@ void EmulatedController::RestoreConfig() {
241 ReloadFromSettings(); 251 ReloadFromSettings();
242} 252}
243 253
244std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices() const { 254std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(DeviceIndex device_index) const {
245 std::vector<Common::ParamPackage> devices; 255 std::vector<Common::ParamPackage> devices;
246 for (const auto& param : button_params) { 256 for (const auto& param : button_params) {
247 if (!param.Has("engine")) { 257 if (!param.Has("engine")) {
@@ -612,21 +622,21 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t
612 } 622 }
613 623
614 switch (index) { 624 switch (index) {
615 case 0: 625 case LeftIndex:
616 controller.battery_state.left = { 626 controller.battery_state.left = {
617 .is_powered = is_powered, 627 .is_powered = is_powered,
618 .is_charging = is_charging, 628 .is_charging = is_charging,
619 .battery_level = battery_level, 629 .battery_level = battery_level,
620 }; 630 };
621 break; 631 break;
622 case 1: 632 case RightIndex:
623 controller.battery_state.right = { 633 controller.battery_state.right = {
624 .is_powered = is_powered, 634 .is_powered = is_powered,
625 .is_charging = is_charging, 635 .is_charging = is_charging,
626 .battery_level = battery_level, 636 .battery_level = battery_level,
627 }; 637 };
628 break; 638 break;
629 case 2: 639 case DualIndex:
630 controller.battery_state.dual = { 640 controller.battery_state.dual = {
631 .is_powered = is_powered, 641 .is_powered = is_powered,
632 .is_charging = is_charging, 642 .is_charging = is_charging,