diff options
Diffstat (limited to 'src/core/hid')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 17 | ||||
| -rw-r--r-- | src/core/hid/hid_core.cpp | 5 | ||||
| -rw-r--r-- | src/core/hid/hid_types.h | 80 | ||||
| -rw-r--r-- | src/core/hid/input_interpreter.cpp | 4 | ||||
| -rw-r--r-- | src/core/hid/input_interpreter.h | 4 |
5 files changed, 40 insertions, 70 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 34927cddd..a22015ada 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/thread.h" | 8 | #include "common/thread.h" |
| 9 | #include "core/hid/emulated_controller.h" | 9 | #include "core/hid/emulated_controller.h" |
| 10 | #include "core/hid/input_converter.h" | 10 | #include "core/hid/input_converter.h" |
| 11 | #include "core/hle/service/hid/hid_util.h" | ||
| 11 | 12 | ||
| 12 | namespace Core::HID { | 13 | namespace Core::HID { |
| 13 | constexpr s32 HID_JOYSTICK_MAX = 0x7fff; | 14 | constexpr s32 HID_JOYSTICK_MAX = 0x7fff; |
| @@ -82,7 +83,7 @@ Settings::ControllerType EmulatedController::MapNPadToSettingsType(NpadStyleInde | |||
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | void EmulatedController::ReloadFromSettings() { | 85 | void EmulatedController::ReloadFromSettings() { |
| 85 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 86 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 86 | const auto& player = Settings::values.players.GetValue()[player_index]; | 87 | const auto& player = Settings::values.players.GetValue()[player_index]; |
| 87 | 88 | ||
| 88 | for (std::size_t index = 0; index < player.buttons.size(); ++index) { | 89 | for (std::size_t index = 0; index < player.buttons.size(); ++index) { |
| @@ -118,7 +119,7 @@ void EmulatedController::ReloadFromSettings() { | |||
| 118 | } | 119 | } |
| 119 | 120 | ||
| 120 | void EmulatedController::ReloadColorsFromSettings() { | 121 | void EmulatedController::ReloadColorsFromSettings() { |
| 121 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 122 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 122 | const auto& player = Settings::values.players.GetValue()[player_index]; | 123 | const auto& player = Settings::values.players.GetValue()[player_index]; |
| 123 | 124 | ||
| 124 | // Avoid updating colors if overridden by physical controller | 125 | // Avoid updating colors if overridden by physical controller |
| @@ -215,7 +216,7 @@ void EmulatedController::LoadDevices() { | |||
| 215 | } | 216 | } |
| 216 | 217 | ||
| 217 | void EmulatedController::LoadTASParams() { | 218 | void EmulatedController::LoadTASParams() { |
| 218 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 219 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 219 | Common::ParamPackage common_params{}; | 220 | Common::ParamPackage common_params{}; |
| 220 | common_params.Set("engine", "tas"); | 221 | common_params.Set("engine", "tas"); |
| 221 | common_params.Set("port", static_cast<int>(player_index)); | 222 | common_params.Set("port", static_cast<int>(player_index)); |
| @@ -264,7 +265,7 @@ void EmulatedController::LoadTASParams() { | |||
| 264 | } | 265 | } |
| 265 | 266 | ||
| 266 | void EmulatedController::LoadVirtualGamepadParams() { | 267 | void EmulatedController::LoadVirtualGamepadParams() { |
| 267 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 268 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 268 | Common::ParamPackage common_params{}; | 269 | Common::ParamPackage common_params{}; |
| 269 | common_params.Set("engine", "virtual_gamepad"); | 270 | common_params.Set("engine", "virtual_gamepad"); |
| 270 | common_params.Set("port", static_cast<int>(player_index)); | 271 | common_params.Set("port", static_cast<int>(player_index)); |
| @@ -615,7 +616,7 @@ bool EmulatedController::IsConfiguring() const { | |||
| 615 | } | 616 | } |
| 616 | 617 | ||
| 617 | void EmulatedController::SaveCurrentConfig() { | 618 | void EmulatedController::SaveCurrentConfig() { |
| 618 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 619 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 619 | auto& player = Settings::values.players.GetValue()[player_index]; | 620 | auto& player = Settings::values.players.GetValue()[player_index]; |
| 620 | player.connected = is_connected; | 621 | player.connected = is_connected; |
| 621 | player.controller_type = MapNPadToSettingsType(npad_type); | 622 | player.controller_type = MapNPadToSettingsType(npad_type); |
| @@ -1212,7 +1213,7 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v | |||
| 1212 | if (!output_devices[device_index]) { | 1213 | if (!output_devices[device_index]) { |
| 1213 | return false; | 1214 | return false; |
| 1214 | } | 1215 | } |
| 1215 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 1216 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 1216 | const auto& player = Settings::values.players.GetValue()[player_index]; | 1217 | const auto& player = Settings::values.players.GetValue()[player_index]; |
| 1217 | const f32 strength = static_cast<f32>(player.vibration_strength) / 100.0f; | 1218 | const f32 strength = static_cast<f32>(player.vibration_strength) / 100.0f; |
| 1218 | 1219 | ||
| @@ -1238,7 +1239,7 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v | |||
| 1238 | } | 1239 | } |
| 1239 | 1240 | ||
| 1240 | bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { | 1241 | bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { |
| 1241 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | 1242 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 1242 | const auto& player = Settings::values.players.GetValue()[player_index]; | 1243 | const auto& player = Settings::values.players.GetValue()[player_index]; |
| 1243 | 1244 | ||
| 1244 | if (!player.vibration_enabled) { | 1245 | if (!player.vibration_enabled) { |
| @@ -1648,7 +1649,7 @@ void EmulatedController::SetNpadStyleIndex(NpadStyleIndex npad_type_) { | |||
| 1648 | } | 1649 | } |
| 1649 | if (is_connected) { | 1650 | if (is_connected) { |
| 1650 | LOG_WARNING(Service_HID, "Controller {} type changed while it's connected", | 1651 | LOG_WARNING(Service_HID, "Controller {} type changed while it's connected", |
| 1651 | NpadIdTypeToIndex(npad_id_type)); | 1652 | Service::HID::NpadIdTypeToIndex(npad_id_type)); |
| 1652 | } | 1653 | } |
| 1653 | npad_type = npad_type_; | 1654 | npad_type = npad_type_; |
| 1654 | } | 1655 | } |
diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp index cf53c04d9..2cf25a870 100644 --- a/src/core/hid/hid_core.cpp +++ b/src/core/hid/hid_core.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "core/hid/emulated_controller.h" | 6 | #include "core/hid/emulated_controller.h" |
| 7 | #include "core/hid/emulated_devices.h" | 7 | #include "core/hid/emulated_devices.h" |
| 8 | #include "core/hid/hid_core.h" | 8 | #include "core/hid/hid_core.h" |
| 9 | #include "core/hle/service/hid/hid_util.h" | ||
| 9 | 10 | ||
| 10 | namespace Core::HID { | 11 | namespace Core::HID { |
| 11 | 12 | ||
| @@ -98,11 +99,11 @@ const EmulatedDevices* HIDCore::GetEmulatedDevices() const { | |||
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t index) { | 101 | EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t index) { |
| 101 | return GetEmulatedController(IndexToNpadIdType(index)); | 102 | return GetEmulatedController(Service::HID::IndexToNpadIdType(index)); |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | const EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t index) const { | 105 | const EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t index) const { |
| 105 | return GetEmulatedController(IndexToNpadIdType(index)); | 106 | return GetEmulatedController(Service::HID::IndexToNpadIdType(index)); |
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | void HIDCore::SetSupportedStyleTag(NpadStyleTag style_tag) { | 109 | void HIDCore::SetSupportedStyleTag(NpadStyleTag style_tag) { |
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h index 70fcc6b69..4bf285f36 100644 --- a/src/core/hid/hid_types.h +++ b/src/core/hid/hid_types.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/point.h" | 9 | #include "common/point.h" |
| 10 | #include "common/uuid.h" | 10 | #include "common/uuid.h" |
| 11 | #include "common/vector_math.h" | ||
| 11 | 12 | ||
| 12 | namespace Core::HID { | 13 | namespace Core::HID { |
| 13 | 14 | ||
| @@ -598,6 +599,29 @@ struct SixAxisSensorIcInformation { | |||
| 598 | static_assert(sizeof(SixAxisSensorIcInformation) == 0xC8, | 599 | static_assert(sizeof(SixAxisSensorIcInformation) == 0xC8, |
| 599 | "SixAxisSensorIcInformation is an invalid size"); | 600 | "SixAxisSensorIcInformation is an invalid size"); |
| 600 | 601 | ||
| 602 | // This is nn::hid::SixAxisSensorAttribute | ||
| 603 | struct SixAxisSensorAttribute { | ||
| 604 | union { | ||
| 605 | u32 raw{}; | ||
| 606 | BitField<0, 1, u32> is_connected; | ||
| 607 | BitField<1, 1, u32> is_interpolated; | ||
| 608 | }; | ||
| 609 | }; | ||
| 610 | static_assert(sizeof(SixAxisSensorAttribute) == 4, "SixAxisSensorAttribute is an invalid size"); | ||
| 611 | |||
| 612 | // This is nn::hid::SixAxisSensorState | ||
| 613 | struct SixAxisSensorState { | ||
| 614 | s64 delta_time{}; | ||
| 615 | s64 sampling_number{}; | ||
| 616 | Common::Vec3f accel{}; | ||
| 617 | Common::Vec3f gyro{}; | ||
| 618 | Common::Vec3f rotation{}; | ||
| 619 | std::array<Common::Vec3f, 3> orientation{}; | ||
| 620 | SixAxisSensorAttribute attribute{}; | ||
| 621 | INSERT_PADDING_BYTES(4); // Reserved | ||
| 622 | }; | ||
| 623 | static_assert(sizeof(SixAxisSensorState) == 0x60, "SixAxisSensorState is an invalid size"); | ||
| 624 | |||
| 601 | // This is nn::hid::VibrationDeviceHandle | 625 | // This is nn::hid::VibrationDeviceHandle |
| 602 | struct VibrationDeviceHandle { | 626 | struct VibrationDeviceHandle { |
| 603 | NpadStyleIndex npad_type{NpadStyleIndex::None}; | 627 | NpadStyleIndex npad_type{NpadStyleIndex::None}; |
| @@ -708,60 +732,4 @@ struct UniquePadId { | |||
| 708 | }; | 732 | }; |
| 709 | static_assert(sizeof(UniquePadId) == 0x8, "UniquePadId is an invalid size"); | 733 | static_assert(sizeof(UniquePadId) == 0x8, "UniquePadId is an invalid size"); |
| 710 | 734 | ||
| 711 | /// Converts a NpadIdType to an array index. | ||
| 712 | constexpr size_t NpadIdTypeToIndex(NpadIdType npad_id_type) { | ||
| 713 | switch (npad_id_type) { | ||
| 714 | case NpadIdType::Player1: | ||
| 715 | return 0; | ||
| 716 | case NpadIdType::Player2: | ||
| 717 | return 1; | ||
| 718 | case NpadIdType::Player3: | ||
| 719 | return 2; | ||
| 720 | case NpadIdType::Player4: | ||
| 721 | return 3; | ||
| 722 | case NpadIdType::Player5: | ||
| 723 | return 4; | ||
| 724 | case NpadIdType::Player6: | ||
| 725 | return 5; | ||
| 726 | case NpadIdType::Player7: | ||
| 727 | return 6; | ||
| 728 | case NpadIdType::Player8: | ||
| 729 | return 7; | ||
| 730 | case NpadIdType::Handheld: | ||
| 731 | return 8; | ||
| 732 | case NpadIdType::Other: | ||
| 733 | return 9; | ||
| 734 | default: | ||
| 735 | return 0; | ||
| 736 | } | ||
| 737 | } | ||
| 738 | |||
| 739 | /// Converts an array index to a NpadIdType | ||
| 740 | constexpr NpadIdType IndexToNpadIdType(size_t index) { | ||
| 741 | switch (index) { | ||
| 742 | case 0: | ||
| 743 | return NpadIdType::Player1; | ||
| 744 | case 1: | ||
| 745 | return NpadIdType::Player2; | ||
| 746 | case 2: | ||
| 747 | return NpadIdType::Player3; | ||
| 748 | case 3: | ||
| 749 | return NpadIdType::Player4; | ||
| 750 | case 4: | ||
| 751 | return NpadIdType::Player5; | ||
| 752 | case 5: | ||
| 753 | return NpadIdType::Player6; | ||
| 754 | case 6: | ||
| 755 | return NpadIdType::Player7; | ||
| 756 | case 7: | ||
| 757 | return NpadIdType::Player8; | ||
| 758 | case 8: | ||
| 759 | return NpadIdType::Handheld; | ||
| 760 | case 9: | ||
| 761 | return NpadIdType::Other; | ||
| 762 | default: | ||
| 763 | return NpadIdType::Invalid; | ||
| 764 | } | ||
| 765 | } | ||
| 766 | |||
| 767 | } // namespace Core::HID | 735 | } // namespace Core::HID |
diff --git a/src/core/hid/input_interpreter.cpp b/src/core/hid/input_interpreter.cpp index 11359f318..a6bdd28f2 100644 --- a/src/core/hid/input_interpreter.cpp +++ b/src/core/hid/input_interpreter.cpp | |||
| @@ -13,14 +13,14 @@ InputInterpreter::InputInterpreter(Core::System& system) | |||
| 13 | : npad{system.ServiceManager() | 13 | : npad{system.ServiceManager() |
| 14 | .GetService<Service::HID::IHidServer>("hid") | 14 | .GetService<Service::HID::IHidServer>("hid") |
| 15 | ->GetResourceManager() | 15 | ->GetResourceManager() |
| 16 | ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} { | 16 | ->GetNpad()} { |
| 17 | ResetButtonStates(); | 17 | ResetButtonStates(); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | InputInterpreter::~InputInterpreter() = default; | 20 | InputInterpreter::~InputInterpreter() = default; |
| 21 | 21 | ||
| 22 | void InputInterpreter::PollInput() { | 22 | void InputInterpreter::PollInput() { |
| 23 | const auto button_state = npad.GetAndResetPressState(); | 23 | const auto button_state = npad->GetAndResetPressState(); |
| 24 | 24 | ||
| 25 | previous_index = current_index; | 25 | previous_index = current_index; |
| 26 | current_index = (current_index + 1) % button_states.size(); | 26 | current_index = (current_index + 1) % button_states.size(); |
diff --git a/src/core/hid/input_interpreter.h b/src/core/hid/input_interpreter.h index 8c521b381..3569aac93 100644 --- a/src/core/hid/input_interpreter.h +++ b/src/core/hid/input_interpreter.h | |||
| @@ -16,7 +16,7 @@ enum class NpadButton : u64; | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | namespace Service::HID { | 18 | namespace Service::HID { |
| 19 | class Controller_NPad; | 19 | class NPad; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| @@ -101,7 +101,7 @@ public: | |||
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | private: | 103 | private: |
| 104 | Service::HID::Controller_NPad& npad; | 104 | std::shared_ptr<Service::HID::NPad> npad; |
| 105 | 105 | ||
| 106 | /// Stores 9 consecutive button states polled from HID. | 106 | /// Stores 9 consecutive button states polled from HID. |
| 107 | std::array<Core::HID::NpadButton, 9> button_states{}; | 107 | std::array<Core::HID::NpadButton, 9> button_states{}; |