diff options
| author | 2021-10-11 00:43:11 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:24 -0600 | |
| commit | 06a5ef5874144a70e30e577a83ba68d1dad79e78 (patch) | |
| tree | 867fa1153c7285c858cdb5bd7f60f08266532a88 /src/core/hid/emulated_controller.cpp | |
| parent | core: Update input interpreter (diff) | |
| download | yuzu-06a5ef5874144a70e30e577a83ba68d1dad79e78.tar.gz yuzu-06a5ef5874144a70e30e577a83ba68d1dad79e78.tar.xz yuzu-06a5ef5874144a70e30e577a83ba68d1dad79e78.zip | |
core/hid: Add output devices
Diffstat (limited to 'src/core/hid/emulated_controller.cpp')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 119 |
1 files changed, 92 insertions, 27 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 4eb5d99bc..b9d16657a 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -66,12 +66,32 @@ void EmulatedController::ReloadFromSettings() { | |||
| 66 | for (std::size_t index = 0; index < player.motions.size(); ++index) { | 66 | for (std::size_t index = 0; index < player.motions.size(); ++index) { |
| 67 | motion_params[index] = Common::ParamPackage(player.motions[index]); | 67 | motion_params[index] = Common::ParamPackage(player.motions[index]); |
| 68 | } | 68 | } |
| 69 | |||
| 70 | controller.colors_state.left = { | ||
| 71 | .body = player.body_color_left, | ||
| 72 | .button = player.button_color_left, | ||
| 73 | }; | ||
| 74 | |||
| 75 | controller.colors_state.right = { | ||
| 76 | .body = player.body_color_right, | ||
| 77 | .button = player.button_color_right, | ||
| 78 | }; | ||
| 79 | |||
| 80 | controller.colors_state.fullkey = controller.colors_state.left; | ||
| 81 | |||
| 82 | SetNpadType(MapSettingsTypeToNPad(player.controller_type)); | ||
| 83 | |||
| 84 | if (player.connected) { | ||
| 85 | Connect(); | ||
| 86 | } else { | ||
| 87 | Disconnect(); | ||
| 88 | } | ||
| 89 | |||
| 69 | ReloadInput(); | 90 | ReloadInput(); |
| 70 | } | 91 | } |
| 71 | 92 | ||
| 72 | void EmulatedController::ReloadInput() { | 93 | void EmulatedController::ReloadInput() { |
| 73 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 94 | const auto player_index = NpadIdTypeToIndex(npad_id_type); |
| 74 | const auto& player = Settings::values.players.GetValue()[player_index]; | ||
| 75 | const auto left_side = button_params[Settings::NativeButton::ZL]; | 95 | const auto left_side = button_params[Settings::NativeButton::ZL]; |
| 76 | const auto right_side = button_params[Settings::NativeButton::ZR]; | 96 | const auto right_side = button_params[Settings::NativeButton::ZR]; |
| 77 | 97 | ||
| @@ -90,21 +110,13 @@ void EmulatedController::ReloadInput() { | |||
| 90 | trigger_devices[1] = | 110 | trigger_devices[1] = |
| 91 | Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZR]); | 111 | Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZR]); |
| 92 | 112 | ||
| 93 | controller.colors_state.left = { | ||
| 94 | .body = player.body_color_left, | ||
| 95 | .button = player.button_color_left, | ||
| 96 | }; | ||
| 97 | |||
| 98 | controller.colors_state.right = { | ||
| 99 | .body = player.body_color_right, | ||
| 100 | .button = player.button_color_right, | ||
| 101 | }; | ||
| 102 | |||
| 103 | controller.colors_state.fullkey = controller.colors_state.left; | ||
| 104 | |||
| 105 | battery_devices[0] = Input::CreateDevice<Input::InputDevice>(left_side); | 113 | battery_devices[0] = Input::CreateDevice<Input::InputDevice>(left_side); |
| 106 | battery_devices[1] = Input::CreateDevice<Input::InputDevice>(right_side); | 114 | battery_devices[1] = Input::CreateDevice<Input::InputDevice>(right_side); |
| 107 | 115 | ||
| 116 | button_params[Settings::NativeButton::ZL].Set("output",true); | ||
| 117 | output_devices[0] = | ||
| 118 | Input::CreateDevice<Input::OutputDevice>(button_params[Settings::NativeButton::ZL]); | ||
| 119 | |||
| 108 | for (std::size_t index = 0; index < button_devices.size(); ++index) { | 120 | for (std::size_t index = 0; index < button_devices.size(); ++index) { |
| 109 | if (!button_devices[index]) { | 121 | if (!button_devices[index]) { |
| 110 | continue; | 122 | continue; |
| @@ -149,14 +161,6 @@ void EmulatedController::ReloadInput() { | |||
| 149 | [this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }}; | 161 | [this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }}; |
| 150 | motion_devices[index]->SetCallback(motion_callback); | 162 | motion_devices[index]->SetCallback(motion_callback); |
| 151 | } | 163 | } |
| 152 | |||
| 153 | SetNpadType(MapSettingsTypeToNPad(player.controller_type)); | ||
| 154 | |||
| 155 | if (player.connected) { | ||
| 156 | Connect(); | ||
| 157 | } else { | ||
| 158 | Disconnect(); | ||
| 159 | } | ||
| 160 | } | 164 | } |
| 161 | 165 | ||
| 162 | void EmulatedController::UnloadInput() { | 166 | void EmulatedController::UnloadInput() { |
| @@ -197,7 +201,8 @@ void EmulatedController::SaveCurrentConfig() { | |||
| 197 | 201 | ||
| 198 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 202 | const auto player_index = NpadIdTypeToIndex(npad_id_type); |
| 199 | auto& player = Settings::values.players.GetValue()[player_index]; | 203 | auto& player = Settings::values.players.GetValue()[player_index]; |
| 200 | 204 | player.connected = is_connected; | |
| 205 | player.controller_type = MapNPadToSettingsType(npad_type); | ||
| 201 | for (std::size_t index = 0; index < player.buttons.size(); ++index) { | 206 | for (std::size_t index = 0; index < player.buttons.size(); ++index) { |
| 202 | player.buttons[index] = button_params[index].Serialize(); | 207 | player.buttons[index] = button_params[index].Serialize(); |
| 203 | } | 208 | } |
| @@ -601,13 +606,50 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t | |||
| 601 | TriggerOnChange(ControllerTriggerType::Battery); | 606 | TriggerOnChange(ControllerTriggerType::Battery); |
| 602 | } | 607 | } |
| 603 | 608 | ||
| 604 | bool EmulatedController::SetVibration([[maybe_unused]] std::size_t device_index, | 609 | bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) { |
| 605 | [[maybe_unused]] VibrationValue vibration) { | 610 | if (!output_devices[device_index]) { |
| 606 | return false; | 611 | return false; |
| 612 | } | ||
| 613 | |||
| 614 | const Input::VibrationStatus status = { | ||
| 615 | .low_amplitude = vibration.high_amplitude, | ||
| 616 | .low_frequency = vibration.high_amplitude, | ||
| 617 | .high_amplitude = vibration.high_amplitude, | ||
| 618 | .high_frequency = vibration.high_amplitude, | ||
| 619 | }; | ||
| 620 | return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None; | ||
| 621 | } | ||
| 622 | |||
| 623 | bool EmulatedController::TestVibration(std::size_t device_index) { | ||
| 624 | if (!output_devices[device_index]) { | ||
| 625 | return false; | ||
| 626 | } | ||
| 627 | |||
| 628 | // Send a slight vibration to test for rumble support | ||
| 629 | constexpr Input::VibrationStatus status = { | ||
| 630 | .low_amplitude = 0.001f, | ||
| 631 | .low_frequency = 160.0f, | ||
| 632 | .high_amplitude = 0.001f, | ||
| 633 | .high_frequency = 320.0f, | ||
| 634 | }; | ||
| 635 | return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None; | ||
| 607 | } | 636 | } |
| 608 | 637 | ||
| 609 | int EmulatedController::TestVibration(std::size_t device_index) { | 638 | void EmulatedController::SetLedPattern() { |
| 610 | return 1; | 639 | for (auto& device : output_devices) { |
| 640 | if (!device) { | ||
| 641 | continue; | ||
| 642 | } | ||
| 643 | |||
| 644 | const LedPattern pattern = GetLedPattern(); | ||
| 645 | const Input::LedStatus status = { | ||
| 646 | .led_1 = pattern.position1 != 0, | ||
| 647 | .led_2 = pattern.position2 != 0, | ||
| 648 | .led_3 = pattern.position3 != 0, | ||
| 649 | .led_4 = pattern.position4 != 0, | ||
| 650 | }; | ||
| 651 | device->SetLED(status); | ||
| 652 | } | ||
| 611 | } | 653 | } |
| 612 | 654 | ||
| 613 | void EmulatedController::Connect() { | 655 | void EmulatedController::Connect() { |
| @@ -655,6 +697,29 @@ void EmulatedController::SetNpadType(NpadType npad_type_) { | |||
| 655 | TriggerOnChange(ControllerTriggerType::Type); | 697 | TriggerOnChange(ControllerTriggerType::Type); |
| 656 | } | 698 | } |
| 657 | 699 | ||
| 700 | LedPattern EmulatedController::GetLedPattern() const { | ||
| 701 | switch (npad_id_type) { | ||
| 702 | case NpadIdType::Player1: | ||
| 703 | return LedPattern{1, 0, 0, 0}; | ||
| 704 | case NpadIdType::Player2: | ||
| 705 | return LedPattern{1, 1, 0, 0}; | ||
| 706 | case NpadIdType::Player3: | ||
| 707 | return LedPattern{1, 1, 1, 0}; | ||
| 708 | case NpadIdType::Player4: | ||
| 709 | return LedPattern{1, 1, 1, 1}; | ||
| 710 | case NpadIdType::Player5: | ||
| 711 | return LedPattern{1, 0, 0, 1}; | ||
| 712 | case NpadIdType::Player6: | ||
| 713 | return LedPattern{1, 0, 1, 0}; | ||
| 714 | case NpadIdType::Player7: | ||
| 715 | return LedPattern{1, 0, 1, 1}; | ||
| 716 | case NpadIdType::Player8: | ||
| 717 | return LedPattern{0, 1, 1, 0}; | ||
| 718 | default: | ||
| 719 | return LedPattern{0, 0, 0, 0}; | ||
| 720 | } | ||
| 721 | } | ||
| 722 | |||
| 658 | ButtonValues EmulatedController::GetButtonsValues() const { | 723 | ButtonValues EmulatedController::GetButtonsValues() const { |
| 659 | return controller.button_values; | 724 | return controller.button_values; |
| 660 | } | 725 | } |