diff options
Diffstat (limited to 'src/core/hid/emulated_controller.cpp')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 98 |
1 files changed, 77 insertions, 21 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index b04ab4cd8..7ef6ef118 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -54,6 +54,7 @@ Settings::ControllerType EmulatedController::MapNPadToSettingsType(NpadType type | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | void EmulatedController::ReloadFromSettings() { | 56 | void EmulatedController::ReloadFromSettings() { |
| 57 | //LOG_ERROR(Service_HID, "reload config from settings {}", NpadIdTypeToIndex(npad_id_type)); | ||
| 57 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 58 | const auto player_index = NpadIdTypeToIndex(npad_id_type); |
| 58 | const auto& player = Settings::values.players.GetValue()[player_index]; | 59 | const auto& player = Settings::values.players.GetValue()[player_index]; |
| 59 | 60 | ||
| @@ -91,6 +92,7 @@ void EmulatedController::ReloadFromSettings() { | |||
| 91 | } | 92 | } |
| 92 | 93 | ||
| 93 | void EmulatedController::ReloadInput() { | 94 | void EmulatedController::ReloadInput() { |
| 95 | //LOG_ERROR(Service_HID, "reload config {}", NpadIdTypeToIndex(npad_id_type)); | ||
| 94 | // If you load any device here add the equivalent to the UnloadInput() function | 96 | // If you load any device here add the equivalent to the UnloadInput() function |
| 95 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 97 | const auto player_index = NpadIdTypeToIndex(npad_id_type); |
| 96 | const auto left_side = button_params[Settings::NativeButton::ZL]; | 98 | const auto left_side = button_params[Settings::NativeButton::ZL]; |
| @@ -187,11 +189,29 @@ void EmulatedController::UnloadInput() { | |||
| 187 | 189 | ||
| 188 | void EmulatedController::EnableConfiguration() { | 190 | void EmulatedController::EnableConfiguration() { |
| 189 | is_configuring = true; | 191 | is_configuring = true; |
| 190 | SaveCurrentConfig(); | 192 | temporary_is_connected = is_connected; |
| 193 | temporary_npad_type = npad_type; | ||
| 191 | } | 194 | } |
| 192 | 195 | ||
| 193 | void EmulatedController::DisableConfiguration() { | 196 | void EmulatedController::DisableConfiguration() { |
| 194 | is_configuring = false; | 197 | is_configuring = false; |
| 198 | |||
| 199 | // Apply temporary npad type to the real controller | ||
| 200 | if (temporary_npad_type != npad_type) { | ||
| 201 | if (is_connected) { | ||
| 202 | Disconnect(); | ||
| 203 | } | ||
| 204 | SetNpadType(temporary_npad_type); | ||
| 205 | } | ||
| 206 | |||
| 207 | // Apply temporary connected status to the real controller | ||
| 208 | if (temporary_is_connected != is_connected) { | ||
| 209 | if (temporary_is_connected) { | ||
| 210 | Connect(); | ||
| 211 | return; | ||
| 212 | } | ||
| 213 | Disconnect(); | ||
| 214 | } | ||
| 195 | } | 215 | } |
| 196 | 216 | ||
| 197 | bool EmulatedController::IsConfiguring() const { | 217 | bool EmulatedController::IsConfiguring() const { |
| @@ -199,10 +219,6 @@ bool EmulatedController::IsConfiguring() const { | |||
| 199 | } | 219 | } |
| 200 | 220 | ||
| 201 | void EmulatedController::SaveCurrentConfig() { | 221 | void EmulatedController::SaveCurrentConfig() { |
| 202 | if (!is_configuring) { | ||
| 203 | return; | ||
| 204 | } | ||
| 205 | |||
| 206 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 222 | const auto player_index = NpadIdTypeToIndex(npad_id_type); |
| 207 | auto& player = Settings::values.players.GetValue()[player_index]; | 223 | auto& player = Settings::values.players.GetValue()[player_index]; |
| 208 | player.connected = is_connected; | 224 | player.connected = is_connected; |
| @@ -657,26 +673,47 @@ void EmulatedController::SetLedPattern() { | |||
| 657 | } | 673 | } |
| 658 | 674 | ||
| 659 | void EmulatedController::Connect() { | 675 | void EmulatedController::Connect() { |
| 660 | std::lock_guard lock{mutex}; | 676 | { |
| 661 | if (is_connected) { | 677 | std::lock_guard lock{mutex}; |
| 662 | LOG_WARNING(Service_HID, "Tried to turn on a connected controller {}", npad_id_type); | 678 | if (is_configuring) { |
| 663 | return; | 679 | temporary_is_connected = true; |
| 680 | TriggerOnChange(ControllerTriggerType::Connected); | ||
| 681 | return; | ||
| 682 | } | ||
| 683 | |||
| 684 | if (is_connected) { | ||
| 685 | return; | ||
| 686 | } | ||
| 687 | is_connected = true; | ||
| 664 | } | 688 | } |
| 665 | is_connected = true; | 689 | LOG_ERROR(Service_HID, "Connected controller {}", NpadIdTypeToIndex(npad_id_type)); |
| 666 | TriggerOnChange(ControllerTriggerType::Connected); | 690 | TriggerOnChange(ControllerTriggerType::Connected); |
| 667 | } | 691 | } |
| 668 | 692 | ||
| 669 | void EmulatedController::Disconnect() { | 693 | void EmulatedController::Disconnect() { |
| 670 | std::lock_guard lock{mutex}; | 694 | { |
| 671 | if (!is_connected) { | 695 | std::lock_guard lock{mutex}; |
| 672 | LOG_WARNING(Service_HID, "Tried to turn off a disconnected controller {}", npad_id_type); | 696 | if (is_configuring) { |
| 673 | return; | 697 | temporary_is_connected = false; |
| 698 | LOG_ERROR(Service_HID, "Disconnected temporal controller {}", | ||
| 699 | NpadIdTypeToIndex(npad_id_type)); | ||
| 700 | TriggerOnChange(ControllerTriggerType::Disconnected); | ||
| 701 | return; | ||
| 702 | } | ||
| 703 | |||
| 704 | if (!is_connected) { | ||
| 705 | return; | ||
| 706 | } | ||
| 707 | is_connected = false; | ||
| 674 | } | 708 | } |
| 675 | is_connected = false; | 709 | LOG_ERROR(Service_HID, "Disconnected controller {}", NpadIdTypeToIndex(npad_id_type)); |
| 676 | TriggerOnChange(ControllerTriggerType::Disconnected); | 710 | TriggerOnChange(ControllerTriggerType::Disconnected); |
| 677 | } | 711 | } |
| 678 | 712 | ||
| 679 | bool EmulatedController::IsConnected() const { | 713 | bool EmulatedController::IsConnected(bool temporary) const { |
| 714 | if (temporary) { | ||
| 715 | return temporary_is_connected; | ||
| 716 | } | ||
| 680 | return is_connected; | 717 | return is_connected; |
| 681 | } | 718 | } |
| 682 | 719 | ||
| @@ -688,16 +725,35 @@ NpadIdType EmulatedController::GetNpadIdType() const { | |||
| 688 | return npad_id_type; | 725 | return npad_id_type; |
| 689 | } | 726 | } |
| 690 | 727 | ||
| 691 | NpadType EmulatedController::GetNpadType() const { | 728 | NpadType EmulatedController::GetNpadType(bool temporary) const { |
| 729 | if (temporary) { | ||
| 730 | return temporary_npad_type; | ||
| 731 | } | ||
| 692 | return npad_type; | 732 | return npad_type; |
| 693 | } | 733 | } |
| 694 | 734 | ||
| 695 | void EmulatedController::SetNpadType(NpadType npad_type_) { | 735 | void EmulatedController::SetNpadType(NpadType npad_type_) { |
| 696 | std::lock_guard lock{mutex}; | 736 | { |
| 697 | if (npad_type == npad_type_) { | 737 | std::lock_guard lock{mutex}; |
| 698 | return; | 738 | |
| 739 | if (is_configuring) { | ||
| 740 | if (temporary_npad_type == npad_type_) { | ||
| 741 | return; | ||
| 742 | } | ||
| 743 | temporary_npad_type = npad_type_; | ||
| 744 | TriggerOnChange(ControllerTriggerType::Type); | ||
| 745 | return; | ||
| 746 | } | ||
| 747 | |||
| 748 | if (npad_type == npad_type_) { | ||
| 749 | return; | ||
| 750 | } | ||
| 751 | if (is_connected) { | ||
| 752 | LOG_WARNING(Service_HID, "Controller {} type changed while it's connected", | ||
| 753 | NpadIdTypeToIndex(npad_id_type)); | ||
| 754 | } | ||
| 755 | npad_type = npad_type_; | ||
| 699 | } | 756 | } |
| 700 | npad_type = npad_type_; | ||
| 701 | TriggerOnChange(ControllerTriggerType::Type); | 757 | TriggerOnChange(ControllerTriggerType::Type); |
| 702 | } | 758 | } |
| 703 | 759 | ||