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.cpp88
1 files changed, 45 insertions, 43 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 69568f4e9..49893cdbd 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -110,25 +110,25 @@ void EmulatedController::LoadDevices() {
110 110
111 std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, 111 std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
112 button_params.begin() + Settings::NativeButton::BUTTON_NS_END, 112 button_params.begin() + Settings::NativeButton::BUTTON_NS_END,
113 button_devices.begin(), Input::CreateDevice<Input::InputDevice>); 113 button_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>);
114 std::transform(stick_params.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, 114 std::transform(stick_params.begin() + Settings::NativeAnalog::STICK_HID_BEGIN,
115 stick_params.begin() + Settings::NativeAnalog::STICK_HID_END, 115 stick_params.begin() + Settings::NativeAnalog::STICK_HID_END,
116 stick_devices.begin(), Input::CreateDevice<Input::InputDevice>); 116 stick_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>);
117 std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, 117 std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN,
118 motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, 118 motion_params.begin() + Settings::NativeMotion::MOTION_HID_END,
119 motion_devices.begin(), Input::CreateDevice<Input::InputDevice>); 119 motion_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>);
120 std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(), 120 std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(),
121 Input::CreateDevice<Input::InputDevice>); 121 Common::Input::CreateDevice<Common::Input::InputDevice>);
122 std::transform(battery_params.begin(), battery_params.begin(), battery_devices.end(), 122 std::transform(battery_params.begin(), battery_params.begin(), battery_devices.end(),
123 Input::CreateDevice<Input::InputDevice>); 123 Common::Input::CreateDevice<Common::Input::InputDevice>);
124 std::transform(output_params.begin(), output_params.end(), output_devices.begin(), 124 std::transform(output_params.begin(), output_params.end(), output_devices.begin(),
125 Input::CreateDevice<Input::OutputDevice>); 125 Common::Input::CreateDevice<Common::Input::OutputDevice>);
126 126
127 // Initialize TAS devices 127 // Initialize TAS devices
128 std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(), 128 std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(),
129 Input::CreateDevice<Input::InputDevice>); 129 Common::Input::CreateDevice<Common::Input::InputDevice>);
130 std::transform(tas_stick_params.begin(), tas_stick_params.end(), tas_stick_devices.begin(), 130 std::transform(tas_stick_params.begin(), tas_stick_params.end(), tas_stick_devices.begin(),
131 Input::CreateDevice<Input::InputDevice>); 131 Common::Input::CreateDevice<Common::Input::InputDevice>);
132} 132}
133 133
134void EmulatedController::LoadTASParams() { 134void EmulatedController::LoadTASParams() {
@@ -178,8 +178,8 @@ void EmulatedController::ReloadInput() {
178 if (!button_devices[index]) { 178 if (!button_devices[index]) {
179 continue; 179 continue;
180 } 180 }
181 Input::InputCallback button_callback{ 181 Common::Input::InputCallback button_callback{
182 [this, index](Input::CallbackStatus callback) { SetButton(callback, index); }}; 182 [this, index](Common::Input::CallbackStatus callback) { SetButton(callback, index); }};
183 button_devices[index]->SetCallback(button_callback); 183 button_devices[index]->SetCallback(button_callback);
184 button_devices[index]->ForceUpdate(); 184 button_devices[index]->ForceUpdate();
185 } 185 }
@@ -188,8 +188,8 @@ void EmulatedController::ReloadInput() {
188 if (!stick_devices[index]) { 188 if (!stick_devices[index]) {
189 continue; 189 continue;
190 } 190 }
191 Input::InputCallback stick_callback{ 191 Common::Input::InputCallback stick_callback{
192 [this, index](Input::CallbackStatus callback) { SetStick(callback, index); }}; 192 [this, index](Common::Input::CallbackStatus callback) { SetStick(callback, index); }};
193 stick_devices[index]->SetCallback(stick_callback); 193 stick_devices[index]->SetCallback(stick_callback);
194 stick_devices[index]->ForceUpdate(); 194 stick_devices[index]->ForceUpdate();
195 } 195 }
@@ -198,8 +198,8 @@ void EmulatedController::ReloadInput() {
198 if (!trigger_devices[index]) { 198 if (!trigger_devices[index]) {
199 continue; 199 continue;
200 } 200 }
201 Input::InputCallback trigger_callback{ 201 Common::Input::InputCallback trigger_callback{
202 [this, index](Input::CallbackStatus callback) { SetTrigger(callback, index); }}; 202 [this, index](Common::Input::CallbackStatus callback) { SetTrigger(callback, index); }};
203 trigger_devices[index]->SetCallback(trigger_callback); 203 trigger_devices[index]->SetCallback(trigger_callback);
204 trigger_devices[index]->ForceUpdate(); 204 trigger_devices[index]->ForceUpdate();
205 } 205 }
@@ -208,8 +208,8 @@ void EmulatedController::ReloadInput() {
208 if (!battery_devices[index]) { 208 if (!battery_devices[index]) {
209 continue; 209 continue;
210 } 210 }
211 Input::InputCallback battery_callback{ 211 Common::Input::InputCallback battery_callback{
212 [this, index](Input::CallbackStatus callback) { SetBattery(callback, index); }}; 212 [this, index](Common::Input::CallbackStatus callback) { SetBattery(callback, index); }};
213 battery_devices[index]->SetCallback(battery_callback); 213 battery_devices[index]->SetCallback(battery_callback);
214 battery_devices[index]->ForceUpdate(); 214 battery_devices[index]->ForceUpdate();
215 } 215 }
@@ -218,8 +218,8 @@ void EmulatedController::ReloadInput() {
218 if (!motion_devices[index]) { 218 if (!motion_devices[index]) {
219 continue; 219 continue;
220 } 220 }
221 Input::InputCallback motion_callback{ 221 Common::Input::InputCallback motion_callback{
222 [this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }}; 222 [this, index](Common::Input::CallbackStatus callback) { SetMotion(callback, index); }};
223 motion_devices[index]->SetCallback(motion_callback); 223 motion_devices[index]->SetCallback(motion_callback);
224 motion_devices[index]->ForceUpdate(); 224 motion_devices[index]->ForceUpdate();
225 } 225 }
@@ -229,8 +229,8 @@ void EmulatedController::ReloadInput() {
229 if (!tas_button_devices[index]) { 229 if (!tas_button_devices[index]) {
230 continue; 230 continue;
231 } 231 }
232 Input::InputCallback button_callback{ 232 Common::Input::InputCallback button_callback{
233 [this, index](Input::CallbackStatus callback) { SetButton(callback, index); }}; 233 [this, index](Common::Input::CallbackStatus callback) { SetButton(callback, index); }};
234 tas_button_devices[index]->SetCallback(button_callback); 234 tas_button_devices[index]->SetCallback(button_callback);
235 } 235 }
236 236
@@ -238,8 +238,8 @@ void EmulatedController::ReloadInput() {
238 if (!tas_stick_devices[index]) { 238 if (!tas_stick_devices[index]) {
239 continue; 239 continue;
240 } 240 }
241 Input::InputCallback stick_callback{ 241 Common::Input::InputCallback stick_callback{
242 [this, index](Input::CallbackStatus callback) { SetStick(callback, index); }}; 242 [this, index](Common::Input::CallbackStatus callback) { SetStick(callback, index); }};
243 tas_stick_devices[index]->SetCallback(stick_callback); 243 tas_stick_devices[index]->SetCallback(stick_callback);
244 } 244 }
245} 245}
@@ -418,7 +418,7 @@ void EmulatedController::SetMotionParam(std::size_t index, Common::ParamPackage
418 ReloadInput(); 418 ReloadInput();
419} 419}
420 420
421void EmulatedController::SetButton(Input::CallbackStatus callback, std::size_t index) { 421void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index) {
422 if (index >= controller.button_values.size()) { 422 if (index >= controller.button_values.size()) {
423 return; 423 return;
424 } 424 }
@@ -548,7 +548,7 @@ void EmulatedController::SetButton(Input::CallbackStatus callback, std::size_t i
548 TriggerOnChange(ControllerTriggerType::Button, true); 548 TriggerOnChange(ControllerTriggerType::Button, true);
549} 549}
550 550
551void EmulatedController::SetStick(Input::CallbackStatus callback, std::size_t index) { 551void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index) {
552 if (index >= controller.stick_values.size()) { 552 if (index >= controller.stick_values.size()) {
553 return; 553 return;
554 } 554 }
@@ -587,7 +587,7 @@ void EmulatedController::SetStick(Input::CallbackStatus callback, std::size_t in
587 TriggerOnChange(ControllerTriggerType::Stick, true); 587 TriggerOnChange(ControllerTriggerType::Stick, true);
588} 588}
589 589
590void EmulatedController::SetTrigger(Input::CallbackStatus callback, std::size_t index) { 590void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index) {
591 if (index >= controller.trigger_values.size()) { 591 if (index >= controller.trigger_values.size()) {
592 return; 592 return;
593 } 593 }
@@ -618,7 +618,7 @@ void EmulatedController::SetTrigger(Input::CallbackStatus callback, std::size_t
618 TriggerOnChange(ControllerTriggerType::Trigger, true); 618 TriggerOnChange(ControllerTriggerType::Trigger, true);
619} 619}
620 620
621void EmulatedController::SetMotion(Input::CallbackStatus callback, std::size_t index) { 621void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::size_t index) {
622 if (index >= controller.motion_values.size()) { 622 if (index >= controller.motion_values.size()) {
623 return; 623 return;
624 } 624 }
@@ -655,7 +655,7 @@ void EmulatedController::SetMotion(Input::CallbackStatus callback, std::size_t i
655 TriggerOnChange(ControllerTriggerType::Motion, true); 655 TriggerOnChange(ControllerTriggerType::Motion, true);
656} 656}
657 657
658void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t index) { 658void EmulatedController::SetBattery(Common::Input::CallbackStatus callback, std::size_t index) {
659 if (index >= controller.battery_values.size()) { 659 if (index >= controller.battery_values.size()) {
660 return; 660 return;
661 } 661 }
@@ -671,25 +671,25 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t
671 bool is_powered = false; 671 bool is_powered = false;
672 BatteryLevel battery_level = 0; 672 BatteryLevel battery_level = 0;
673 switch (controller.battery_values[index]) { 673 switch (controller.battery_values[index]) {
674 case Input::BatteryLevel::Charging: 674 case Common::Input::BatteryLevel::Charging:
675 is_charging = true; 675 is_charging = true;
676 is_powered = true; 676 is_powered = true;
677 battery_level = 6; 677 battery_level = 6;
678 break; 678 break;
679 case Input::BatteryLevel::Medium: 679 case Common::Input::BatteryLevel::Medium:
680 battery_level = 6; 680 battery_level = 6;
681 break; 681 break;
682 case Input::BatteryLevel::Low: 682 case Common::Input::BatteryLevel::Low:
683 battery_level = 4; 683 battery_level = 4;
684 break; 684 break;
685 case Input::BatteryLevel::Critical: 685 case Common::Input::BatteryLevel::Critical:
686 battery_level = 2; 686 battery_level = 2;
687 break; 687 break;
688 case Input::BatteryLevel::Empty: 688 case Common::Input::BatteryLevel::Empty:
689 battery_level = 0; 689 battery_level = 0;
690 break; 690 break;
691 case Input::BatteryLevel::None: 691 case Common::Input::BatteryLevel::None:
692 case Input::BatteryLevel::Full: 692 case Common::Input::BatteryLevel::Full:
693 default: 693 default:
694 is_powered = true; 694 is_powered = true;
695 battery_level = 8; 695 battery_level = 8;
@@ -739,18 +739,19 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v
739 739
740 // Exponential amplification is too strong at low amplitudes. Switch to a linear 740 // Exponential amplification is too strong at low amplitudes. Switch to a linear
741 // amplification if strength is set below 0.7f 741 // amplification if strength is set below 0.7f
742 const Input::VibrationAmplificationType type = 742 const Common::Input::VibrationAmplificationType type =
743 strength > 0.7f ? Input::VibrationAmplificationType::Exponential 743 strength > 0.7f ? Common::Input::VibrationAmplificationType::Exponential
744 : Input::VibrationAmplificationType::Linear; 744 : Common::Input::VibrationAmplificationType::Linear;
745 745
746 const Input::VibrationStatus status = { 746 const Common::Input::VibrationStatus status = {
747 .low_amplitude = std::min(vibration.low_amplitude * strength, 1.0f), 747 .low_amplitude = std::min(vibration.low_amplitude * strength, 1.0f),
748 .low_frequency = vibration.low_frequency, 748 .low_frequency = vibration.low_frequency,
749 .high_amplitude = std::min(vibration.high_amplitude * strength, 1.0f), 749 .high_amplitude = std::min(vibration.high_amplitude * strength, 1.0f),
750 .high_frequency = vibration.high_frequency, 750 .high_frequency = vibration.high_frequency,
751 .type = type, 751 .type = type,
752 }; 752 };
753 return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None; 753 return output_devices[device_index]->SetVibration(status) ==
754 Common::Input::VibrationError::None;
754} 755}
755 756
756bool EmulatedController::TestVibration(std::size_t device_index) { 757bool EmulatedController::TestVibration(std::size_t device_index) {
@@ -762,14 +763,15 @@ bool EmulatedController::TestVibration(std::size_t device_index) {
762 } 763 }
763 764
764 // Send a slight vibration to test for rumble support 765 // Send a slight vibration to test for rumble support
765 constexpr Input::VibrationStatus status = { 766 constexpr Common::Input::VibrationStatus status = {
766 .low_amplitude = 0.001f, 767 .low_amplitude = 0.001f,
767 .low_frequency = 160.0f, 768 .low_frequency = 160.0f,
768 .high_amplitude = 0.001f, 769 .high_amplitude = 0.001f,
769 .high_frequency = 320.0f, 770 .high_frequency = 320.0f,
770 .type = Input::VibrationAmplificationType::Linear, 771 .type = Common::Input::VibrationAmplificationType::Linear,
771 }; 772 };
772 return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None; 773 return output_devices[device_index]->SetVibration(status) ==
774 Common::Input::VibrationError::None;
773} 775}
774 776
775void EmulatedController::SetLedPattern() { 777void EmulatedController::SetLedPattern() {
@@ -779,7 +781,7 @@ void EmulatedController::SetLedPattern() {
779 } 781 }
780 782
781 const LedPattern pattern = GetLedPattern(); 783 const LedPattern pattern = GetLedPattern();
782 const Input::LedStatus status = { 784 const Common::Input::LedStatus status = {
783 .led_1 = pattern.position1 != 0, 785 .led_1 = pattern.position1 != 0,
784 .led_2 = pattern.position2 != 0, 786 .led_2 = pattern.position2 != 0,
785 .led_3 = pattern.position3 != 0, 787 .led_3 = pattern.position3 != 0,