diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 2 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 4 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 4 | ||||
| -rw-r--r-- | src/core/hid/hid_types.h | 67 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/applet_controller.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/applet_controller.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 498 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 161 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 289 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 4 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player_widget.cpp | 24 |
11 files changed, 632 insertions, 428 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index 864481f52..374dd5d41 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp | |||
| @@ -152,7 +152,7 @@ void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) { | |||
| 152 | motion.rotation = emulated.GetGyroscope(); | 152 | motion.rotation = emulated.GetGyroscope(); |
| 153 | motion.orientation = emulated.GetOrientation(); | 153 | motion.orientation = emulated.GetOrientation(); |
| 154 | motion.quaternion = emulated.GetQuaternion(); | 154 | motion.quaternion = emulated.GetQuaternion(); |
| 155 | motion.is_at_rest = emulated.IsMoving(motion_sensitivity); | 155 | motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); |
| 156 | 156 | ||
| 157 | TriggerOnChange(ConsoleTriggerType::Motion); | 157 | TriggerOnChange(ConsoleTriggerType::Motion); |
| 158 | } | 158 | } |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index a9038e06f..54c1a2324 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -347,7 +347,7 @@ void EmulatedController::RestoreConfig() { | |||
| 347 | } | 347 | } |
| 348 | 348 | ||
| 349 | std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices( | 349 | std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices( |
| 350 | DeviceIndex device_index) const { | 350 | EmulatedDeviceIndex device_index) const { |
| 351 | std::vector<Common::ParamPackage> devices; | 351 | std::vector<Common::ParamPackage> devices; |
| 352 | for (const auto& param : button_params) { | 352 | for (const auto& param : button_params) { |
| 353 | if (!param.Has("engine")) { | 353 | if (!param.Has("engine")) { |
| @@ -704,7 +704,7 @@ void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std:: | |||
| 704 | motion.gyro = emulated.GetGyroscope(); | 704 | motion.gyro = emulated.GetGyroscope(); |
| 705 | motion.rotation = emulated.GetRotations(); | 705 | motion.rotation = emulated.GetRotations(); |
| 706 | motion.orientation = emulated.GetOrientation(); | 706 | motion.orientation = emulated.GetOrientation(); |
| 707 | motion.is_at_rest = emulated.IsMoving(motion_sensitivity); | 707 | motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); |
| 708 | 708 | ||
| 709 | TriggerOnChange(ControllerTriggerType::Motion, true); | 709 | TriggerOnChange(ControllerTriggerType::Motion, true); |
| 710 | } | 710 | } |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index fa2e89c0b..2c5d51bc8 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -81,7 +81,7 @@ struct ControllerMotion { | |||
| 81 | bool is_at_rest{}; | 81 | bool is_at_rest{}; |
| 82 | }; | 82 | }; |
| 83 | 83 | ||
| 84 | enum DeviceIndex : u8 { | 84 | enum EmulatedDeviceIndex : u8 { |
| 85 | LeftIndex, | 85 | LeftIndex, |
| 86 | RightIndex, | 86 | RightIndex, |
| 87 | DualIndex, | 87 | DualIndex, |
| @@ -202,7 +202,7 @@ public: | |||
| 202 | void RestoreConfig(); | 202 | void RestoreConfig(); |
| 203 | 203 | ||
| 204 | /// Returns a vector of mapped devices from the mapped button and stick parameters | 204 | /// Returns a vector of mapped devices from the mapped button and stick parameters |
| 205 | std::vector<Common::ParamPackage> GetMappedDevices(DeviceIndex device_index) const; | 205 | std::vector<Common::ParamPackage> GetMappedDevices(EmulatedDeviceIndex device_index) const; |
| 206 | 206 | ||
| 207 | // Returns the current mapped button device | 207 | // Returns the current mapped button device |
| 208 | Common::ParamPackage GetButtonParam(std::size_t index) const; | 208 | Common::ParamPackage GetButtonParam(std::size_t index) const; |
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h index 22177b5ed..f224cb744 100644 --- a/src/core/hid/hid_types.h +++ b/src/core/hid/hid_types.h | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | namespace Core::HID { | 13 | namespace Core::HID { |
| 14 | 14 | ||
| 15 | // This is nn::hid::NpadIdType | 15 | // This is nn::hid::NpadIdType |
| 16 | enum class NpadIdType : u8 { | 16 | enum class NpadIdType : u32 { |
| 17 | Player1 = 0x0, | 17 | Player1 = 0x0, |
| 18 | Player2 = 0x1, | 18 | Player2 = 0x1, |
| 19 | Player3 = 0x2, | 19 | Player3 = 0x2, |
| @@ -25,7 +25,7 @@ enum class NpadIdType : u8 { | |||
| 25 | Other = 0x10, | 25 | Other = 0x10, |
| 26 | Handheld = 0x20, | 26 | Handheld = 0x20, |
| 27 | 27 | ||
| 28 | Invalid = 0xFF, | 28 | Invalid = 0xFFFFFFFF, |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | /// Converts a NpadIdType to an array index. | 31 | /// Converts a NpadIdType to an array index. |
| @@ -104,10 +104,30 @@ enum class NpadStyleIndex : u8 { | |||
| 104 | MaxNpadType = 34, | 104 | MaxNpadType = 34, |
| 105 | }; | 105 | }; |
| 106 | 106 | ||
| 107 | // This is nn::hid::NpadStyleSet | ||
| 108 | enum class NpadStyleSet : u32 { | ||
| 109 | None = 0, | ||
| 110 | Fullkey = 1U << 0, | ||
| 111 | Handheld = 1U << 1, | ||
| 112 | JoyDual = 1U << 2, | ||
| 113 | JoyLeft = 1U << 3, | ||
| 114 | JoyRight = 1U << 4, | ||
| 115 | Gc = 1U << 5, | ||
| 116 | Palma = 1U << 6, | ||
| 117 | Lark = 1U << 7, | ||
| 118 | HandheldLark = 1U << 8, | ||
| 119 | Lucia = 1U << 9, | ||
| 120 | Lagoon = 1U << 10, | ||
| 121 | Lager = 1U << 11, | ||
| 122 | SystemExt = 1U << 29, | ||
| 123 | System = 1U << 30, | ||
| 124 | }; | ||
| 125 | static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size"); | ||
| 126 | |||
| 107 | // This is nn::hid::NpadStyleTag | 127 | // This is nn::hid::NpadStyleTag |
| 108 | struct NpadStyleTag { | 128 | struct NpadStyleTag { |
| 109 | union { | 129 | union { |
| 110 | u32 raw{}; | 130 | NpadStyleSet raw{}; |
| 111 | 131 | ||
| 112 | BitField<0, 1, u32> fullkey; | 132 | BitField<0, 1, u32> fullkey; |
| 113 | BitField<1, 1, u32> handheld; | 133 | BitField<1, 1, u32> handheld; |
| @@ -322,6 +342,47 @@ struct DebugPadButton { | |||
| 322 | }; | 342 | }; |
| 323 | static_assert(sizeof(DebugPadButton) == 0x4, "DebugPadButton is an invalid size"); | 343 | static_assert(sizeof(DebugPadButton) == 0x4, "DebugPadButton is an invalid size"); |
| 324 | 344 | ||
| 345 | enum class DeviceIndex : u8 { | ||
| 346 | Left = 0, | ||
| 347 | Right = 1, | ||
| 348 | None = 2, | ||
| 349 | MaxDeviceIndex = 3, | ||
| 350 | }; | ||
| 351 | |||
| 352 | // This is nn::hid::ConsoleSixAxisSensorHandle | ||
| 353 | struct ConsoleSixAxisSensorHandle { | ||
| 354 | u8 unknown_1; | ||
| 355 | u8 unknown_2; | ||
| 356 | INSERT_PADDING_BYTES_NOINIT(2); | ||
| 357 | }; | ||
| 358 | static_assert(sizeof(ConsoleSixAxisSensorHandle) == 4, | ||
| 359 | "ConsoleSixAxisSensorHandle is an invalid size"); | ||
| 360 | |||
| 361 | // This is nn::hid::SixAxisSensorHandle | ||
| 362 | struct SixAxisSensorHandle { | ||
| 363 | NpadStyleIndex npad_type; | ||
| 364 | u8 npad_id; | ||
| 365 | DeviceIndex device_index; | ||
| 366 | INSERT_PADDING_BYTES_NOINIT(1); | ||
| 367 | }; | ||
| 368 | static_assert(sizeof(SixAxisSensorHandle) == 4, "SixAxisSensorHandle is an invalid size"); | ||
| 369 | |||
| 370 | struct SixAxisSensorFusionParameters { | ||
| 371 | f32 parameter1; | ||
| 372 | f32 parameter2; | ||
| 373 | }; | ||
| 374 | static_assert(sizeof(SixAxisSensorFusionParameters) == 8, | ||
| 375 | "SixAxisSensorFusionParameters is an invalid size"); | ||
| 376 | |||
| 377 | // This is nn::hid::VibrationDeviceHandle | ||
| 378 | struct VibrationDeviceHandle { | ||
| 379 | NpadStyleIndex npad_type; | ||
| 380 | u8 npad_id; | ||
| 381 | DeviceIndex device_index; | ||
| 382 | INSERT_PADDING_BYTES_NOINIT(1); | ||
| 383 | }; | ||
| 384 | static_assert(sizeof(VibrationDeviceHandle) == 4, "SixAxisSensorHandle is an invalid size"); | ||
| 385 | |||
| 325 | // This is nn::hid::VibrationDeviceType | 386 | // This is nn::hid::VibrationDeviceType |
| 326 | enum class VibrationDeviceType : u32 { | 387 | enum class VibrationDeviceType : u32 { |
| 327 | Unknown = 0, | 388 | Unknown = 0, |
diff --git a/src/core/hle/service/am/applets/applet_controller.cpp b/src/core/hle/service/am/applets/applet_controller.cpp index 374e0c7f4..d073f2210 100644 --- a/src/core/hle/service/am/applets/applet_controller.cpp +++ b/src/core/hle/service/am/applets/applet_controller.cpp | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "core/frontend/applets/controller.h" | 12 | #include "core/frontend/applets/controller.h" |
| 13 | #include "core/hid/emulated_controller.h" | 13 | #include "core/hid/emulated_controller.h" |
| 14 | #include "core/hid/hid_core.h" | 14 | #include "core/hid/hid_core.h" |
| 15 | #include "core/hid/hid_types.h" | ||
| 15 | #include "core/hle/result.h" | 16 | #include "core/hle/result.h" |
| 16 | #include "core/hle/service/am/am.h" | 17 | #include "core/hle/service/am/am.h" |
| 17 | #include "core/hle/service/am/applets/applet_controller.h" | 18 | #include "core/hle/service/am/applets/applet_controller.h" |
diff --git a/src/core/hle/service/am/applets/applet_controller.h b/src/core/hle/service/am/applets/applet_controller.h index 0a34c4fc0..1a832505e 100644 --- a/src/core/hle/service/am/applets/applet_controller.h +++ b/src/core/hle/service/am/applets/applet_controller.h | |||
| @@ -16,6 +16,10 @@ namespace Core { | |||
| 16 | class System; | 16 | class System; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | namespace Core::HID { | ||
| 20 | enum class NpadStyleSet : u32; | ||
| 21 | } | ||
| 22 | |||
| 19 | namespace Service::AM::Applets { | 23 | namespace Service::AM::Applets { |
| 20 | 24 | ||
| 21 | using IdentificationColor = std::array<u8, 4>; | 25 | using IdentificationColor = std::array<u8, 4>; |
| @@ -52,7 +56,7 @@ struct ControllerSupportArgPrivate { | |||
| 52 | bool flag_1{}; | 56 | bool flag_1{}; |
| 53 | ControllerSupportMode mode{}; | 57 | ControllerSupportMode mode{}; |
| 54 | ControllerSupportCaller caller{}; | 58 | ControllerSupportCaller caller{}; |
| 55 | u32 style_set{}; | 59 | Core::HID::NpadStyleSet style_set{}; |
| 56 | u32 joy_hold_type{}; | 60 | u32 joy_hold_type{}; |
| 57 | }; | 61 | }; |
| 58 | static_assert(sizeof(ControllerSupportArgPrivate) == 0x14, | 62 | static_assert(sizeof(ControllerSupportArgPrivate) == 0x14, |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index b97e575f3..eaec79139 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -21,68 +21,25 @@ | |||
| 21 | 21 | ||
| 22 | namespace Service::HID { | 22 | namespace Service::HID { |
| 23 | constexpr std::size_t NPAD_OFFSET = 0x9A00; | 23 | constexpr std::size_t NPAD_OFFSET = 0x9A00; |
| 24 | constexpr u32 MAX_NPAD_ID = 7; | 24 | constexpr std::array<Core::HID::NpadIdType, 10> npad_id_list{ |
| 25 | constexpr std::size_t HANDHELD_INDEX = 8; | 25 | Core::HID::NpadIdType::Player1, Core::HID::NpadIdType::Player2, Core::HID::NpadIdType::Player3, |
| 26 | constexpr std::array<u32, 10> npad_id_list{ | 26 | Core::HID::NpadIdType::Player4, Core::HID::NpadIdType::Player5, Core::HID::NpadIdType::Player6, |
| 27 | 0, 1, 2, 3, 4, 5, 6, 7, NPAD_HANDHELD, NPAD_UNKNOWN, | 27 | Core::HID::NpadIdType::Player7, Core::HID::NpadIdType::Player8, Core::HID::NpadIdType::Other, |
| 28 | Core::HID::NpadIdType::Handheld, | ||
| 28 | }; | 29 | }; |
| 29 | 30 | ||
| 30 | std::size_t Controller_NPad::NPadIdToIndex(u32 npad_id) { | 31 | bool Controller_NPad::IsNpadIdValid(Core::HID::NpadIdType npad_id) { |
| 31 | switch (npad_id) { | 32 | switch (npad_id) { |
| 32 | case 0: | 33 | case Core::HID::NpadIdType::Player1: |
| 33 | case 1: | 34 | case Core::HID::NpadIdType::Player2: |
| 34 | case 2: | 35 | case Core::HID::NpadIdType::Player3: |
| 35 | case 3: | 36 | case Core::HID::NpadIdType::Player4: |
| 36 | case 4: | 37 | case Core::HID::NpadIdType::Player5: |
| 37 | case 5: | 38 | case Core::HID::NpadIdType::Player6: |
| 38 | case 6: | 39 | case Core::HID::NpadIdType::Player7: |
| 39 | case 7: | 40 | case Core::HID::NpadIdType::Player8: |
| 40 | return npad_id; | 41 | case Core::HID::NpadIdType::Other: |
| 41 | case HANDHELD_INDEX: | 42 | case Core::HID::NpadIdType::Handheld: |
| 42 | case NPAD_HANDHELD: | ||
| 43 | return HANDHELD_INDEX; | ||
| 44 | case 9: | ||
| 45 | case NPAD_UNKNOWN: | ||
| 46 | return 9; | ||
| 47 | default: | ||
| 48 | UNIMPLEMENTED_MSG("Unknown npad id {}", npad_id); | ||
| 49 | return 0; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | u32 Controller_NPad::IndexToNPad(std::size_t index) { | ||
| 54 | switch (index) { | ||
| 55 | case 0: | ||
| 56 | case 1: | ||
| 57 | case 2: | ||
| 58 | case 3: | ||
| 59 | case 4: | ||
| 60 | case 5: | ||
| 61 | case 6: | ||
| 62 | case 7: | ||
| 63 | return static_cast<u32>(index); | ||
| 64 | case HANDHELD_INDEX: | ||
| 65 | return NPAD_HANDHELD; | ||
| 66 | case 9: | ||
| 67 | return NPAD_UNKNOWN; | ||
| 68 | default: | ||
| 69 | UNIMPLEMENTED_MSG("Unknown npad index {}", index); | ||
| 70 | return 0; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | bool Controller_NPad::IsNpadIdValid(u32 npad_id) { | ||
| 75 | switch (npad_id) { | ||
| 76 | case 0: | ||
| 77 | case 1: | ||
| 78 | case 2: | ||
| 79 | case 3: | ||
| 80 | case 4: | ||
| 81 | case 5: | ||
| 82 | case 6: | ||
| 83 | case 7: | ||
| 84 | case NPAD_UNKNOWN: | ||
| 85 | case NPAD_HANDHELD: | ||
| 86 | return true; | 43 | return true; |
| 87 | default: | 44 | default: |
| 88 | LOG_ERROR(Service_HID, "Invalid npad id {}", npad_id); | 45 | LOG_ERROR(Service_HID, "Invalid npad id {}", npad_id); |
| @@ -90,10 +47,16 @@ bool Controller_NPad::IsNpadIdValid(u32 npad_id) { | |||
| 90 | } | 47 | } |
| 91 | } | 48 | } |
| 92 | 49 | ||
| 93 | bool Controller_NPad::IsDeviceHandleValid(const DeviceHandle& device_handle) { | 50 | bool Controller_NPad::IsDeviceHandleValid(const Core::HID::VibrationDeviceHandle& device_handle) { |
| 94 | return IsNpadIdValid(device_handle.npad_id) && | 51 | return IsNpadIdValid(static_cast<Core::HID::NpadIdType>(device_handle.npad_id)) && |
| 52 | device_handle.npad_type < Core::HID::NpadStyleIndex::MaxNpadType && | ||
| 53 | device_handle.device_index < Core::HID::DeviceIndex::MaxDeviceIndex; | ||
| 54 | } | ||
| 55 | |||
| 56 | bool Controller_NPad::IsDeviceHandleValid(const Core::HID::SixAxisSensorHandle& device_handle) { | ||
| 57 | return IsNpadIdValid(static_cast<Core::HID::NpadIdType>(device_handle.npad_id)) && | ||
| 95 | device_handle.npad_type < Core::HID::NpadStyleIndex::MaxNpadType && | 58 | device_handle.npad_type < Core::HID::NpadStyleIndex::MaxNpadType && |
| 96 | device_handle.device_index < DeviceIndex::MaxDeviceIndex; | 59 | device_handle.device_index < Core::HID::DeviceIndex::MaxDeviceIndex; |
| 97 | } | 60 | } |
| 98 | 61 | ||
| 99 | Controller_NPad::Controller_NPad(Core::HID::HIDCore& hid_core_, | 62 | Controller_NPad::Controller_NPad(Core::HID::HIDCore& hid_core_, |
| @@ -102,9 +65,9 @@ Controller_NPad::Controller_NPad(Core::HID::HIDCore& hid_core_, | |||
| 102 | for (std::size_t i = 0; i < controller_data.size(); ++i) { | 65 | for (std::size_t i = 0; i < controller_data.size(); ++i) { |
| 103 | auto& controller = controller_data[i]; | 66 | auto& controller = controller_data[i]; |
| 104 | controller.device = hid_core.GetEmulatedControllerByIndex(i); | 67 | controller.device = hid_core.GetEmulatedControllerByIndex(i); |
| 105 | controller.vibration[Core::HID::DeviceIndex::LeftIndex].latest_vibration_value = | 68 | controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value = |
| 106 | DEFAULT_VIBRATION_VALUE; | 69 | DEFAULT_VIBRATION_VALUE; |
| 107 | controller.vibration[Core::HID::DeviceIndex::RightIndex].latest_vibration_value = | 70 | controller.vibration[Core::HID::EmulatedDeviceIndex::RightIndex].latest_vibration_value = |
| 108 | DEFAULT_VIBRATION_VALUE; | 71 | DEFAULT_VIBRATION_VALUE; |
| 109 | Core::HID::ControllerUpdateCallback engine_callback{ | 72 | Core::HID::ControllerUpdateCallback engine_callback{ |
| 110 | .on_change = [this, | 73 | .on_change = [this, |
| @@ -130,17 +93,21 @@ void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, | |||
| 130 | ControllerUpdate(Core::HID::ControllerTriggerType::Battery, controller_idx); | 93 | ControllerUpdate(Core::HID::ControllerTriggerType::Battery, controller_idx); |
| 131 | return; | 94 | return; |
| 132 | } | 95 | } |
| 96 | if (controller_idx >= controller_data.size()) { | ||
| 97 | return; | ||
| 98 | } | ||
| 133 | 99 | ||
| 134 | auto& controller = controller_data[controller_idx]; | 100 | auto& controller = controller_data[controller_idx]; |
| 135 | const auto is_connected = controller.device->IsConnected(); | 101 | const auto is_connected = controller.device->IsConnected(); |
| 136 | const auto npad_type = controller.device->GetNpadStyleIndex(); | 102 | const auto npad_type = controller.device->GetNpadStyleIndex(); |
| 103 | const auto npad_id = controller.device->GetNpadIdType(); | ||
| 137 | switch (type) { | 104 | switch (type) { |
| 138 | case Core::HID::ControllerTriggerType::Connected: | 105 | case Core::HID::ControllerTriggerType::Connected: |
| 139 | case Core::HID::ControllerTriggerType::Disconnected: | 106 | case Core::HID::ControllerTriggerType::Disconnected: |
| 140 | if (is_connected == controller.is_connected) { | 107 | if (is_connected == controller.is_connected) { |
| 141 | return; | 108 | return; |
| 142 | } | 109 | } |
| 143 | UpdateControllerAt(npad_type, controller_idx, is_connected); | 110 | UpdateControllerAt(npad_type, npad_id, is_connected); |
| 144 | break; | 111 | break; |
| 145 | case Core::HID::ControllerTriggerType::Battery: { | 112 | case Core::HID::ControllerTriggerType::Battery: { |
| 146 | if (!controller.is_connected) { | 113 | if (!controller.is_connected) { |
| @@ -158,15 +125,16 @@ void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, | |||
| 158 | } | 125 | } |
| 159 | } | 126 | } |
| 160 | 127 | ||
| 161 | void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | 128 | void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { |
| 162 | auto& controller = controller_data[controller_idx]; | 129 | LOG_DEBUG(Service_HID, "Npad connected {}", npad_id); |
| 130 | auto& controller = GetControllerFromNpadIdType(npad_id); | ||
| 163 | const auto controller_type = controller.device->GetNpadStyleIndex(); | 131 | const auto controller_type = controller.device->GetNpadStyleIndex(); |
| 164 | auto& shared_memory = controller.shared_memory_entry; | 132 | auto& shared_memory = controller.shared_memory_entry; |
| 165 | if (controller_type == Core::HID::NpadStyleIndex::None) { | 133 | if (controller_type == Core::HID::NpadStyleIndex::None) { |
| 166 | controller.styleset_changed_event->GetWritableEvent().Signal(); | 134 | controller.styleset_changed_event->GetWritableEvent().Signal(); |
| 167 | return; | 135 | return; |
| 168 | } | 136 | } |
| 169 | shared_memory.style_set.raw = 0; // Zero out | 137 | shared_memory.style_tag.raw = Core::HID::NpadStyleSet::None; |
| 170 | shared_memory.device_type.raw = 0; | 138 | shared_memory.device_type.raw = 0; |
| 171 | shared_memory.system_properties.raw = 0; | 139 | shared_memory.system_properties.raw = 0; |
| 172 | switch (controller_type) { | 140 | switch (controller_type) { |
| @@ -174,7 +142,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | |||
| 174 | UNREACHABLE(); | 142 | UNREACHABLE(); |
| 175 | break; | 143 | break; |
| 176 | case Core::HID::NpadStyleIndex::ProController: | 144 | case Core::HID::NpadStyleIndex::ProController: |
| 177 | shared_memory.style_set.fullkey.Assign(1); | 145 | shared_memory.style_tag.fullkey.Assign(1); |
| 178 | shared_memory.device_type.fullkey.Assign(1); | 146 | shared_memory.device_type.fullkey.Assign(1); |
| 179 | shared_memory.system_properties.is_vertical.Assign(1); | 147 | shared_memory.system_properties.is_vertical.Assign(1); |
| 180 | shared_memory.system_properties.use_plus.Assign(1); | 148 | shared_memory.system_properties.use_plus.Assign(1); |
| @@ -183,7 +151,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | |||
| 183 | shared_memory.applet_footer.type = AppletFooterUiType::SwitchProController; | 151 | shared_memory.applet_footer.type = AppletFooterUiType::SwitchProController; |
| 184 | break; | 152 | break; |
| 185 | case Core::HID::NpadStyleIndex::Handheld: | 153 | case Core::HID::NpadStyleIndex::Handheld: |
| 186 | shared_memory.style_set.handheld.Assign(1); | 154 | shared_memory.style_tag.handheld.Assign(1); |
| 187 | shared_memory.device_type.handheld_left.Assign(1); | 155 | shared_memory.device_type.handheld_left.Assign(1); |
| 188 | shared_memory.device_type.handheld_right.Assign(1); | 156 | shared_memory.device_type.handheld_right.Assign(1); |
| 189 | shared_memory.system_properties.is_vertical.Assign(1); | 157 | shared_memory.system_properties.is_vertical.Assign(1); |
| @@ -193,7 +161,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | |||
| 193 | shared_memory.applet_footer.type = AppletFooterUiType::HandheldJoyConLeftJoyConRight; | 161 | shared_memory.applet_footer.type = AppletFooterUiType::HandheldJoyConLeftJoyConRight; |
| 194 | break; | 162 | break; |
| 195 | case Core::HID::NpadStyleIndex::JoyconDual: | 163 | case Core::HID::NpadStyleIndex::JoyconDual: |
| 196 | shared_memory.style_set.joycon_dual.Assign(1); | 164 | shared_memory.style_tag.joycon_dual.Assign(1); |
| 197 | shared_memory.device_type.joycon_left.Assign(1); | 165 | shared_memory.device_type.joycon_left.Assign(1); |
| 198 | shared_memory.device_type.joycon_right.Assign(1); | 166 | shared_memory.device_type.joycon_right.Assign(1); |
| 199 | shared_memory.system_properties.is_vertical.Assign(1); | 167 | shared_memory.system_properties.is_vertical.Assign(1); |
| @@ -203,7 +171,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | |||
| 203 | shared_memory.applet_footer.type = AppletFooterUiType::JoyDual; | 171 | shared_memory.applet_footer.type = AppletFooterUiType::JoyDual; |
| 204 | break; | 172 | break; |
| 205 | case Core::HID::NpadStyleIndex::JoyconLeft: | 173 | case Core::HID::NpadStyleIndex::JoyconLeft: |
| 206 | shared_memory.style_set.joycon_left.Assign(1); | 174 | shared_memory.style_tag.joycon_left.Assign(1); |
| 207 | shared_memory.device_type.joycon_left.Assign(1); | 175 | shared_memory.device_type.joycon_left.Assign(1); |
| 208 | shared_memory.system_properties.is_horizontal.Assign(1); | 176 | shared_memory.system_properties.is_horizontal.Assign(1); |
| 209 | shared_memory.system_properties.use_minus.Assign(1); | 177 | shared_memory.system_properties.use_minus.Assign(1); |
| @@ -211,7 +179,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | |||
| 211 | shared_memory.applet_footer.type = AppletFooterUiType::JoyLeftHorizontal; | 179 | shared_memory.applet_footer.type = AppletFooterUiType::JoyLeftHorizontal; |
| 212 | break; | 180 | break; |
| 213 | case Core::HID::NpadStyleIndex::JoyconRight: | 181 | case Core::HID::NpadStyleIndex::JoyconRight: |
| 214 | shared_memory.style_set.joycon_right.Assign(1); | 182 | shared_memory.style_tag.joycon_right.Assign(1); |
| 215 | shared_memory.device_type.joycon_right.Assign(1); | 183 | shared_memory.device_type.joycon_right.Assign(1); |
| 216 | shared_memory.system_properties.is_horizontal.Assign(1); | 184 | shared_memory.system_properties.is_horizontal.Assign(1); |
| 217 | shared_memory.system_properties.use_plus.Assign(1); | 185 | shared_memory.system_properties.use_plus.Assign(1); |
| @@ -219,32 +187,32 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | |||
| 219 | shared_memory.applet_footer.type = AppletFooterUiType::JoyRightHorizontal; | 187 | shared_memory.applet_footer.type = AppletFooterUiType::JoyRightHorizontal; |
| 220 | break; | 188 | break; |
| 221 | case Core::HID::NpadStyleIndex::GameCube: | 189 | case Core::HID::NpadStyleIndex::GameCube: |
| 222 | shared_memory.style_set.gamecube.Assign(1); | 190 | shared_memory.style_tag.gamecube.Assign(1); |
| 223 | shared_memory.device_type.fullkey.Assign(1); | 191 | shared_memory.device_type.fullkey.Assign(1); |
| 224 | shared_memory.system_properties.is_vertical.Assign(1); | 192 | shared_memory.system_properties.is_vertical.Assign(1); |
| 225 | shared_memory.system_properties.use_plus.Assign(1); | 193 | shared_memory.system_properties.use_plus.Assign(1); |
| 226 | break; | 194 | break; |
| 227 | case Core::HID::NpadStyleIndex::Pokeball: | 195 | case Core::HID::NpadStyleIndex::Pokeball: |
| 228 | shared_memory.style_set.palma.Assign(1); | 196 | shared_memory.style_tag.palma.Assign(1); |
| 229 | shared_memory.device_type.palma.Assign(1); | 197 | shared_memory.device_type.palma.Assign(1); |
| 230 | shared_memory.assignment_mode = NpadJoyAssignmentMode::Single; | 198 | shared_memory.assignment_mode = NpadJoyAssignmentMode::Single; |
| 231 | break; | 199 | break; |
| 232 | case Core::HID::NpadStyleIndex::NES: | 200 | case Core::HID::NpadStyleIndex::NES: |
| 233 | shared_memory.style_set.lark.Assign(1); | 201 | shared_memory.style_tag.lark.Assign(1); |
| 234 | shared_memory.device_type.fullkey.Assign(1); | 202 | shared_memory.device_type.fullkey.Assign(1); |
| 235 | break; | 203 | break; |
| 236 | case Core::HID::NpadStyleIndex::SNES: | 204 | case Core::HID::NpadStyleIndex::SNES: |
| 237 | shared_memory.style_set.lucia.Assign(1); | 205 | shared_memory.style_tag.lucia.Assign(1); |
| 238 | shared_memory.device_type.fullkey.Assign(1); | 206 | shared_memory.device_type.fullkey.Assign(1); |
| 239 | shared_memory.applet_footer.type = AppletFooterUiType::Lucia; | 207 | shared_memory.applet_footer.type = AppletFooterUiType::Lucia; |
| 240 | break; | 208 | break; |
| 241 | case Core::HID::NpadStyleIndex::N64: | 209 | case Core::HID::NpadStyleIndex::N64: |
| 242 | shared_memory.style_set.lagoon.Assign(1); | 210 | shared_memory.style_tag.lagoon.Assign(1); |
| 243 | shared_memory.device_type.fullkey.Assign(1); | 211 | shared_memory.device_type.fullkey.Assign(1); |
| 244 | shared_memory.applet_footer.type = AppletFooterUiType::Lagon; | 212 | shared_memory.applet_footer.type = AppletFooterUiType::Lagon; |
| 245 | break; | 213 | break; |
| 246 | case Core::HID::NpadStyleIndex::SegaGenesis: | 214 | case Core::HID::NpadStyleIndex::SegaGenesis: |
| 247 | shared_memory.style_set.lager.Assign(1); | 215 | shared_memory.style_tag.lager.Assign(1); |
| 248 | shared_memory.device_type.fullkey.Assign(1); | 216 | shared_memory.device_type.fullkey.Assign(1); |
| 249 | break; | 217 | break; |
| 250 | default: | 218 | default: |
| @@ -268,7 +236,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | |||
| 268 | 236 | ||
| 269 | controller.is_connected = true; | 237 | controller.is_connected = true; |
| 270 | controller.device->Connect(); | 238 | controller.device->Connect(); |
| 271 | SignalStyleSetChangedEvent(IndexToNPad(controller_idx)); | 239 | SignalStyleSetChangedEvent(npad_id); |
| 272 | WriteEmptyEntry(controller.shared_memory_entry); | 240 | WriteEmptyEntry(controller.shared_memory_entry); |
| 273 | } | 241 | } |
| 274 | 242 | ||
| @@ -283,7 +251,7 @@ void Controller_NPad::OnInit() { | |||
| 283 | service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i)); | 251 | service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i)); |
| 284 | } | 252 | } |
| 285 | 253 | ||
| 286 | if (hid_core.GetSupportedStyleTag().raw == 0) { | 254 | if (hid_core.GetSupportedStyleTag().raw == Core::HID::NpadStyleSet::None) { |
| 287 | // We want to support all controllers | 255 | // We want to support all controllers |
| 288 | Core::HID::NpadStyleTag style{}; | 256 | Core::HID::NpadStyleTag style{}; |
| 289 | style.handheld.Assign(1); | 257 | style.handheld.Assign(1); |
| @@ -298,7 +266,7 @@ void Controller_NPad::OnInit() { | |||
| 298 | 266 | ||
| 299 | supported_npad_id_types.resize(npad_id_list.size()); | 267 | supported_npad_id_types.resize(npad_id_list.size()); |
| 300 | std::memcpy(supported_npad_id_types.data(), npad_id_list.data(), | 268 | std::memcpy(supported_npad_id_types.data(), npad_id_list.data(), |
| 301 | npad_id_list.size() * sizeof(u32)); | 269 | npad_id_list.size() * sizeof(Core::HID::NpadIdType)); |
| 302 | 270 | ||
| 303 | // Prefill controller buffers | 271 | // Prefill controller buffers |
| 304 | for (auto& controller : controller_data) { | 272 | for (auto& controller : controller_data) { |
| @@ -322,8 +290,7 @@ void Controller_NPad::OnInit() { | |||
| 322 | for (auto& controller : controller_data) { | 290 | for (auto& controller : controller_data) { |
| 323 | const auto& device = controller.device; | 291 | const auto& device = controller.device; |
| 324 | if (device->IsConnected()) { | 292 | if (device->IsConnected()) { |
| 325 | const std::size_t index = Core::HID::NpadIdTypeToIndex(device->GetNpadIdType()); | 293 | AddNewControllerAt(device->GetNpadStyleIndex(), device->GetNpadIdType()); |
| 326 | AddNewControllerAt(device->GetNpadStyleIndex(), index); | ||
| 327 | } | 294 | } |
| 328 | } | 295 | } |
| 329 | } | 296 | } |
| @@ -354,15 +321,14 @@ void Controller_NPad::OnRelease() { | |||
| 354 | auto& controller = controller_data[i]; | 321 | auto& controller = controller_data[i]; |
| 355 | service_context.CloseEvent(controller.styleset_changed_event); | 322 | service_context.CloseEvent(controller.styleset_changed_event); |
| 356 | for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { | 323 | for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { |
| 357 | VibrateControllerAtIndex(i, device_idx, {}); | 324 | VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_idx, {}); |
| 358 | } | 325 | } |
| 359 | } | 326 | } |
| 360 | } | 327 | } |
| 361 | 328 | ||
| 362 | void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { | 329 | void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { |
| 363 | std::lock_guard lock{mutex}; | 330 | std::lock_guard lock{mutex}; |
| 364 | const auto controller_idx = NPadIdToIndex(npad_id); | 331 | auto& controller = GetControllerFromNpadIdType(npad_id); |
| 365 | auto& controller = controller_data[controller_idx]; | ||
| 366 | const auto controller_type = controller.device->GetNpadStyleIndex(); | 332 | const auto controller_type = controller.device->GetNpadStyleIndex(); |
| 367 | if (!controller.device->IsConnected()) { | 333 | if (!controller.device->IsConnected()) { |
| 368 | return; | 334 | return; |
| @@ -431,9 +397,8 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 431 | &controller.shared_memory_entry, sizeof(NpadInternalState)); | 397 | &controller.shared_memory_entry, sizeof(NpadInternalState)); |
| 432 | continue; | 398 | continue; |
| 433 | } | 399 | } |
| 434 | const u32 npad_index = static_cast<u32>(i); | ||
| 435 | 400 | ||
| 436 | RequestPadStateUpdate(npad_index); | 401 | RequestPadStateUpdate(controller.device->GetNpadIdType()); |
| 437 | auto& pad_state = controller.npad_pad_state; | 402 | auto& pad_state = controller.npad_pad_state; |
| 438 | auto& libnx_state = controller.npad_libnx_state; | 403 | auto& libnx_state = controller.npad_libnx_state; |
| 439 | auto& trigger_state = controller.npad_trigger_state; | 404 | auto& trigger_state = controller.npad_trigger_state; |
| @@ -571,10 +536,11 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 571 | auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; | 536 | auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; |
| 572 | auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; | 537 | auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; |
| 573 | 538 | ||
| 574 | if (sixaxis_sensors_enabled && Settings::values.motion_enabled.GetValue()) { | 539 | if (controller.sixaxis_sensor_enabled && Settings::values.motion_enabled.GetValue()) { |
| 575 | sixaxis_at_rest = true; | 540 | controller.sixaxis_at_rest = true; |
| 576 | for (std::size_t e = 0; e < motion_state.size(); ++e) { | 541 | for (std::size_t e = 0; e < motion_state.size(); ++e) { |
| 577 | sixaxis_at_rest = sixaxis_at_rest && motion_state[e].is_at_rest; | 542 | controller.sixaxis_at_rest = |
| 543 | controller.sixaxis_at_rest && motion_state[e].is_at_rest; | ||
| 578 | } | 544 | } |
| 579 | } | 545 | } |
| 580 | 546 | ||
| @@ -584,7 +550,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 584 | break; | 550 | break; |
| 585 | case Core::HID::NpadStyleIndex::ProController: | 551 | case Core::HID::NpadStyleIndex::ProController: |
| 586 | sixaxis_fullkey_state.attribute.raw = 0; | 552 | sixaxis_fullkey_state.attribute.raw = 0; |
| 587 | if (sixaxis_sensors_enabled) { | 553 | if (controller.sixaxis_sensor_enabled) { |
| 588 | sixaxis_fullkey_state.attribute.is_connected.Assign(1); | 554 | sixaxis_fullkey_state.attribute.is_connected.Assign(1); |
| 589 | sixaxis_fullkey_state.accel = motion_state[0].accel; | 555 | sixaxis_fullkey_state.accel = motion_state[0].accel; |
| 590 | sixaxis_fullkey_state.gyro = motion_state[0].gyro; | 556 | sixaxis_fullkey_state.gyro = motion_state[0].gyro; |
| @@ -594,7 +560,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 594 | break; | 560 | break; |
| 595 | case Core::HID::NpadStyleIndex::Handheld: | 561 | case Core::HID::NpadStyleIndex::Handheld: |
| 596 | sixaxis_handheld_state.attribute.raw = 0; | 562 | sixaxis_handheld_state.attribute.raw = 0; |
| 597 | if (sixaxis_sensors_enabled) { | 563 | if (controller.sixaxis_sensor_enabled) { |
| 598 | sixaxis_handheld_state.attribute.is_connected.Assign(1); | 564 | sixaxis_handheld_state.attribute.is_connected.Assign(1); |
| 599 | sixaxis_handheld_state.accel = motion_state[0].accel; | 565 | sixaxis_handheld_state.accel = motion_state[0].accel; |
| 600 | sixaxis_handheld_state.gyro = motion_state[0].gyro; | 566 | sixaxis_handheld_state.gyro = motion_state[0].gyro; |
| @@ -605,7 +571,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 605 | case Core::HID::NpadStyleIndex::JoyconDual: | 571 | case Core::HID::NpadStyleIndex::JoyconDual: |
| 606 | sixaxis_dual_left_state.attribute.raw = 0; | 572 | sixaxis_dual_left_state.attribute.raw = 0; |
| 607 | sixaxis_dual_right_state.attribute.raw = 0; | 573 | sixaxis_dual_right_state.attribute.raw = 0; |
| 608 | if (sixaxis_sensors_enabled) { | 574 | if (controller.sixaxis_sensor_enabled) { |
| 609 | // Set motion for the left joycon | 575 | // Set motion for the left joycon |
| 610 | sixaxis_dual_left_state.attribute.is_connected.Assign(1); | 576 | sixaxis_dual_left_state.attribute.is_connected.Assign(1); |
| 611 | sixaxis_dual_left_state.accel = motion_state[0].accel; | 577 | sixaxis_dual_left_state.accel = motion_state[0].accel; |
| @@ -613,7 +579,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 613 | sixaxis_dual_left_state.rotation = motion_state[0].rotation; | 579 | sixaxis_dual_left_state.rotation = motion_state[0].rotation; |
| 614 | sixaxis_dual_left_state.orientation = motion_state[0].orientation; | 580 | sixaxis_dual_left_state.orientation = motion_state[0].orientation; |
| 615 | } | 581 | } |
| 616 | if (sixaxis_sensors_enabled) { | 582 | if (controller.sixaxis_sensor_enabled) { |
| 617 | // Set motion for the right joycon | 583 | // Set motion for the right joycon |
| 618 | sixaxis_dual_right_state.attribute.is_connected.Assign(1); | 584 | sixaxis_dual_right_state.attribute.is_connected.Assign(1); |
| 619 | sixaxis_dual_right_state.accel = motion_state[1].accel; | 585 | sixaxis_dual_right_state.accel = motion_state[1].accel; |
| @@ -624,7 +590,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 624 | break; | 590 | break; |
| 625 | case Core::HID::NpadStyleIndex::JoyconLeft: | 591 | case Core::HID::NpadStyleIndex::JoyconLeft: |
| 626 | sixaxis_left_lifo_state.attribute.raw = 0; | 592 | sixaxis_left_lifo_state.attribute.raw = 0; |
| 627 | if (sixaxis_sensors_enabled) { | 593 | if (controller.sixaxis_sensor_enabled) { |
| 628 | sixaxis_left_lifo_state.attribute.is_connected.Assign(1); | 594 | sixaxis_left_lifo_state.attribute.is_connected.Assign(1); |
| 629 | sixaxis_left_lifo_state.accel = motion_state[0].accel; | 595 | sixaxis_left_lifo_state.accel = motion_state[0].accel; |
| 630 | sixaxis_left_lifo_state.gyro = motion_state[0].gyro; | 596 | sixaxis_left_lifo_state.gyro = motion_state[0].gyro; |
| @@ -634,7 +600,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 634 | break; | 600 | break; |
| 635 | case Core::HID::NpadStyleIndex::JoyconRight: | 601 | case Core::HID::NpadStyleIndex::JoyconRight: |
| 636 | sixaxis_right_lifo_state.attribute.raw = 0; | 602 | sixaxis_right_lifo_state.attribute.raw = 0; |
| 637 | if (sixaxis_sensors_enabled) { | 603 | if (controller.sixaxis_sensor_enabled) { |
| 638 | sixaxis_right_lifo_state.attribute.is_connected.Assign(1); | 604 | sixaxis_right_lifo_state.attribute.is_connected.Assign(1); |
| 639 | sixaxis_right_lifo_state.accel = motion_state[1].accel; | 605 | sixaxis_right_lifo_state.accel = motion_state[1].accel; |
| 640 | sixaxis_right_lifo_state.gyro = motion_state[1].gyro; | 606 | sixaxis_right_lifo_state.gyro = motion_state[1].gyro; |
| @@ -724,26 +690,30 @@ Controller_NPad::NpadCommunicationMode Controller_NPad::GetNpadCommunicationMode | |||
| 724 | return communication_mode; | 690 | return communication_mode; |
| 725 | } | 691 | } |
| 726 | 692 | ||
| 727 | void Controller_NPad::SetNpadMode(u32 npad_id, NpadJoyAssignmentMode assignment_mode) { | 693 | void Controller_NPad::SetNpadMode(Core::HID::NpadIdType npad_id, |
| 728 | const std::size_t npad_index = NPadIdToIndex(npad_id); | 694 | NpadJoyAssignmentMode assignment_mode) { |
| 729 | ASSERT(npad_index < controller_data.size()); | 695 | if (!IsNpadIdValid(npad_id)) { |
| 730 | auto& controller = controller_data[npad_index]; | 696 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); |
| 697 | return; | ||
| 698 | } | ||
| 699 | |||
| 700 | auto& controller = GetControllerFromNpadIdType(npad_id); | ||
| 731 | if (controller.shared_memory_entry.assignment_mode != assignment_mode) { | 701 | if (controller.shared_memory_entry.assignment_mode != assignment_mode) { |
| 732 | controller.shared_memory_entry.assignment_mode = assignment_mode; | 702 | controller.shared_memory_entry.assignment_mode = assignment_mode; |
| 733 | } | 703 | } |
| 734 | } | 704 | } |
| 735 | 705 | ||
| 736 | bool Controller_NPad::VibrateControllerAtIndex(std::size_t npad_index, std::size_t device_index, | 706 | bool Controller_NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, |
| 737 | const VibrationValue& vibration_value) { | 707 | std::size_t device_index, |
| 738 | auto& controller = controller_data[npad_index]; | 708 | const Core::HID::VibrationValue& vibration_value) { |
| 739 | 709 | auto& controller = GetControllerFromNpadIdType(npad_id); | |
| 740 | if (!controller.device->IsConnected()) { | 710 | if (!controller.device->IsConnected()) { |
| 741 | return false; | 711 | return false; |
| 742 | } | 712 | } |
| 743 | 713 | ||
| 744 | if (!controller.device->IsVibrationEnabled()) { | 714 | if (!controller.device->IsVibrationEnabled()) { |
| 745 | if (controller.vibration[device_index].latest_vibration_value.amp_low != 0.0f || | 715 | if (controller.vibration[device_index].latest_vibration_value.low_amplitude != 0.0f || |
| 746 | controller.vibration[device_index].latest_vibration_value.amp_high != 0.0f) { | 716 | controller.vibration[device_index].latest_vibration_value.high_amplitude != 0.0f) { |
| 747 | // Send an empty vibration to stop any vibrations. | 717 | // Send an empty vibration to stop any vibrations. |
| 748 | Core::HID::VibrationValue vibration{0.0f, 160.0f, 0.0f, 320.0f}; | 718 | Core::HID::VibrationValue vibration{0.0f, 160.0f, 0.0f, 320.0f}; |
| 749 | controller.device->SetVibration(device_index, vibration); | 719 | controller.device->SetVibration(device_index, vibration); |
| @@ -762,7 +732,7 @@ bool Controller_NPad::VibrateControllerAtIndex(std::size_t npad_index, std::size | |||
| 762 | const auto now = steady_clock::now(); | 732 | const auto now = steady_clock::now(); |
| 763 | 733 | ||
| 764 | // Filter out non-zero vibrations that are within 10ms of each other. | 734 | // Filter out non-zero vibrations that are within 10ms of each other. |
| 765 | if ((vibration_value.amp_low != 0.0f || vibration_value.amp_high != 0.0f) && | 735 | if ((vibration_value.low_amplitude != 0.0f || vibration_value.high_amplitude != 0.0f) && |
| 766 | duration_cast<milliseconds>( | 736 | duration_cast<milliseconds>( |
| 767 | now - controller.vibration[device_index].last_vibration_timepoint) < | 737 | now - controller.vibration[device_index].last_vibration_timepoint) < |
| 768 | milliseconds(10)) { | 738 | milliseconds(10)) { |
| @@ -772,13 +742,15 @@ bool Controller_NPad::VibrateControllerAtIndex(std::size_t npad_index, std::size | |||
| 772 | controller.vibration[device_index].last_vibration_timepoint = now; | 742 | controller.vibration[device_index].last_vibration_timepoint = now; |
| 773 | } | 743 | } |
| 774 | 744 | ||
| 775 | Core::HID::VibrationValue vibration{vibration_value.amp_low, vibration_value.freq_low, | 745 | Core::HID::VibrationValue vibration{ |
| 776 | vibration_value.amp_high, vibration_value.freq_high}; | 746 | vibration_value.low_amplitude, vibration_value.low_frequency, |
| 747 | vibration_value.high_amplitude, vibration_value.high_frequency}; | ||
| 777 | return controller.device->SetVibration(device_index, vibration); | 748 | return controller.device->SetVibration(device_index, vibration); |
| 778 | } | 749 | } |
| 779 | 750 | ||
| 780 | void Controller_NPad::VibrateController(const DeviceHandle& vibration_device_handle, | 751 | void Controller_NPad::VibrateController( |
| 781 | const VibrationValue& vibration_value) { | 752 | const Core::HID::VibrationDeviceHandle& vibration_device_handle, |
| 753 | const Core::HID::VibrationValue& vibration_value) { | ||
| 782 | if (!IsDeviceHandleValid(vibration_device_handle)) { | 754 | if (!IsDeviceHandleValid(vibration_device_handle)) { |
| 783 | return; | 755 | return; |
| 784 | } | 756 | } |
| @@ -787,15 +759,14 @@ void Controller_NPad::VibrateController(const DeviceHandle& vibration_device_han | |||
| 787 | return; | 759 | return; |
| 788 | } | 760 | } |
| 789 | 761 | ||
| 790 | const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); | 762 | auto& controller = GetControllerFromHandle(vibration_device_handle); |
| 791 | auto& controller = controller_data[npad_index]; | ||
| 792 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); | 763 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); |
| 793 | 764 | ||
| 794 | if (!controller.vibration[device_index].device_mounted || !controller.device->IsConnected()) { | 765 | if (!controller.vibration[device_index].device_mounted || !controller.device->IsConnected()) { |
| 795 | return; | 766 | return; |
| 796 | } | 767 | } |
| 797 | 768 | ||
| 798 | if (vibration_device_handle.device_index == DeviceIndex::None) { | 769 | if (vibration_device_handle.device_index == Core::HID::DeviceIndex::None) { |
| 799 | UNREACHABLE_MSG("DeviceIndex should never be None!"); | 770 | UNREACHABLE_MSG("DeviceIndex should never be None!"); |
| 800 | return; | 771 | return; |
| 801 | } | 772 | } |
| @@ -803,28 +774,30 @@ void Controller_NPad::VibrateController(const DeviceHandle& vibration_device_han | |||
| 803 | // Some games try to send mismatched parameters in the device handle, block these. | 774 | // Some games try to send mismatched parameters in the device handle, block these. |
| 804 | if ((controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconLeft && | 775 | if ((controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconLeft && |
| 805 | (vibration_device_handle.npad_type == Core::HID::NpadStyleIndex::JoyconRight || | 776 | (vibration_device_handle.npad_type == Core::HID::NpadStyleIndex::JoyconRight || |
| 806 | vibration_device_handle.device_index == DeviceIndex::Right)) || | 777 | vibration_device_handle.device_index == Core::HID::DeviceIndex::Right)) || |
| 807 | (controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconRight && | 778 | (controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconRight && |
| 808 | (vibration_device_handle.npad_type == Core::HID::NpadStyleIndex::JoyconLeft || | 779 | (vibration_device_handle.npad_type == Core::HID::NpadStyleIndex::JoyconLeft || |
| 809 | vibration_device_handle.device_index == DeviceIndex::Left))) { | 780 | vibration_device_handle.device_index == Core::HID::DeviceIndex::Left))) { |
| 810 | return; | 781 | return; |
| 811 | } | 782 | } |
| 812 | 783 | ||
| 813 | // Filter out vibrations with equivalent values to reduce unnecessary state changes. | 784 | // Filter out vibrations with equivalent values to reduce unnecessary state changes. |
| 814 | if (vibration_value.amp_low == | 785 | if (vibration_value.low_amplitude == |
| 815 | controller.vibration[device_index].latest_vibration_value.amp_low && | 786 | controller.vibration[device_index].latest_vibration_value.low_amplitude && |
| 816 | vibration_value.amp_high == | 787 | vibration_value.high_amplitude == |
| 817 | controller.vibration[device_index].latest_vibration_value.amp_high) { | 788 | controller.vibration[device_index].latest_vibration_value.high_amplitude) { |
| 818 | return; | 789 | return; |
| 819 | } | 790 | } |
| 820 | 791 | ||
| 821 | if (VibrateControllerAtIndex(npad_index, device_index, vibration_value)) { | 792 | if (VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_index, |
| 793 | vibration_value)) { | ||
| 822 | controller.vibration[device_index].latest_vibration_value = vibration_value; | 794 | controller.vibration[device_index].latest_vibration_value = vibration_value; |
| 823 | } | 795 | } |
| 824 | } | 796 | } |
| 825 | 797 | ||
| 826 | void Controller_NPad::VibrateControllers(const std::vector<DeviceHandle>& vibration_device_handles, | 798 | void Controller_NPad::VibrateControllers( |
| 827 | const std::vector<VibrationValue>& vibration_values) { | 799 | const std::vector<Core::HID::VibrationDeviceHandle>& vibration_device_handles, |
| 800 | const std::vector<Core::HID::VibrationValue>& vibration_values) { | ||
| 828 | if (!Settings::values.vibration_enabled.GetValue() && !permit_vibration_session_enabled) { | 801 | if (!Settings::values.vibration_enabled.GetValue() && !permit_vibration_session_enabled) { |
| 829 | return; | 802 | return; |
| 830 | } | 803 | } |
| @@ -839,31 +812,31 @@ void Controller_NPad::VibrateControllers(const std::vector<DeviceHandle>& vibrat | |||
| 839 | } | 812 | } |
| 840 | } | 813 | } |
| 841 | 814 | ||
| 842 | Controller_NPad::VibrationValue Controller_NPad::GetLastVibration( | 815 | Core::HID::VibrationValue Controller_NPad::GetLastVibration( |
| 843 | const DeviceHandle& vibration_device_handle) const { | 816 | const Core::HID::VibrationDeviceHandle& vibration_device_handle) const { |
| 844 | if (!IsDeviceHandleValid(vibration_device_handle)) { | 817 | if (!IsDeviceHandleValid(vibration_device_handle)) { |
| 845 | return {}; | 818 | return {}; |
| 846 | } | 819 | } |
| 847 | 820 | ||
| 848 | const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); | 821 | const auto& controller = GetControllerFromHandle(vibration_device_handle); |
| 849 | const auto& controller = controller_data[npad_index]; | ||
| 850 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); | 822 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); |
| 851 | return controller.vibration[device_index].latest_vibration_value; | 823 | return controller.vibration[device_index].latest_vibration_value; |
| 852 | } | 824 | } |
| 853 | 825 | ||
| 854 | void Controller_NPad::InitializeVibrationDevice(const DeviceHandle& vibration_device_handle) { | 826 | void Controller_NPad::InitializeVibrationDevice( |
| 827 | const Core::HID::VibrationDeviceHandle& vibration_device_handle) { | ||
| 855 | if (!IsDeviceHandleValid(vibration_device_handle)) { | 828 | if (!IsDeviceHandleValid(vibration_device_handle)) { |
| 856 | return; | 829 | return; |
| 857 | } | 830 | } |
| 858 | 831 | ||
| 859 | const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); | 832 | const auto npad_index = static_cast<Core::HID::NpadIdType>(vibration_device_handle.npad_id); |
| 860 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); | 833 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); |
| 861 | InitializeVibrationDeviceAtIndex(npad_index, device_index); | 834 | InitializeVibrationDeviceAtIndex(npad_index, device_index); |
| 862 | } | 835 | } |
| 863 | 836 | ||
| 864 | void Controller_NPad::InitializeVibrationDeviceAtIndex(std::size_t npad_index, | 837 | void Controller_NPad::InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id, |
| 865 | std::size_t device_index) { | 838 | std::size_t device_index) { |
| 866 | auto& controller = controller_data[npad_index]; | 839 | auto& controller = GetControllerFromNpadIdType(npad_id); |
| 867 | if (!Settings::values.vibration_enabled.GetValue()) { | 840 | if (!Settings::values.vibration_enabled.GetValue()) { |
| 868 | controller.vibration[device_index].device_mounted = false; | 841 | controller.vibration[device_index].device_mounted = false; |
| 869 | return; | 842 | return; |
| @@ -877,58 +850,67 @@ void Controller_NPad::SetPermitVibrationSession(bool permit_vibration_session) { | |||
| 877 | permit_vibration_session_enabled = permit_vibration_session; | 850 | permit_vibration_session_enabled = permit_vibration_session; |
| 878 | } | 851 | } |
| 879 | 852 | ||
| 880 | bool Controller_NPad::IsVibrationDeviceMounted(const DeviceHandle& vibration_device_handle) const { | 853 | bool Controller_NPad::IsVibrationDeviceMounted( |
| 854 | const Core::HID::VibrationDeviceHandle& vibration_device_handle) const { | ||
| 881 | if (!IsDeviceHandleValid(vibration_device_handle)) { | 855 | if (!IsDeviceHandleValid(vibration_device_handle)) { |
| 882 | return false; | 856 | return false; |
| 883 | } | 857 | } |
| 884 | 858 | ||
| 885 | const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); | 859 | const auto& controller = GetControllerFromHandle(vibration_device_handle); |
| 886 | const auto& controller = controller_data[npad_index]; | ||
| 887 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); | 860 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); |
| 888 | return controller.vibration[device_index].device_mounted; | 861 | return controller.vibration[device_index].device_mounted; |
| 889 | } | 862 | } |
| 890 | 863 | ||
| 891 | Kernel::KReadableEvent& Controller_NPad::GetStyleSetChangedEvent(u32 npad_id) { | 864 | Kernel::KReadableEvent& Controller_NPad::GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id) { |
| 892 | const auto& controller = controller_data[NPadIdToIndex(npad_id)]; | 865 | if (!IsNpadIdValid(npad_id)) { |
| 866 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); | ||
| 867 | // Fallback to player 1 | ||
| 868 | const auto& controller = GetControllerFromNpadIdType(Core::HID::NpadIdType::Player1); | ||
| 869 | return controller.styleset_changed_event->GetReadableEvent(); | ||
| 870 | } | ||
| 871 | |||
| 872 | const auto& controller = GetControllerFromNpadIdType(npad_id); | ||
| 893 | return controller.styleset_changed_event->GetReadableEvent(); | 873 | return controller.styleset_changed_event->GetReadableEvent(); |
| 894 | } | 874 | } |
| 895 | 875 | ||
| 896 | void Controller_NPad::SignalStyleSetChangedEvent(u32 npad_id) const { | 876 | void Controller_NPad::SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const { |
| 897 | const auto& controller = controller_data[NPadIdToIndex(npad_id)]; | 877 | const auto& controller = GetControllerFromNpadIdType(npad_id); |
| 898 | controller.styleset_changed_event->GetWritableEvent().Signal(); | 878 | controller.styleset_changed_event->GetWritableEvent().Signal(); |
| 899 | } | 879 | } |
| 900 | 880 | ||
| 901 | void Controller_NPad::AddNewControllerAt(Core::HID::NpadStyleIndex controller, | 881 | void Controller_NPad::AddNewControllerAt(Core::HID::NpadStyleIndex controller, |
| 902 | std::size_t npad_index) { | 882 | Core::HID::NpadIdType npad_id) { |
| 903 | UpdateControllerAt(controller, npad_index, true); | 883 | UpdateControllerAt(controller, npad_id, true); |
| 904 | } | 884 | } |
| 905 | 885 | ||
| 906 | void Controller_NPad::UpdateControllerAt(Core::HID::NpadStyleIndex type, std::size_t npad_index, | 886 | void Controller_NPad::UpdateControllerAt(Core::HID::NpadStyleIndex type, |
| 907 | bool connected) { | 887 | Core::HID::NpadIdType npad_id, bool connected) { |
| 908 | auto& controller = controller_data[npad_index]; | 888 | auto& controller = GetControllerFromNpadIdType(npad_id); |
| 909 | if (!connected) { | 889 | if (!connected) { |
| 910 | DisconnectNpadAtIndex(npad_index); | 890 | DisconnectNpad(npad_id); |
| 911 | return; | 891 | return; |
| 912 | } | 892 | } |
| 913 | 893 | ||
| 914 | controller.device->SetNpadStyleIndex(type); | 894 | controller.device->SetNpadStyleIndex(type); |
| 915 | InitNewlyAddedController(npad_index); | 895 | InitNewlyAddedController(npad_id); |
| 916 | } | 896 | } |
| 917 | 897 | ||
| 918 | void Controller_NPad::DisconnectNpad(u32 npad_id) { | 898 | void Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) { |
| 919 | DisconnectNpadAtIndex(NPadIdToIndex(npad_id)); | 899 | if (!IsNpadIdValid(npad_id)) { |
| 920 | } | 900 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); |
| 901 | return; | ||
| 902 | } | ||
| 921 | 903 | ||
| 922 | void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) { | 904 | LOG_DEBUG(Service_HID, "Npad disconnected {}", npad_id); |
| 923 | auto& controller = controller_data[npad_index]; | 905 | auto& controller = GetControllerFromNpadIdType(npad_id); |
| 924 | for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { | 906 | for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { |
| 925 | // Send an empty vibration to stop any vibrations. | 907 | // Send an empty vibration to stop any vibrations. |
| 926 | VibrateControllerAtIndex(npad_index, device_idx, {}); | 908 | VibrateControllerAtIndex(npad_id, device_idx, {}); |
| 927 | controller.vibration[device_idx].device_mounted = false; | 909 | controller.vibration[device_idx].device_mounted = false; |
| 928 | } | 910 | } |
| 929 | 911 | ||
| 930 | auto& shared_memory_entry = controller.shared_memory_entry; | 912 | auto& shared_memory_entry = controller.shared_memory_entry; |
| 931 | shared_memory_entry.style_set.raw = 0; // Zero out | 913 | shared_memory_entry.style_tag.raw = Core::HID::NpadStyleSet::None; // Zero out |
| 932 | shared_memory_entry.device_type.raw = 0; | 914 | shared_memory_entry.device_type.raw = 0; |
| 933 | shared_memory_entry.system_properties.raw = 0; | 915 | shared_memory_entry.system_properties.raw = 0; |
| 934 | shared_memory_entry.button_properties.raw = 0; | 916 | shared_memory_entry.button_properties.raw = 0; |
| @@ -949,48 +931,102 @@ void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) { | |||
| 949 | 931 | ||
| 950 | controller.is_connected = false; | 932 | controller.is_connected = false; |
| 951 | controller.device->Disconnect(); | 933 | controller.device->Disconnect(); |
| 952 | SignalStyleSetChangedEvent(IndexToNPad(npad_index)); | 934 | SignalStyleSetChangedEvent(npad_id); |
| 953 | WriteEmptyEntry(controller.shared_memory_entry); | 935 | WriteEmptyEntry(controller.shared_memory_entry); |
| 954 | } | 936 | } |
| 955 | 937 | ||
| 956 | void Controller_NPad::SetGyroscopeZeroDriftMode(GyroscopeZeroDriftMode drift_mode) { | 938 | void Controller_NPad::SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, |
| 957 | gyroscope_zero_drift_mode = drift_mode; | 939 | GyroscopeZeroDriftMode drift_mode) { |
| 940 | if (!IsDeviceHandleValid(sixaxis_handle)) { | ||
| 941 | LOG_ERROR(Service_HID, "Invalid handle"); | ||
| 942 | return; | ||
| 943 | } | ||
| 944 | auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 945 | controller.gyroscope_zero_drift_mode = drift_mode; | ||
| 958 | } | 946 | } |
| 959 | 947 | ||
| 960 | Controller_NPad::GyroscopeZeroDriftMode Controller_NPad::GetGyroscopeZeroDriftMode() const { | 948 | Controller_NPad::GyroscopeZeroDriftMode Controller_NPad::GetGyroscopeZeroDriftMode( |
| 961 | return gyroscope_zero_drift_mode; | 949 | Core::HID::SixAxisSensorHandle sixaxis_handle) const { |
| 950 | if (!IsDeviceHandleValid(sixaxis_handle)) { | ||
| 951 | LOG_ERROR(Service_HID, "Invalid handle"); | ||
| 952 | // Return the default value | ||
| 953 | return GyroscopeZeroDriftMode::Standard; | ||
| 954 | } | ||
| 955 | const auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 956 | return controller.gyroscope_zero_drift_mode; | ||
| 962 | } | 957 | } |
| 963 | 958 | ||
| 964 | bool Controller_NPad::IsSixAxisSensorAtRest() const { | 959 | bool Controller_NPad::IsSixAxisSensorAtRest(Core::HID::SixAxisSensorHandle sixaxis_handle) const { |
| 965 | return sixaxis_at_rest; | 960 | if (!IsDeviceHandleValid(sixaxis_handle)) { |
| 961 | LOG_ERROR(Service_HID, "Invalid handle"); | ||
| 962 | // Return the default value | ||
| 963 | return true; | ||
| 964 | } | ||
| 965 | const auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 966 | return controller.sixaxis_at_rest; | ||
| 967 | } | ||
| 968 | |||
| 969 | void Controller_NPad::SetSixAxisEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, | ||
| 970 | bool sixaxis_status) { | ||
| 971 | if (!IsDeviceHandleValid(sixaxis_handle)) { | ||
| 972 | LOG_ERROR(Service_HID, "Invalid handle"); | ||
| 973 | return; | ||
| 974 | } | ||
| 975 | auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 976 | controller.sixaxis_sensor_enabled = sixaxis_status; | ||
| 966 | } | 977 | } |
| 967 | 978 | ||
| 968 | void Controller_NPad::SetSixAxisEnabled(bool six_axis_status) { | 979 | void Controller_NPad::SetSixAxisFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, |
| 969 | sixaxis_sensors_enabled = six_axis_status; | 980 | bool sixaxis_fusion_status) { |
| 981 | if (!IsDeviceHandleValid(sixaxis_handle)) { | ||
| 982 | LOG_ERROR(Service_HID, "Invalid handle"); | ||
| 983 | return; | ||
| 984 | } | ||
| 985 | auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 986 | controller.sixaxis_fusion_enabled = sixaxis_fusion_status; | ||
| 970 | } | 987 | } |
| 971 | 988 | ||
| 972 | void Controller_NPad::SetSixAxisFusionParameters(f32 parameter1, f32 parameter2) { | 989 | void Controller_NPad::SetSixAxisFusionParameters( |
| 973 | sixaxis_fusion_parameter1 = parameter1; | 990 | Core::HID::SixAxisSensorHandle sixaxis_handle, |
| 974 | sixaxis_fusion_parameter2 = parameter2; | 991 | Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters) { |
| 992 | if (!IsDeviceHandleValid(sixaxis_handle)) { | ||
| 993 | LOG_ERROR(Service_HID, "Invalid handle"); | ||
| 994 | return; | ||
| 995 | } | ||
| 996 | auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 997 | controller.sixaxis_fusion = sixaxis_fusion_parameters; | ||
| 975 | } | 998 | } |
| 976 | 999 | ||
| 977 | std::pair<f32, f32> Controller_NPad::GetSixAxisFusionParameters() { | 1000 | Core::HID::SixAxisSensorFusionParameters Controller_NPad::GetSixAxisFusionParameters( |
| 978 | return { | 1001 | Core::HID::SixAxisSensorHandle sixaxis_handle) { |
| 979 | sixaxis_fusion_parameter1, | 1002 | if (!IsDeviceHandleValid(sixaxis_handle)) { |
| 980 | sixaxis_fusion_parameter2, | 1003 | LOG_ERROR(Service_HID, "Invalid handle"); |
| 981 | }; | 1004 | // Since these parameters are unknow just return zeros |
| 1005 | return {}; | ||
| 1006 | } | ||
| 1007 | auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 1008 | return controller.sixaxis_fusion; | ||
| 982 | } | 1009 | } |
| 983 | 1010 | ||
| 984 | void Controller_NPad::ResetSixAxisFusionParameters() { | 1011 | void Controller_NPad::ResetSixAxisFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle) { |
| 985 | sixaxis_fusion_parameter1 = 0.0f; | 1012 | if (!IsDeviceHandleValid(sixaxis_handle)) { |
| 986 | sixaxis_fusion_parameter2 = 0.0f; | 1013 | LOG_ERROR(Service_HID, "Invalid handle"); |
| 1014 | return; | ||
| 1015 | } | ||
| 1016 | auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 1017 | // Since these parameters are unknow just fill with zeros | ||
| 1018 | controller.sixaxis_fusion = {}; | ||
| 987 | } | 1019 | } |
| 988 | 1020 | ||
| 989 | void Controller_NPad::MergeSingleJoyAsDualJoy(u32 npad_id_1, u32 npad_id_2) { | 1021 | void Controller_NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, |
| 990 | const auto npad_index_1 = NPadIdToIndex(npad_id_1); | 1022 | Core::HID::NpadIdType npad_id_2) { |
| 991 | const auto npad_index_2 = NPadIdToIndex(npad_id_2); | 1023 | if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { |
| 992 | const auto& controller_1 = controller_data[npad_index_1].device; | 1024 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id_1:{}, npad_id_2:{}", npad_id_1, |
| 993 | const auto& controller_2 = controller_data[npad_index_2].device; | 1025 | npad_id_2); |
| 1026 | return; | ||
| 1027 | } | ||
| 1028 | auto& controller_1 = GetControllerFromNpadIdType(npad_id_1).device; | ||
| 1029 | auto& controller_2 = GetControllerFromNpadIdType(npad_id_2).device; | ||
| 994 | 1030 | ||
| 995 | // If the controllers at both npad indices form a pair of left and right joycons, merge them. | 1031 | // If the controllers at both npad indices form a pair of left and right joycons, merge them. |
| 996 | // Otherwise, do nothing. | 1032 | // Otherwise, do nothing. |
| @@ -1000,7 +1036,7 @@ void Controller_NPad::MergeSingleJoyAsDualJoy(u32 npad_id_1, u32 npad_id_2) { | |||
| 1000 | controller_1->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconRight)) { | 1036 | controller_1->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconRight)) { |
| 1001 | // Disconnect the joycon at the second id and connect the dual joycon at the first index. | 1037 | // Disconnect the joycon at the second id and connect the dual joycon at the first index. |
| 1002 | DisconnectNpad(npad_id_2); | 1038 | DisconnectNpad(npad_id_2); |
| 1003 | AddNewControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_index_1); | 1039 | AddNewControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id_1); |
| 1004 | } | 1040 | } |
| 1005 | } | 1041 | } |
| 1006 | 1042 | ||
| @@ -1014,15 +1050,20 @@ void Controller_NPad::StopLRAssignmentMode() { | |||
| 1014 | is_in_lr_assignment_mode = false; | 1050 | is_in_lr_assignment_mode = false; |
| 1015 | } | 1051 | } |
| 1016 | 1052 | ||
| 1017 | bool Controller_NPad::SwapNpadAssignment(u32 npad_id_1, u32 npad_id_2) { | 1053 | bool Controller_NPad::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, |
| 1018 | if (npad_id_1 == NPAD_HANDHELD || npad_id_2 == NPAD_HANDHELD || npad_id_1 == NPAD_UNKNOWN || | 1054 | Core::HID::NpadIdType npad_id_2) { |
| 1019 | npad_id_2 == NPAD_UNKNOWN) { | 1055 | if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { |
| 1056 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id_1:{}, npad_id_2:{}", npad_id_1, | ||
| 1057 | npad_id_2); | ||
| 1058 | return false; | ||
| 1059 | } | ||
| 1060 | if (npad_id_1 == Core::HID::NpadIdType::Handheld || | ||
| 1061 | npad_id_2 == Core::HID::NpadIdType::Handheld || npad_id_1 == Core::HID::NpadIdType::Other || | ||
| 1062 | npad_id_2 == Core::HID::NpadIdType::Other) { | ||
| 1020 | return true; | 1063 | return true; |
| 1021 | } | 1064 | } |
| 1022 | const auto npad_index_1 = NPadIdToIndex(npad_id_1); | 1065 | const auto& controller_1 = GetControllerFromNpadIdType(npad_id_1).device; |
| 1023 | const auto npad_index_2 = NPadIdToIndex(npad_id_2); | 1066 | const auto& controller_2 = GetControllerFromNpadIdType(npad_id_2).device; |
| 1024 | const auto& controller_1 = controller_data[npad_index_1].device; | ||
| 1025 | const auto& controller_2 = controller_data[npad_index_2].device; | ||
| 1026 | const auto type_index_1 = controller_1->GetNpadStyleIndex(); | 1067 | const auto type_index_1 = controller_1->GetNpadStyleIndex(); |
| 1027 | const auto type_index_2 = controller_2->GetNpadStyleIndex(); | 1068 | const auto type_index_2 = controller_2->GetNpadStyleIndex(); |
| 1028 | 1069 | ||
| @@ -1030,28 +1071,39 @@ bool Controller_NPad::SwapNpadAssignment(u32 npad_id_1, u32 npad_id_2) { | |||
| 1030 | return false; | 1071 | return false; |
| 1031 | } | 1072 | } |
| 1032 | 1073 | ||
| 1033 | AddNewControllerAt(type_index_2, npad_index_1); | 1074 | AddNewControllerAt(type_index_2, npad_id_1); |
| 1034 | AddNewControllerAt(type_index_1, npad_index_2); | 1075 | AddNewControllerAt(type_index_1, npad_id_2); |
| 1035 | 1076 | ||
| 1036 | return true; | 1077 | return true; |
| 1037 | } | 1078 | } |
| 1038 | 1079 | ||
| 1039 | Core::HID::LedPattern Controller_NPad::GetLedPattern(u32 npad_id) { | 1080 | Core::HID::LedPattern Controller_NPad::GetLedPattern(Core::HID::NpadIdType npad_id) { |
| 1040 | if (npad_id == npad_id_list.back() || npad_id == npad_id_list[npad_id_list.size() - 2]) { | 1081 | if (!IsNpadIdValid(npad_id)) { |
| 1041 | // These are controllers without led patterns | 1082 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); |
| 1042 | return Core::HID::LedPattern{0, 0, 0, 0}; | 1083 | return Core::HID::LedPattern{0, 0, 0, 0}; |
| 1043 | } | 1084 | } |
| 1044 | return controller_data[npad_id].device->GetLedPattern(); | 1085 | const auto& controller = GetControllerFromNpadIdType(npad_id).device; |
| 1086 | return controller->GetLedPattern(); | ||
| 1045 | } | 1087 | } |
| 1046 | 1088 | ||
| 1047 | bool Controller_NPad::IsUnintendedHomeButtonInputProtectionEnabled(u32 npad_id) const { | 1089 | bool Controller_NPad::IsUnintendedHomeButtonInputProtectionEnabled( |
| 1048 | auto& controller = controller_data[NPadIdToIndex(npad_id)]; | 1090 | Core::HID::NpadIdType npad_id) const { |
| 1091 | if (!IsNpadIdValid(npad_id)) { | ||
| 1092 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); | ||
| 1093 | // Return the default value | ||
| 1094 | return false; | ||
| 1095 | } | ||
| 1096 | const auto& controller = GetControllerFromNpadIdType(npad_id); | ||
| 1049 | return controller.unintended_home_button_input_protection; | 1097 | return controller.unintended_home_button_input_protection; |
| 1050 | } | 1098 | } |
| 1051 | 1099 | ||
| 1052 | void Controller_NPad::SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled, | 1100 | void Controller_NPad::SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled, |
| 1053 | u32 npad_id) { | 1101 | Core::HID::NpadIdType npad_id) { |
| 1054 | auto& controller = controller_data[NPadIdToIndex(npad_id)]; | 1102 | if (!IsNpadIdValid(npad_id)) { |
| 1103 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); | ||
| 1104 | return; | ||
| 1105 | } | ||
| 1106 | auto& controller = GetControllerFromNpadIdType(npad_id); | ||
| 1055 | controller.unintended_home_button_input_protection = is_protection_enabled; | 1107 | controller.unintended_home_button_input_protection = is_protection_enabled; |
| 1056 | } | 1108 | } |
| 1057 | 1109 | ||
| @@ -1099,7 +1151,7 @@ bool Controller_NPad::IsControllerSupported(Core::HID::NpadStyleIndex controller | |||
| 1099 | if (controller == Core::HID::NpadStyleIndex::Handheld) { | 1151 | if (controller == Core::HID::NpadStyleIndex::Handheld) { |
| 1100 | const bool support_handheld = | 1152 | const bool support_handheld = |
| 1101 | std::find(supported_npad_id_types.begin(), supported_npad_id_types.end(), | 1153 | std::find(supported_npad_id_types.begin(), supported_npad_id_types.end(), |
| 1102 | NPAD_HANDHELD) != supported_npad_id_types.end(); | 1154 | Core::HID::NpadIdType::Handheld) != supported_npad_id_types.end(); |
| 1103 | // Handheld is not even a supported type, lets stop here | 1155 | // Handheld is not even a supported type, lets stop here |
| 1104 | if (!support_handheld) { | 1156 | if (!support_handheld) { |
| 1105 | return false; | 1157 | return false; |
| @@ -1113,7 +1165,9 @@ bool Controller_NPad::IsControllerSupported(Core::HID::NpadStyleIndex controller | |||
| 1113 | } | 1165 | } |
| 1114 | 1166 | ||
| 1115 | if (std::any_of(supported_npad_id_types.begin(), supported_npad_id_types.end(), | 1167 | if (std::any_of(supported_npad_id_types.begin(), supported_npad_id_types.end(), |
| 1116 | [](u32 npad_id) { return npad_id <= MAX_NPAD_ID; })) { | 1168 | [](Core::HID::NpadIdType npad_id) { |
| 1169 | return npad_id <= Core::HID::NpadIdType::Player8; | ||
| 1170 | })) { | ||
| 1117 | Core::HID::NpadStyleTag style = GetSupportedStyleSet(); | 1171 | Core::HID::NpadStyleTag style = GetSupportedStyleSet(); |
| 1118 | switch (controller) { | 1172 | switch (controller) { |
| 1119 | case Core::HID::NpadStyleIndex::ProController: | 1173 | case Core::HID::NpadStyleIndex::ProController: |
| @@ -1144,4 +1198,48 @@ bool Controller_NPad::IsControllerSupported(Core::HID::NpadStyleIndex controller | |||
| 1144 | return false; | 1198 | return false; |
| 1145 | } | 1199 | } |
| 1146 | 1200 | ||
| 1201 | Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( | ||
| 1202 | const Core::HID::SixAxisSensorHandle& device_handle) { | ||
| 1203 | const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id); | ||
| 1204 | return GetControllerFromNpadIdType(npad_id); | ||
| 1205 | } | ||
| 1206 | |||
| 1207 | const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( | ||
| 1208 | const Core::HID::SixAxisSensorHandle& device_handle) const { | ||
| 1209 | const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id); | ||
| 1210 | return GetControllerFromNpadIdType(npad_id); | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( | ||
| 1214 | const Core::HID::VibrationDeviceHandle& device_handle) { | ||
| 1215 | const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id); | ||
| 1216 | return GetControllerFromNpadIdType(npad_id); | ||
| 1217 | } | ||
| 1218 | |||
| 1219 | const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( | ||
| 1220 | const Core::HID::VibrationDeviceHandle& device_handle) const { | ||
| 1221 | const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id); | ||
| 1222 | return GetControllerFromNpadIdType(npad_id); | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromNpadIdType( | ||
| 1226 | Core::HID::NpadIdType npad_id) { | ||
| 1227 | if (!IsNpadIdValid(npad_id)) { | ||
| 1228 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); | ||
| 1229 | npad_id = Core::HID::NpadIdType::Player1; | ||
| 1230 | } | ||
| 1231 | const auto npad_index = Core::HID::NpadIdTypeToIndex(npad_id); | ||
| 1232 | return controller_data[npad_index]; | ||
| 1233 | } | ||
| 1234 | |||
| 1235 | const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromNpadIdType( | ||
| 1236 | Core::HID::NpadIdType npad_id) const { | ||
| 1237 | if (!IsNpadIdValid(npad_id)) { | ||
| 1238 | LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); | ||
| 1239 | npad_id = Core::HID::NpadIdType::Player1; | ||
| 1240 | } | ||
| 1241 | const auto npad_index = Core::HID::NpadIdTypeToIndex(npad_id); | ||
| 1242 | return controller_data[npad_index]; | ||
| 1243 | } | ||
| 1244 | |||
| 1147 | } // namespace Service::HID | 1245 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index a996755ed..3798c037f 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -31,9 +31,6 @@ class ServiceContext; | |||
| 31 | 31 | ||
| 32 | namespace Service::HID { | 32 | namespace Service::HID { |
| 33 | 33 | ||
| 34 | constexpr u32 NPAD_HANDHELD = 32; | ||
| 35 | constexpr u32 NPAD_UNKNOWN = 16; // TODO(ogniK): What is this? | ||
| 36 | |||
| 37 | class Controller_NPad final : public ControllerBase { | 34 | class Controller_NPad final : public ControllerBase { |
| 38 | public: | 35 | public: |
| 39 | explicit Controller_NPad(Core::HID::HIDCore& hid_core_, | 36 | explicit Controller_NPad(Core::HID::HIDCore& hid_core_, |
| @@ -53,13 +50,6 @@ public: | |||
| 53 | void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 50 | void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 54 | std::size_t size) override; | 51 | std::size_t size) override; |
| 55 | 52 | ||
| 56 | enum class DeviceIndex : u8 { | ||
| 57 | Left = 0, | ||
| 58 | Right = 1, | ||
| 59 | None = 2, | ||
| 60 | MaxDeviceIndex = 3, | ||
| 61 | }; | ||
| 62 | |||
| 63 | // This is nn::hid::GyroscopeZeroDriftMode | 53 | // This is nn::hid::GyroscopeZeroDriftMode |
| 64 | enum class GyroscopeZeroDriftMode : u32 { | 54 | enum class GyroscopeZeroDriftMode : u32 { |
| 65 | Loose = 0, | 55 | Loose = 0, |
| @@ -79,6 +69,12 @@ public: | |||
| 79 | Single = 1, | 69 | Single = 1, |
| 80 | }; | 70 | }; |
| 81 | 71 | ||
| 72 | // This is nn::hid::NpadJoyDeviceType | ||
| 73 | enum class NpadJoyDeviceType : s64 { | ||
| 74 | Left = 0, | ||
| 75 | Right = 1, | ||
| 76 | }; | ||
| 77 | |||
| 82 | // This is nn::hid::NpadHandheldActivationMode | 78 | // This is nn::hid::NpadHandheldActivationMode |
| 83 | enum class NpadHandheldActivationMode : u64 { | 79 | enum class NpadHandheldActivationMode : u64 { |
| 84 | Dual = 0, | 80 | Dual = 0, |
| @@ -94,28 +90,11 @@ public: | |||
| 94 | Default = 3, | 90 | Default = 3, |
| 95 | }; | 91 | }; |
| 96 | 92 | ||
| 97 | struct DeviceHandle { | 93 | static constexpr Core::HID::VibrationValue DEFAULT_VIBRATION_VALUE{ |
| 98 | Core::HID::NpadStyleIndex npad_type; | 94 | .low_amplitude = 0.0f, |
| 99 | u8 npad_id; | 95 | .low_frequency = 160.0f, |
| 100 | DeviceIndex device_index; | 96 | .high_amplitude = 0.0f, |
| 101 | INSERT_PADDING_BYTES_NOINIT(1); | 97 | .high_frequency = 320.0f, |
| 102 | }; | ||
| 103 | static_assert(sizeof(DeviceHandle) == 4, "DeviceHandle is an invalid size"); | ||
| 104 | |||
| 105 | // This is nn::hid::VibrationValue | ||
| 106 | struct VibrationValue { | ||
| 107 | f32 amp_low; | ||
| 108 | f32 freq_low; | ||
| 109 | f32 amp_high; | ||
| 110 | f32 freq_high; | ||
| 111 | }; | ||
| 112 | static_assert(sizeof(VibrationValue) == 0x10, "Vibration is an invalid size"); | ||
| 113 | |||
| 114 | static constexpr VibrationValue DEFAULT_VIBRATION_VALUE{ | ||
| 115 | .amp_low = 0.0f, | ||
| 116 | .freq_low = 160.0f, | ||
| 117 | .amp_high = 0.0f, | ||
| 118 | .freq_high = 320.0f, | ||
| 119 | }; | 98 | }; |
| 120 | 99 | ||
| 121 | void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set); | 100 | void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set); |
| @@ -134,68 +113,77 @@ public: | |||
| 134 | void SetNpadCommunicationMode(NpadCommunicationMode communication_mode_); | 113 | void SetNpadCommunicationMode(NpadCommunicationMode communication_mode_); |
| 135 | NpadCommunicationMode GetNpadCommunicationMode() const; | 114 | NpadCommunicationMode GetNpadCommunicationMode() const; |
| 136 | 115 | ||
| 137 | void SetNpadMode(u32 npad_id, NpadJoyAssignmentMode assignment_mode); | 116 | void SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyAssignmentMode assignment_mode); |
| 138 | 117 | ||
| 139 | bool VibrateControllerAtIndex(std::size_t npad_index, std::size_t device_index, | 118 | bool VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index, |
| 140 | const VibrationValue& vibration_value); | 119 | const Core::HID::VibrationValue& vibration_value); |
| 141 | 120 | ||
| 142 | void VibrateController(const DeviceHandle& vibration_device_handle, | 121 | void VibrateController(const Core::HID::VibrationDeviceHandle& vibration_device_handle, |
| 143 | const VibrationValue& vibration_value); | 122 | const Core::HID::VibrationValue& vibration_value); |
| 144 | 123 | ||
| 145 | void VibrateControllers(const std::vector<DeviceHandle>& vibration_device_handles, | 124 | void VibrateControllers( |
| 146 | const std::vector<VibrationValue>& vibration_values); | 125 | const std::vector<Core::HID::VibrationDeviceHandle>& vibration_device_handles, |
| 126 | const std::vector<Core::HID::VibrationValue>& vibration_values); | ||
| 147 | 127 | ||
| 148 | VibrationValue GetLastVibration(const DeviceHandle& vibration_device_handle) const; | 128 | Core::HID::VibrationValue GetLastVibration( |
| 129 | const Core::HID::VibrationDeviceHandle& vibration_device_handle) const; | ||
| 149 | 130 | ||
| 150 | void InitializeVibrationDevice(const DeviceHandle& vibration_device_handle); | 131 | void InitializeVibrationDevice(const Core::HID::VibrationDeviceHandle& vibration_device_handle); |
| 151 | 132 | ||
| 152 | void InitializeVibrationDeviceAtIndex(std::size_t npad_index, std::size_t device_index); | 133 | void InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index); |
| 153 | 134 | ||
| 154 | void SetPermitVibrationSession(bool permit_vibration_session); | 135 | void SetPermitVibrationSession(bool permit_vibration_session); |
| 155 | 136 | ||
| 156 | bool IsVibrationDeviceMounted(const DeviceHandle& vibration_device_handle) const; | 137 | bool IsVibrationDeviceMounted( |
| 138 | const Core::HID::VibrationDeviceHandle& vibration_device_handle) const; | ||
| 157 | 139 | ||
| 158 | Kernel::KReadableEvent& GetStyleSetChangedEvent(u32 npad_id); | 140 | Kernel::KReadableEvent& GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id); |
| 159 | void SignalStyleSetChangedEvent(u32 npad_id) const; | 141 | void SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const; |
| 160 | 142 | ||
| 161 | // Adds a new controller at an index. | 143 | // Adds a new controller at an index. |
| 162 | void AddNewControllerAt(Core::HID::NpadStyleIndex controller, std::size_t npad_index); | 144 | void AddNewControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id); |
| 163 | // Adds a new controller at an index with connection status. | 145 | // Adds a new controller at an index with connection status. |
| 164 | void UpdateControllerAt(Core::HID::NpadStyleIndex controller, std::size_t npad_index, | 146 | void UpdateControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id, |
| 165 | bool connected); | 147 | bool connected); |
| 166 | 148 | ||
| 167 | void DisconnectNpad(u32 npad_id); | 149 | void DisconnectNpad(Core::HID::NpadIdType npad_id); |
| 168 | void DisconnectNpadAtIndex(std::size_t index); | 150 | |
| 169 | 151 | void SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, | |
| 170 | void SetGyroscopeZeroDriftMode(GyroscopeZeroDriftMode drift_mode); | 152 | GyroscopeZeroDriftMode drift_mode); |
| 171 | GyroscopeZeroDriftMode GetGyroscopeZeroDriftMode() const; | 153 | GyroscopeZeroDriftMode GetGyroscopeZeroDriftMode( |
| 172 | bool IsSixAxisSensorAtRest() const; | 154 | Core::HID::SixAxisSensorHandle sixaxis_handle) const; |
| 173 | void SetSixAxisEnabled(bool six_axis_status); | 155 | bool IsSixAxisSensorAtRest(Core::HID::SixAxisSensorHandle sixaxis_handle) const; |
| 174 | void SetSixAxisFusionParameters(f32 parameter1, f32 parameter2); | 156 | void SetSixAxisEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, bool sixaxis_status); |
| 175 | std::pair<f32, f32> GetSixAxisFusionParameters(); | 157 | void SetSixAxisFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, |
| 176 | void ResetSixAxisFusionParameters(); | 158 | bool sixaxis_fusion_status); |
| 177 | Core::HID::LedPattern GetLedPattern(u32 npad_id); | 159 | void SetSixAxisFusionParameters( |
| 178 | bool IsUnintendedHomeButtonInputProtectionEnabled(u32 npad_id) const; | 160 | Core::HID::SixAxisSensorHandle sixaxis_handle, |
| 179 | void SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled, u32 npad_id); | 161 | Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters); |
| 162 | Core::HID::SixAxisSensorFusionParameters GetSixAxisFusionParameters( | ||
| 163 | Core::HID::SixAxisSensorHandle sixaxis_handle); | ||
| 164 | void ResetSixAxisFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle); | ||
| 165 | Core::HID::LedPattern GetLedPattern(Core::HID::NpadIdType npad_id); | ||
| 166 | bool IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id) const; | ||
| 167 | void SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled, | ||
| 168 | Core::HID::NpadIdType npad_id); | ||
| 180 | void SetAnalogStickUseCenterClamp(bool use_center_clamp); | 169 | void SetAnalogStickUseCenterClamp(bool use_center_clamp); |
| 181 | void ClearAllConnectedControllers(); | 170 | void ClearAllConnectedControllers(); |
| 182 | void DisconnectAllConnectedControllers(); | 171 | void DisconnectAllConnectedControllers(); |
| 183 | void ConnectAllDisconnectedControllers(); | 172 | void ConnectAllDisconnectedControllers(); |
| 184 | void ClearAllControllers(); | 173 | void ClearAllControllers(); |
| 185 | 174 | ||
| 186 | void MergeSingleJoyAsDualJoy(u32 npad_id_1, u32 npad_id_2); | 175 | void MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2); |
| 187 | void StartLRAssignmentMode(); | 176 | void StartLRAssignmentMode(); |
| 188 | void StopLRAssignmentMode(); | 177 | void StopLRAssignmentMode(); |
| 189 | bool SwapNpadAssignment(u32 npad_id_1, u32 npad_id_2); | 178 | bool SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2); |
| 190 | 179 | ||
| 191 | // Logical OR for all buttons presses on all controllers | 180 | // Logical OR for all buttons presses on all controllers |
| 192 | // Specifically for cheat engine and other features. | 181 | // Specifically for cheat engine and other features. |
| 193 | u32 GetAndResetPressState(); | 182 | u32 GetAndResetPressState(); |
| 194 | 183 | ||
| 195 | static std::size_t NPadIdToIndex(u32 npad_id); | 184 | static bool IsNpadIdValid(Core::HID::NpadIdType npad_id); |
| 196 | static u32 IndexToNPad(std::size_t index); | 185 | static bool IsDeviceHandleValid(const Core::HID::SixAxisSensorHandle& device_handle); |
| 197 | static bool IsNpadIdValid(u32 npad_id); | 186 | static bool IsDeviceHandleValid(const Core::HID::VibrationDeviceHandle& device_handle); |
| 198 | static bool IsDeviceHandleValid(const DeviceHandle& device_handle); | ||
| 199 | 187 | ||
| 200 | private: | 188 | private: |
| 201 | // This is nn::hid::detail::ColorAttribute | 189 | // This is nn::hid::detail::ColorAttribute |
| @@ -441,7 +429,7 @@ private: | |||
| 441 | 429 | ||
| 442 | // This is nn::hid::detail::NpadInternalState | 430 | // This is nn::hid::detail::NpadInternalState |
| 443 | struct NpadInternalState { | 431 | struct NpadInternalState { |
| 444 | Core::HID::NpadStyleTag style_set; | 432 | Core::HID::NpadStyleTag style_tag; |
| 445 | NpadJoyAssignmentMode assignment_mode; | 433 | NpadJoyAssignmentMode assignment_mode; |
| 446 | NpadFullKeyColorState fullkey_color; | 434 | NpadFullKeyColorState fullkey_color; |
| 447 | NpadJoyColorState joycon_color; | 435 | NpadJoyColorState joycon_color; |
| @@ -476,19 +464,19 @@ private: | |||
| 476 | NpadLuciaType lucia_type; | 464 | NpadLuciaType lucia_type; |
| 477 | NpadLagonType lagon_type; | 465 | NpadLagonType lagon_type; |
| 478 | NpadLagerType lager_type; | 466 | NpadLagerType lager_type; |
| 479 | INSERT_PADDING_BYTES( | 467 | // FW 13.x Investigate there is some sort of bitflag related to joycons |
| 480 | 0x4); // FW 13.x Investigate there is some sort of bitflag related to joycons | 468 | INSERT_PADDING_BYTES(0x4); |
| 481 | INSERT_PADDING_BYTES(0xc08); // Unknown | 469 | INSERT_PADDING_BYTES(0xc08); // Unknown |
| 482 | }; | 470 | }; |
| 483 | static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size"); | 471 | static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size"); |
| 484 | 472 | ||
| 485 | struct VibrationData { | 473 | struct VibrationData { |
| 486 | bool device_mounted{}; | 474 | bool device_mounted{}; |
| 487 | VibrationValue latest_vibration_value{}; | 475 | Core::HID::VibrationValue latest_vibration_value{}; |
| 488 | std::chrono::steady_clock::time_point last_vibration_timepoint{}; | 476 | std::chrono::steady_clock::time_point last_vibration_timepoint{}; |
| 489 | }; | 477 | }; |
| 490 | 478 | ||
| 491 | struct ControllerData { | 479 | struct NpadControllerData { |
| 492 | Core::HID::EmulatedController* device; | 480 | Core::HID::EmulatedController* device; |
| 493 | Kernel::KEvent* styleset_changed_event{}; | 481 | Kernel::KEvent* styleset_changed_event{}; |
| 494 | NpadInternalState shared_memory_entry{}; | 482 | NpadInternalState shared_memory_entry{}; |
| @@ -498,6 +486,13 @@ private: | |||
| 498 | bool is_connected{}; | 486 | bool is_connected{}; |
| 499 | Core::HID::NpadStyleIndex npad_type{Core::HID::NpadStyleIndex::None}; | 487 | Core::HID::NpadStyleIndex npad_type{Core::HID::NpadStyleIndex::None}; |
| 500 | 488 | ||
| 489 | // Motion parameters | ||
| 490 | bool sixaxis_at_rest{true}; | ||
| 491 | bool sixaxis_sensor_enabled{true}; | ||
| 492 | bool sixaxis_fusion_enabled{false}; | ||
| 493 | Core::HID::SixAxisSensorFusionParameters sixaxis_fusion{}; | ||
| 494 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; | ||
| 495 | |||
| 501 | // Current pad state | 496 | // Current pad state |
| 502 | NPadGenericState npad_pad_state{}; | 497 | NPadGenericState npad_pad_state{}; |
| 503 | NPadGenericState npad_libnx_state{}; | 498 | NPadGenericState npad_libnx_state{}; |
| @@ -512,27 +507,33 @@ private: | |||
| 512 | }; | 507 | }; |
| 513 | 508 | ||
| 514 | void ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx); | 509 | void ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx); |
| 515 | void InitNewlyAddedController(std::size_t controller_idx); | 510 | void InitNewlyAddedController(Core::HID::NpadIdType npad_id); |
| 516 | bool IsControllerSupported(Core::HID::NpadStyleIndex controller) const; | 511 | bool IsControllerSupported(Core::HID::NpadStyleIndex controller) const; |
| 517 | void RequestPadStateUpdate(u32 npad_id); | 512 | void RequestPadStateUpdate(Core::HID::NpadIdType npad_id); |
| 518 | void WriteEmptyEntry(NpadInternalState& npad); | 513 | void WriteEmptyEntry(NpadInternalState& npad); |
| 519 | 514 | ||
| 515 | NpadControllerData& GetControllerFromHandle( | ||
| 516 | const Core::HID::SixAxisSensorHandle& device_handle); | ||
| 517 | const NpadControllerData& GetControllerFromHandle( | ||
| 518 | const Core::HID::SixAxisSensorHandle& device_handle) const; | ||
| 519 | NpadControllerData& GetControllerFromHandle( | ||
| 520 | const Core::HID::VibrationDeviceHandle& device_handle); | ||
| 521 | const NpadControllerData& GetControllerFromHandle( | ||
| 522 | const Core::HID::VibrationDeviceHandle& device_handle) const; | ||
| 523 | NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id); | ||
| 524 | const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const; | ||
| 525 | |||
| 520 | std::atomic<u32> press_state{}; | 526 | std::atomic<u32> press_state{}; |
| 521 | 527 | ||
| 522 | std::array<ControllerData, 10> controller_data{}; | 528 | std::array<NpadControllerData, 10> controller_data{}; |
| 523 | KernelHelpers::ServiceContext& service_context; | 529 | KernelHelpers::ServiceContext& service_context; |
| 524 | std::mutex mutex; | 530 | std::mutex mutex; |
| 525 | std::vector<u32> supported_npad_id_types{}; | 531 | std::vector<Core::HID::NpadIdType> supported_npad_id_types{}; |
| 526 | NpadJoyHoldType hold_type{NpadJoyHoldType::Vertical}; | 532 | NpadJoyHoldType hold_type{NpadJoyHoldType::Vertical}; |
| 527 | NpadHandheldActivationMode handheld_activation_mode{NpadHandheldActivationMode::Dual}; | 533 | NpadHandheldActivationMode handheld_activation_mode{NpadHandheldActivationMode::Dual}; |
| 528 | NpadCommunicationMode communication_mode{NpadCommunicationMode::Default}; | 534 | NpadCommunicationMode communication_mode{NpadCommunicationMode::Default}; |
| 529 | bool permit_vibration_session_enabled{false}; | 535 | bool permit_vibration_session_enabled{false}; |
| 530 | bool analog_stick_use_center_clamp{}; | 536 | bool analog_stick_use_center_clamp{}; |
| 531 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; | ||
| 532 | bool sixaxis_sensors_enabled{true}; | ||
| 533 | f32 sixaxis_fusion_parameter1{}; | ||
| 534 | f32 sixaxis_fusion_parameter2{}; | ||
| 535 | bool sixaxis_at_rest{true}; | ||
| 536 | bool is_in_lr_assignment_mode{false}; | 537 | bool is_in_lr_assignment_mode{false}; |
| 537 | }; | 538 | }; |
| 538 | } // namespace Service::HID | 539 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 96e8fb7e1..496b55d0e 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -161,7 +161,7 @@ public: | |||
| 161 | private: | 161 | private: |
| 162 | void InitializeVibrationDevice(Kernel::HLERequestContext& ctx) { | 162 | void InitializeVibrationDevice(Kernel::HLERequestContext& ctx) { |
| 163 | IPC::RequestParser rp{ctx}; | 163 | IPC::RequestParser rp{ctx}; |
| 164 | const auto vibration_device_handle{rp.PopRaw<Controller_NPad::DeviceHandle>()}; | 164 | const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()}; |
| 165 | 165 | ||
| 166 | if (applet_resource != nullptr) { | 166 | if (applet_resource != nullptr) { |
| 167 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 167 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| @@ -417,6 +417,7 @@ void Hid::ActivateXpad(Kernel::HLERequestContext& ctx) { | |||
| 417 | INSERT_PADDING_WORDS_NOINIT(1); | 417 | INSERT_PADDING_WORDS_NOINIT(1); |
| 418 | u64 applet_resource_user_id; | 418 | u64 applet_resource_user_id; |
| 419 | }; | 419 | }; |
| 420 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 420 | 421 | ||
| 421 | const auto parameters{rp.PopRaw<Parameters>()}; | 422 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 422 | 423 | ||
| @@ -443,19 +444,18 @@ void Hid::GetXpadIDs(Kernel::HLERequestContext& ctx) { | |||
| 443 | void Hid::ActivateSixAxisSensor(Kernel::HLERequestContext& ctx) { | 444 | void Hid::ActivateSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 444 | IPC::RequestParser rp{ctx}; | 445 | IPC::RequestParser rp{ctx}; |
| 445 | struct Parameters { | 446 | struct Parameters { |
| 446 | Controller_NPad::DeviceHandle sixaxis_handle; | 447 | u32 basic_xpad_id; |
| 447 | INSERT_PADDING_WORDS_NOINIT(1); | 448 | INSERT_PADDING_WORDS_NOINIT(1); |
| 448 | u64 applet_resource_user_id; | 449 | u64 applet_resource_user_id; |
| 449 | }; | 450 | }; |
| 451 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 450 | 452 | ||
| 451 | const auto parameters{rp.PopRaw<Parameters>()}; | 453 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 452 | 454 | ||
| 453 | applet_resource->GetController<Controller_NPad>(HidController::NPad).SetSixAxisEnabled(true); | 455 | // This function does nothing on 10.0.0+ |
| 454 | 456 | ||
| 455 | LOG_DEBUG(Service_HID, | 457 | LOG_WARNING(Service_HID, "(STUBBED) called, basic_xpad_id={}, applet_resource_user_id={}", |
| 456 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 458 | parameters.basic_xpad_id, parameters.applet_resource_user_id); |
| 457 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | ||
| 458 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 459 | 459 | ||
| 460 | IPC::ResponseBuilder rb{ctx, 2}; | 460 | IPC::ResponseBuilder rb{ctx, 2}; |
| 461 | rb.Push(ResultSuccess); | 461 | rb.Push(ResultSuccess); |
| @@ -464,19 +464,18 @@ void Hid::ActivateSixAxisSensor(Kernel::HLERequestContext& ctx) { | |||
| 464 | void Hid::DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx) { | 464 | void Hid::DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 465 | IPC::RequestParser rp{ctx}; | 465 | IPC::RequestParser rp{ctx}; |
| 466 | struct Parameters { | 466 | struct Parameters { |
| 467 | Controller_NPad::DeviceHandle sixaxis_handle; | 467 | u32 basic_xpad_id; |
| 468 | INSERT_PADDING_WORDS_NOINIT(1); | 468 | INSERT_PADDING_WORDS_NOINIT(1); |
| 469 | u64 applet_resource_user_id; | 469 | u64 applet_resource_user_id; |
| 470 | }; | 470 | }; |
| 471 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 471 | 472 | ||
| 472 | const auto parameters{rp.PopRaw<Parameters>()}; | 473 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 473 | 474 | ||
| 474 | applet_resource->GetController<Controller_NPad>(HidController::NPad).SetSixAxisEnabled(false); | 475 | // This function does nothing on 10.0.0+ |
| 475 | 476 | ||
| 476 | LOG_DEBUG(Service_HID, | 477 | LOG_WARNING(Service_HID, "(STUBBED) called, basic_xpad_id={}, applet_resource_user_id={}", |
| 477 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 478 | parameters.basic_xpad_id, parameters.applet_resource_user_id); |
| 478 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | ||
| 479 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 480 | 479 | ||
| 481 | IPC::ResponseBuilder rb{ctx, 2}; | 480 | IPC::ResponseBuilder rb{ctx, 2}; |
| 482 | rb.Push(ResultSuccess); | 481 | rb.Push(ResultSuccess); |
| @@ -485,14 +484,16 @@ void Hid::DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx) { | |||
| 485 | void Hid::StartSixAxisSensor(Kernel::HLERequestContext& ctx) { | 484 | void Hid::StartSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 486 | IPC::RequestParser rp{ctx}; | 485 | IPC::RequestParser rp{ctx}; |
| 487 | struct Parameters { | 486 | struct Parameters { |
| 488 | Controller_NPad::DeviceHandle sixaxis_handle; | 487 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 489 | INSERT_PADDING_WORDS_NOINIT(1); | 488 | INSERT_PADDING_WORDS_NOINIT(1); |
| 490 | u64 applet_resource_user_id; | 489 | u64 applet_resource_user_id; |
| 491 | }; | 490 | }; |
| 491 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 492 | 492 | ||
| 493 | const auto parameters{rp.PopRaw<Parameters>()}; | 493 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 494 | 494 | ||
| 495 | applet_resource->GetController<Controller_NPad>(HidController::NPad).SetSixAxisEnabled(true); | 495 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 496 | .SetSixAxisEnabled(parameters.sixaxis_handle, true); | ||
| 496 | 497 | ||
| 497 | LOG_DEBUG(Service_HID, | 498 | LOG_DEBUG(Service_HID, |
| 498 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 499 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", |
| @@ -506,14 +507,16 @@ void Hid::StartSixAxisSensor(Kernel::HLERequestContext& ctx) { | |||
| 506 | void Hid::StopSixAxisSensor(Kernel::HLERequestContext& ctx) { | 507 | void Hid::StopSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 507 | IPC::RequestParser rp{ctx}; | 508 | IPC::RequestParser rp{ctx}; |
| 508 | struct Parameters { | 509 | struct Parameters { |
| 509 | Controller_NPad::DeviceHandle sixaxis_handle; | 510 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 510 | INSERT_PADDING_WORDS_NOINIT(1); | 511 | INSERT_PADDING_WORDS_NOINIT(1); |
| 511 | u64 applet_resource_user_id; | 512 | u64 applet_resource_user_id; |
| 512 | }; | 513 | }; |
| 514 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 513 | 515 | ||
| 514 | const auto parameters{rp.PopRaw<Parameters>()}; | 516 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 515 | 517 | ||
| 516 | applet_resource->GetController<Controller_NPad>(HidController::NPad).SetSixAxisEnabled(false); | 518 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 519 | .SetSixAxisEnabled(parameters.sixaxis_handle, false); | ||
| 517 | 520 | ||
| 518 | LOG_DEBUG(Service_HID, | 521 | LOG_DEBUG(Service_HID, |
| 519 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 522 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", |
| @@ -529,19 +532,23 @@ void Hid::EnableSixAxisSensorFusion(Kernel::HLERequestContext& ctx) { | |||
| 529 | struct Parameters { | 532 | struct Parameters { |
| 530 | bool enable_sixaxis_sensor_fusion; | 533 | bool enable_sixaxis_sensor_fusion; |
| 531 | INSERT_PADDING_BYTES_NOINIT(3); | 534 | INSERT_PADDING_BYTES_NOINIT(3); |
| 532 | Controller_NPad::DeviceHandle sixaxis_handle; | 535 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 533 | u64 applet_resource_user_id; | 536 | u64 applet_resource_user_id; |
| 534 | }; | 537 | }; |
| 535 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | 538 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); |
| 536 | 539 | ||
| 537 | const auto parameters{rp.PopRaw<Parameters>()}; | 540 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 538 | 541 | ||
| 539 | LOG_WARNING(Service_HID, | 542 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 540 | "(STUBBED) called, enable_sixaxis_sensor_fusion={}, npad_type={}, npad_id={}, " | 543 | .SetSixAxisFusionEnabled(parameters.sixaxis_handle, |
| 541 | "device_index={}, applet_resource_user_id={}", | 544 | parameters.enable_sixaxis_sensor_fusion); |
| 542 | parameters.enable_sixaxis_sensor_fusion, parameters.sixaxis_handle.npad_type, | 545 | |
| 543 | parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, | 546 | LOG_DEBUG(Service_HID, |
| 544 | parameters.applet_resource_user_id); | 547 | "called, enable_sixaxis_sensor_fusion={}, npad_type={}, npad_id={}, " |
| 548 | "device_index={}, applet_resource_user_id={}", | ||
| 549 | parameters.enable_sixaxis_sensor_fusion, parameters.sixaxis_handle.npad_type, | ||
| 550 | parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, | ||
| 551 | parameters.applet_resource_user_id); | ||
| 545 | 552 | ||
| 546 | IPC::ResponseBuilder rb{ctx, 2}; | 553 | IPC::ResponseBuilder rb{ctx, 2}; |
| 547 | rb.Push(ResultSuccess); | 554 | rb.Push(ResultSuccess); |
| @@ -550,9 +557,9 @@ void Hid::EnableSixAxisSensorFusion(Kernel::HLERequestContext& ctx) { | |||
| 550 | void Hid::SetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | 557 | void Hid::SetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { |
| 551 | IPC::RequestParser rp{ctx}; | 558 | IPC::RequestParser rp{ctx}; |
| 552 | struct Parameters { | 559 | struct Parameters { |
| 553 | Controller_NPad::DeviceHandle sixaxis_handle; | 560 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 554 | f32 parameter1; | 561 | Core::HID::SixAxisSensorFusionParameters sixaxis_fusion; |
| 555 | f32 parameter2; | 562 | INSERT_PADDING_WORDS_NOINIT(1); |
| 556 | u64 applet_resource_user_id; | 563 | u64 applet_resource_user_id; |
| 557 | }; | 564 | }; |
| 558 | static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); | 565 | static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); |
| @@ -560,14 +567,14 @@ void Hid::SetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | |||
| 560 | const auto parameters{rp.PopRaw<Parameters>()}; | 567 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 561 | 568 | ||
| 562 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 569 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 563 | .SetSixAxisFusionParameters(parameters.parameter1, parameters.parameter2); | 570 | .SetSixAxisFusionParameters(parameters.sixaxis_handle, parameters.sixaxis_fusion); |
| 564 | 571 | ||
| 565 | LOG_WARNING(Service_HID, | 572 | LOG_DEBUG(Service_HID, |
| 566 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, parameter1={}, " | 573 | "called, npad_type={}, npad_id={}, device_index={}, parameter1={}, " |
| 567 | "parameter2={}, applet_resource_user_id={}", | 574 | "parameter2={}, applet_resource_user_id={}", |
| 568 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | 575 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, |
| 569 | parameters.sixaxis_handle.device_index, parameters.parameter1, | 576 | parameters.sixaxis_handle.device_index, parameters.sixaxis_fusion.parameter1, |
| 570 | parameters.parameter2, parameters.applet_resource_user_id); | 577 | parameters.sixaxis_fusion.parameter2, parameters.applet_resource_user_id); |
| 571 | 578 | ||
| 572 | IPC::ResponseBuilder rb{ctx, 2}; | 579 | IPC::ResponseBuilder rb{ctx, 2}; |
| 573 | rb.Push(ResultSuccess); | 580 | rb.Push(ResultSuccess); |
| @@ -576,35 +583,33 @@ void Hid::SetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | |||
| 576 | void Hid::GetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | 583 | void Hid::GetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { |
| 577 | IPC::RequestParser rp{ctx}; | 584 | IPC::RequestParser rp{ctx}; |
| 578 | struct Parameters { | 585 | struct Parameters { |
| 579 | Controller_NPad::DeviceHandle sixaxis_handle; | 586 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 587 | INSERT_PADDING_WORDS_NOINIT(1); | ||
| 580 | u64 applet_resource_user_id; | 588 | u64 applet_resource_user_id; |
| 581 | }; | 589 | }; |
| 582 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | 590 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); |
| 583 | 591 | ||
| 584 | f32 parameter1 = 0; | ||
| 585 | f32 parameter2 = 0; | ||
| 586 | const auto parameters{rp.PopRaw<Parameters>()}; | 592 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 587 | 593 | ||
| 588 | std::tie(parameter1, parameter2) = | 594 | const auto sixaxis_fusion_parameters = |
| 589 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 595 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 590 | .GetSixAxisFusionParameters(); | 596 | .GetSixAxisFusionParameters(parameters.sixaxis_handle); |
| 591 | 597 | ||
| 592 | LOG_WARNING( | 598 | LOG_DEBUG(Service_HID, |
| 593 | Service_HID, | 599 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", |
| 594 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 600 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, |
| 595 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | 601 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); |
| 596 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 597 | 602 | ||
| 598 | IPC::ResponseBuilder rb{ctx, 4}; | 603 | IPC::ResponseBuilder rb{ctx, 4}; |
| 599 | rb.Push(ResultSuccess); | 604 | rb.Push(ResultSuccess); |
| 600 | rb.Push(parameter1); | 605 | rb.PushRaw(sixaxis_fusion_parameters); |
| 601 | rb.Push(parameter2); | ||
| 602 | } | 606 | } |
| 603 | 607 | ||
| 604 | void Hid::ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | 608 | void Hid::ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { |
| 605 | IPC::RequestParser rp{ctx}; | 609 | IPC::RequestParser rp{ctx}; |
| 606 | struct Parameters { | 610 | struct Parameters { |
| 607 | Controller_NPad::DeviceHandle sixaxis_handle; | 611 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 612 | INSERT_PADDING_WORDS_NOINIT(1); | ||
| 608 | u64 applet_resource_user_id; | 613 | u64 applet_resource_user_id; |
| 609 | }; | 614 | }; |
| 610 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | 615 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); |
| @@ -612,13 +617,12 @@ void Hid::ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | |||
| 612 | const auto parameters{rp.PopRaw<Parameters>()}; | 617 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 613 | 618 | ||
| 614 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 619 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 615 | .ResetSixAxisFusionParameters(); | 620 | .ResetSixAxisFusionParameters(parameters.sixaxis_handle); |
| 616 | 621 | ||
| 617 | LOG_WARNING( | 622 | LOG_DEBUG(Service_HID, |
| 618 | Service_HID, | 623 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", |
| 619 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 624 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, |
| 620 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | 625 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); |
| 621 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 622 | 626 | ||
| 623 | IPC::ResponseBuilder rb{ctx, 2}; | 627 | IPC::ResponseBuilder rb{ctx, 2}; |
| 624 | rb.Push(ResultSuccess); | 628 | rb.Push(ResultSuccess); |
| @@ -626,12 +630,12 @@ void Hid::ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | |||
| 626 | 630 | ||
| 627 | void Hid::SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | 631 | void Hid::SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { |
| 628 | IPC::RequestParser rp{ctx}; | 632 | IPC::RequestParser rp{ctx}; |
| 629 | const auto sixaxis_handle{rp.PopRaw<Controller_NPad::DeviceHandle>()}; | 633 | const auto sixaxis_handle{rp.PopRaw<Core::HID::SixAxisSensorHandle>()}; |
| 630 | const auto drift_mode{rp.PopEnum<Controller_NPad::GyroscopeZeroDriftMode>()}; | 634 | const auto drift_mode{rp.PopEnum<Controller_NPad::GyroscopeZeroDriftMode>()}; |
| 631 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 635 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| 632 | 636 | ||
| 633 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 637 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 634 | .SetGyroscopeZeroDriftMode(drift_mode); | 638 | .SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode); |
| 635 | 639 | ||
| 636 | LOG_DEBUG(Service_HID, | 640 | LOG_DEBUG(Service_HID, |
| 637 | "called, npad_type={}, npad_id={}, device_index={}, drift_mode={}, " | 641 | "called, npad_type={}, npad_id={}, device_index={}, drift_mode={}, " |
| @@ -646,10 +650,11 @@ void Hid::SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | |||
| 646 | void Hid::GetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | 650 | void Hid::GetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { |
| 647 | IPC::RequestParser rp{ctx}; | 651 | IPC::RequestParser rp{ctx}; |
| 648 | struct Parameters { | 652 | struct Parameters { |
| 649 | Controller_NPad::DeviceHandle sixaxis_handle; | 653 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 650 | INSERT_PADDING_WORDS_NOINIT(1); | 654 | INSERT_PADDING_WORDS_NOINIT(1); |
| 651 | u64 applet_resource_user_id; | 655 | u64 applet_resource_user_id; |
| 652 | }; | 656 | }; |
| 657 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 653 | 658 | ||
| 654 | const auto parameters{rp.PopRaw<Parameters>()}; | 659 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 655 | 660 | ||
| @@ -661,21 +666,23 @@ void Hid::GetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | |||
| 661 | IPC::ResponseBuilder rb{ctx, 3}; | 666 | IPC::ResponseBuilder rb{ctx, 3}; |
| 662 | rb.Push(ResultSuccess); | 667 | rb.Push(ResultSuccess); |
| 663 | rb.PushEnum(applet_resource->GetController<Controller_NPad>(HidController::NPad) | 668 | rb.PushEnum(applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 664 | .GetGyroscopeZeroDriftMode()); | 669 | .GetGyroscopeZeroDriftMode(parameters.sixaxis_handle)); |
| 665 | } | 670 | } |
| 666 | 671 | ||
| 667 | void Hid::ResetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | 672 | void Hid::ResetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { |
| 668 | IPC::RequestParser rp{ctx}; | 673 | IPC::RequestParser rp{ctx}; |
| 669 | struct Parameters { | 674 | struct Parameters { |
| 670 | Controller_NPad::DeviceHandle sixaxis_handle; | 675 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 671 | INSERT_PADDING_WORDS_NOINIT(1); | 676 | INSERT_PADDING_WORDS_NOINIT(1); |
| 672 | u64 applet_resource_user_id; | 677 | u64 applet_resource_user_id; |
| 673 | }; | 678 | }; |
| 679 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 674 | 680 | ||
| 675 | const auto parameters{rp.PopRaw<Parameters>()}; | 681 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 682 | const auto drift_mode{Controller_NPad::GyroscopeZeroDriftMode::Standard}; | ||
| 676 | 683 | ||
| 677 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 684 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 678 | .SetGyroscopeZeroDriftMode(Controller_NPad::GyroscopeZeroDriftMode::Standard); | 685 | .SetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); |
| 679 | 686 | ||
| 680 | LOG_DEBUG(Service_HID, | 687 | LOG_DEBUG(Service_HID, |
| 681 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 688 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", |
| @@ -689,10 +696,11 @@ void Hid::ResetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | |||
| 689 | void Hid::IsSixAxisSensorAtRest(Kernel::HLERequestContext& ctx) { | 696 | void Hid::IsSixAxisSensorAtRest(Kernel::HLERequestContext& ctx) { |
| 690 | IPC::RequestParser rp{ctx}; | 697 | IPC::RequestParser rp{ctx}; |
| 691 | struct Parameters { | 698 | struct Parameters { |
| 692 | Controller_NPad::DeviceHandle sixaxis_handle; | 699 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 693 | INSERT_PADDING_WORDS_NOINIT(1); | 700 | INSERT_PADDING_WORDS_NOINIT(1); |
| 694 | u64 applet_resource_user_id; | 701 | u64 applet_resource_user_id; |
| 695 | }; | 702 | }; |
| 703 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 696 | 704 | ||
| 697 | const auto parameters{rp.PopRaw<Parameters>()}; | 705 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 698 | 706 | ||
| @@ -704,16 +712,17 @@ void Hid::IsSixAxisSensorAtRest(Kernel::HLERequestContext& ctx) { | |||
| 704 | IPC::ResponseBuilder rb{ctx, 3}; | 712 | IPC::ResponseBuilder rb{ctx, 3}; |
| 705 | rb.Push(ResultSuccess); | 713 | rb.Push(ResultSuccess); |
| 706 | rb.Push(applet_resource->GetController<Controller_NPad>(HidController::NPad) | 714 | rb.Push(applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 707 | .IsSixAxisSensorAtRest()); | 715 | .IsSixAxisSensorAtRest(parameters.sixaxis_handle)); |
| 708 | } | 716 | } |
| 709 | 717 | ||
| 710 | void Hid::IsFirmwareUpdateAvailableForSixAxisSensor(Kernel::HLERequestContext& ctx) { | 718 | void Hid::IsFirmwareUpdateAvailableForSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 711 | IPC::RequestParser rp{ctx}; | 719 | IPC::RequestParser rp{ctx}; |
| 712 | struct Parameters { | 720 | struct Parameters { |
| 713 | Controller_NPad::DeviceHandle sixaxis_handle; | 721 | Core::HID::SixAxisSensorHandle sixaxis_handle; |
| 714 | INSERT_PADDING_WORDS_NOINIT(1); | 722 | INSERT_PADDING_WORDS_NOINIT(1); |
| 715 | u64 applet_resource_user_id; | 723 | u64 applet_resource_user_id; |
| 716 | }; | 724 | }; |
| 725 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 717 | 726 | ||
| 718 | const auto parameters{rp.PopRaw<Parameters>()}; | 727 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 719 | 728 | ||
| @@ -735,13 +744,14 @@ void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) { | |||
| 735 | INSERT_PADDING_WORDS_NOINIT(1); | 744 | INSERT_PADDING_WORDS_NOINIT(1); |
| 736 | u64 applet_resource_user_id; | 745 | u64 applet_resource_user_id; |
| 737 | }; | 746 | }; |
| 747 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 738 | 748 | ||
| 739 | const auto parameters{rp.PopRaw<Parameters>()}; | 749 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 740 | 750 | ||
| 741 | applet_resource->ActivateController(HidController::Gesture); | 751 | applet_resource->ActivateController(HidController::Gesture); |
| 742 | 752 | ||
| 743 | LOG_DEBUG(Service_HID, "called, unknown={}, applet_resource_user_id={}", parameters.unknown, | 753 | LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, applet_resource_user_id={}", |
| 744 | parameters.applet_resource_user_id); | 754 | parameters.unknown, parameters.applet_resource_user_id); |
| 745 | 755 | ||
| 746 | IPC::ResponseBuilder rb{ctx, 2}; | 756 | IPC::ResponseBuilder rb{ctx, 2}; |
| 747 | rb.Push(ResultSuccess); | 757 | rb.Push(ResultSuccess); |
| @@ -749,12 +759,20 @@ void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) { | |||
| 749 | 759 | ||
| 750 | void Hid::SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { | 760 | void Hid::SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { |
| 751 | IPC::RequestParser rp{ctx}; | 761 | IPC::RequestParser rp{ctx}; |
| 752 | const auto supported_styleset{rp.Pop<u32>()}; | 762 | struct Parameters { |
| 763 | Core::HID::NpadStyleSet supported_styleset; | ||
| 764 | INSERT_PADDING_WORDS_NOINIT(1); | ||
| 765 | u64 applet_resource_user_id; | ||
| 766 | }; | ||
| 767 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 768 | |||
| 769 | const auto parameters{rp.PopRaw<Parameters>()}; | ||
| 753 | 770 | ||
| 754 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 771 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 755 | .SetSupportedStyleSet({supported_styleset}); | 772 | .SetSupportedStyleSet({parameters.supported_styleset}); |
| 756 | 773 | ||
| 757 | LOG_DEBUG(Service_HID, "called, supported_styleset={}", supported_styleset); | 774 | LOG_DEBUG(Service_HID, "called, supported_styleset={}, applet_resource_user_id={}", |
| 775 | parameters.supported_styleset, parameters.applet_resource_user_id); | ||
| 758 | 776 | ||
| 759 | IPC::ResponseBuilder rb{ctx, 2}; | 777 | IPC::ResponseBuilder rb{ctx, 2}; |
| 760 | rb.Push(ResultSuccess); | 778 | rb.Push(ResultSuccess); |
| @@ -768,9 +786,9 @@ void Hid::GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { | |||
| 768 | 786 | ||
| 769 | IPC::ResponseBuilder rb{ctx, 3}; | 787 | IPC::ResponseBuilder rb{ctx, 3}; |
| 770 | rb.Push(ResultSuccess); | 788 | rb.Push(ResultSuccess); |
| 771 | rb.Push(applet_resource->GetController<Controller_NPad>(HidController::NPad) | 789 | rb.PushEnum(applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 772 | .GetSupportedStyleSet() | 790 | .GetSupportedStyleSet() |
| 773 | .raw); | 791 | .raw); |
| 774 | } | 792 | } |
| 775 | 793 | ||
| 776 | void Hid::SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { | 794 | void Hid::SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { |
| @@ -813,11 +831,12 @@ void Hid::DeactivateNpad(Kernel::HLERequestContext& ctx) { | |||
| 813 | void Hid::AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { | 831 | void Hid::AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { |
| 814 | IPC::RequestParser rp{ctx}; | 832 | IPC::RequestParser rp{ctx}; |
| 815 | struct Parameters { | 833 | struct Parameters { |
| 816 | u32 npad_id; | 834 | Core::HID::NpadIdType npad_id; |
| 817 | INSERT_PADDING_WORDS_NOINIT(1); | 835 | INSERT_PADDING_WORDS_NOINIT(1); |
| 818 | u64 applet_resource_user_id; | 836 | u64 applet_resource_user_id; |
| 819 | u64 unknown; | 837 | u64 unknown; |
| 820 | }; | 838 | }; |
| 839 | static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); | ||
| 821 | 840 | ||
| 822 | const auto parameters{rp.PopRaw<Parameters>()}; | 841 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 823 | 842 | ||
| @@ -833,10 +852,11 @@ void Hid::AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { | |||
| 833 | void Hid::DisconnectNpad(Kernel::HLERequestContext& ctx) { | 852 | void Hid::DisconnectNpad(Kernel::HLERequestContext& ctx) { |
| 834 | IPC::RequestParser rp{ctx}; | 853 | IPC::RequestParser rp{ctx}; |
| 835 | struct Parameters { | 854 | struct Parameters { |
| 836 | u32 npad_id; | 855 | Core::HID::NpadIdType npad_id; |
| 837 | INSERT_PADDING_WORDS_NOINIT(1); | 856 | INSERT_PADDING_WORDS_NOINIT(1); |
| 838 | u64 applet_resource_user_id; | 857 | u64 applet_resource_user_id; |
| 839 | }; | 858 | }; |
| 859 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 840 | 860 | ||
| 841 | const auto parameters{rp.PopRaw<Parameters>()}; | 861 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 842 | 862 | ||
| @@ -852,7 +872,7 @@ void Hid::DisconnectNpad(Kernel::HLERequestContext& ctx) { | |||
| 852 | 872 | ||
| 853 | void Hid::GetPlayerLedPattern(Kernel::HLERequestContext& ctx) { | 873 | void Hid::GetPlayerLedPattern(Kernel::HLERequestContext& ctx) { |
| 854 | IPC::RequestParser rp{ctx}; | 874 | IPC::RequestParser rp{ctx}; |
| 855 | const auto npad_id{rp.Pop<u32>()}; | 875 | const auto npad_id{rp.PopEnum<Core::HID::NpadIdType>()}; |
| 856 | 876 | ||
| 857 | LOG_DEBUG(Service_HID, "called, npad_id={}", npad_id); | 877 | LOG_DEBUG(Service_HID, "called, npad_id={}", npad_id); |
| 858 | 878 | ||
| @@ -867,16 +887,17 @@ void Hid::ActivateNpadWithRevision(Kernel::HLERequestContext& ctx) { | |||
| 867 | // Should have no effect with how our npad sets up the data | 887 | // Should have no effect with how our npad sets up the data |
| 868 | IPC::RequestParser rp{ctx}; | 888 | IPC::RequestParser rp{ctx}; |
| 869 | struct Parameters { | 889 | struct Parameters { |
| 870 | u32 unknown; | 890 | s32 revision; |
| 871 | INSERT_PADDING_WORDS_NOINIT(1); | 891 | INSERT_PADDING_WORDS_NOINIT(1); |
| 872 | u64 applet_resource_user_id; | 892 | u64 applet_resource_user_id; |
| 873 | }; | 893 | }; |
| 894 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 874 | 895 | ||
| 875 | const auto parameters{rp.PopRaw<Parameters>()}; | 896 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 876 | 897 | ||
| 877 | applet_resource->ActivateController(HidController::NPad); | 898 | applet_resource->ActivateController(HidController::NPad); |
| 878 | 899 | ||
| 879 | LOG_DEBUG(Service_HID, "called, unknown={}, applet_resource_user_id={}", parameters.unknown, | 900 | LOG_DEBUG(Service_HID, "called, revision={}, applet_resource_user_id={}", parameters.revision, |
| 880 | parameters.applet_resource_user_id); | 901 | parameters.applet_resource_user_id); |
| 881 | 902 | ||
| 882 | IPC::ResponseBuilder rb{ctx, 2}; | 903 | IPC::ResponseBuilder rb{ctx, 2}; |
| @@ -911,10 +932,11 @@ void Hid::GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { | |||
| 911 | void Hid::SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx) { | 932 | void Hid::SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx) { |
| 912 | IPC::RequestParser rp{ctx}; | 933 | IPC::RequestParser rp{ctx}; |
| 913 | struct Parameters { | 934 | struct Parameters { |
| 914 | u32 npad_id; | 935 | Core::HID::NpadIdType npad_id; |
| 915 | INSERT_PADDING_WORDS_NOINIT(1); | 936 | INSERT_PADDING_WORDS_NOINIT(1); |
| 916 | u64 applet_resource_user_id; | 937 | u64 applet_resource_user_id; |
| 917 | }; | 938 | }; |
| 939 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 918 | 940 | ||
| 919 | const auto parameters{rp.PopRaw<Parameters>()}; | 941 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 920 | 942 | ||
| @@ -932,11 +954,12 @@ void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) { | |||
| 932 | // TODO: Check the differences between this and SetNpadJoyAssignmentModeSingleByDefault | 954 | // TODO: Check the differences between this and SetNpadJoyAssignmentModeSingleByDefault |
| 933 | IPC::RequestParser rp{ctx}; | 955 | IPC::RequestParser rp{ctx}; |
| 934 | struct Parameters { | 956 | struct Parameters { |
| 935 | u32 npad_id; | 957 | Core::HID::NpadIdType npad_id; |
| 936 | INSERT_PADDING_WORDS_NOINIT(1); | 958 | INSERT_PADDING_WORDS_NOINIT(1); |
| 937 | u64 applet_resource_user_id; | 959 | u64 applet_resource_user_id; |
| 938 | u64 npad_joy_device_type; | 960 | u64 npad_joy_device_type; |
| 939 | }; | 961 | }; |
| 962 | static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); | ||
| 940 | 963 | ||
| 941 | const auto parameters{rp.PopRaw<Parameters>()}; | 964 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 942 | 965 | ||
| @@ -955,10 +978,11 @@ void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) { | |||
| 955 | void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { | 978 | void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { |
| 956 | IPC::RequestParser rp{ctx}; | 979 | IPC::RequestParser rp{ctx}; |
| 957 | struct Parameters { | 980 | struct Parameters { |
| 958 | u32 npad_id; | 981 | Core::HID::NpadIdType npad_id; |
| 959 | INSERT_PADDING_WORDS_NOINIT(1); | 982 | INSERT_PADDING_WORDS_NOINIT(1); |
| 960 | u64 applet_resource_user_id; | 983 | u64 applet_resource_user_id; |
| 961 | }; | 984 | }; |
| 985 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 962 | 986 | ||
| 963 | const auto parameters{rp.PopRaw<Parameters>()}; | 987 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 964 | 988 | ||
| @@ -974,8 +998,8 @@ void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { | |||
| 974 | 998 | ||
| 975 | void Hid::MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) { | 999 | void Hid::MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) { |
| 976 | IPC::RequestParser rp{ctx}; | 1000 | IPC::RequestParser rp{ctx}; |
| 977 | const auto npad_id_1{rp.Pop<u32>()}; | 1001 | const auto npad_id_1{rp.PopEnum<Core::HID::NpadIdType>()}; |
| 978 | const auto npad_id_2{rp.Pop<u32>()}; | 1002 | const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()}; |
| 979 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 1003 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| 980 | 1004 | ||
| 981 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 1005 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| @@ -1041,8 +1065,8 @@ void Hid::GetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx) { | |||
| 1041 | 1065 | ||
| 1042 | void Hid::SwapNpadAssignment(Kernel::HLERequestContext& ctx) { | 1066 | void Hid::SwapNpadAssignment(Kernel::HLERequestContext& ctx) { |
| 1043 | IPC::RequestParser rp{ctx}; | 1067 | IPC::RequestParser rp{ctx}; |
| 1044 | const auto npad_id_1{rp.Pop<u32>()}; | 1068 | const auto npad_id_1{rp.PopEnum<Core::HID::NpadIdType>()}; |
| 1045 | const auto npad_id_2{rp.Pop<u32>()}; | 1069 | const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()}; |
| 1046 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 1070 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| 1047 | 1071 | ||
| 1048 | const bool res = applet_resource->GetController<Controller_NPad>(HidController::NPad) | 1072 | const bool res = applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| @@ -1063,10 +1087,11 @@ void Hid::SwapNpadAssignment(Kernel::HLERequestContext& ctx) { | |||
| 1063 | void Hid::IsUnintendedHomeButtonInputProtectionEnabled(Kernel::HLERequestContext& ctx) { | 1087 | void Hid::IsUnintendedHomeButtonInputProtectionEnabled(Kernel::HLERequestContext& ctx) { |
| 1064 | IPC::RequestParser rp{ctx}; | 1088 | IPC::RequestParser rp{ctx}; |
| 1065 | struct Parameters { | 1089 | struct Parameters { |
| 1066 | u32 npad_id; | 1090 | Core::HID::NpadIdType npad_id; |
| 1067 | INSERT_PADDING_WORDS_NOINIT(1); | 1091 | INSERT_PADDING_WORDS_NOINIT(1); |
| 1068 | u64 applet_resource_user_id; | 1092 | u64 applet_resource_user_id; |
| 1069 | }; | 1093 | }; |
| 1094 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 1070 | 1095 | ||
| 1071 | const auto parameters{rp.PopRaw<Parameters>()}; | 1096 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1072 | 1097 | ||
| @@ -1084,9 +1109,10 @@ void Hid::EnableUnintendedHomeButtonInputProtection(Kernel::HLERequestContext& c | |||
| 1084 | struct Parameters { | 1109 | struct Parameters { |
| 1085 | bool unintended_home_button_input_protection; | 1110 | bool unintended_home_button_input_protection; |
| 1086 | INSERT_PADDING_BYTES_NOINIT(3); | 1111 | INSERT_PADDING_BYTES_NOINIT(3); |
| 1087 | u32 npad_id; | 1112 | Core::HID::NpadIdType npad_id; |
| 1088 | u64 applet_resource_user_id; | 1113 | u64 applet_resource_user_id; |
| 1089 | }; | 1114 | }; |
| 1115 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 1090 | 1116 | ||
| 1091 | const auto parameters{rp.PopRaw<Parameters>()}; | 1117 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1092 | 1118 | ||
| @@ -1108,6 +1134,7 @@ void Hid::SetNpadAnalogStickUseCenterClamp(Kernel::HLERequestContext& ctx) { | |||
| 1108 | IPC::RequestParser rp{ctx}; | 1134 | IPC::RequestParser rp{ctx}; |
| 1109 | struct Parameters { | 1135 | struct Parameters { |
| 1110 | bool analog_stick_use_center_clamp; | 1136 | bool analog_stick_use_center_clamp; |
| 1137 | INSERT_PADDING_BYTES_NOINIT(7); | ||
| 1111 | u64 applet_resource_user_id; | 1138 | u64 applet_resource_user_id; |
| 1112 | }; | 1139 | }; |
| 1113 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | 1140 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); |
| @@ -1127,7 +1154,7 @@ void Hid::SetNpadAnalogStickUseCenterClamp(Kernel::HLERequestContext& ctx) { | |||
| 1127 | 1154 | ||
| 1128 | void Hid::GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { | 1155 | void Hid::GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { |
| 1129 | IPC::RequestParser rp{ctx}; | 1156 | IPC::RequestParser rp{ctx}; |
| 1130 | const auto vibration_device_handle{rp.PopRaw<Controller_NPad::DeviceHandle>()}; | 1157 | const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()}; |
| 1131 | 1158 | ||
| 1132 | Core::HID::VibrationDeviceInfo vibration_device_info; | 1159 | Core::HID::VibrationDeviceInfo vibration_device_info; |
| 1133 | 1160 | ||
| @@ -1149,13 +1176,13 @@ void Hid::GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { | |||
| 1149 | } | 1176 | } |
| 1150 | 1177 | ||
| 1151 | switch (vibration_device_handle.device_index) { | 1178 | switch (vibration_device_handle.device_index) { |
| 1152 | case Controller_NPad::DeviceIndex::Left: | 1179 | case Core::HID::DeviceIndex::Left: |
| 1153 | vibration_device_info.position = Core::HID::VibrationDevicePosition::Left; | 1180 | vibration_device_info.position = Core::HID::VibrationDevicePosition::Left; |
| 1154 | break; | 1181 | break; |
| 1155 | case Controller_NPad::DeviceIndex::Right: | 1182 | case Core::HID::DeviceIndex::Right: |
| 1156 | vibration_device_info.position = Core::HID::VibrationDevicePosition::Right; | 1183 | vibration_device_info.position = Core::HID::VibrationDevicePosition::Right; |
| 1157 | break; | 1184 | break; |
| 1158 | case Controller_NPad::DeviceIndex::None: | 1185 | case Core::HID::DeviceIndex::None: |
| 1159 | default: | 1186 | default: |
| 1160 | UNREACHABLE_MSG("DeviceIndex should never be None!"); | 1187 | UNREACHABLE_MSG("DeviceIndex should never be None!"); |
| 1161 | vibration_device_info.position = Core::HID::VibrationDevicePosition::None; | 1188 | vibration_device_info.position = Core::HID::VibrationDevicePosition::None; |
| @@ -1173,11 +1200,12 @@ void Hid::GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { | |||
| 1173 | void Hid::SendVibrationValue(Kernel::HLERequestContext& ctx) { | 1200 | void Hid::SendVibrationValue(Kernel::HLERequestContext& ctx) { |
| 1174 | IPC::RequestParser rp{ctx}; | 1201 | IPC::RequestParser rp{ctx}; |
| 1175 | struct Parameters { | 1202 | struct Parameters { |
| 1176 | Controller_NPad::DeviceHandle vibration_device_handle; | 1203 | Core::HID::VibrationDeviceHandle vibration_device_handle; |
| 1177 | Controller_NPad::VibrationValue vibration_value; | 1204 | Core::HID::VibrationValue vibration_value; |
| 1178 | INSERT_PADDING_WORDS_NOINIT(1); | 1205 | INSERT_PADDING_WORDS_NOINIT(1); |
| 1179 | u64 applet_resource_user_id; | 1206 | u64 applet_resource_user_id; |
| 1180 | }; | 1207 | }; |
| 1208 | static_assert(sizeof(Parameters) == 0x20, "Parameters has incorrect size."); | ||
| 1181 | 1209 | ||
| 1182 | const auto parameters{rp.PopRaw<Parameters>()}; | 1210 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1183 | 1211 | ||
| @@ -1197,10 +1225,11 @@ void Hid::SendVibrationValue(Kernel::HLERequestContext& ctx) { | |||
| 1197 | void Hid::GetActualVibrationValue(Kernel::HLERequestContext& ctx) { | 1225 | void Hid::GetActualVibrationValue(Kernel::HLERequestContext& ctx) { |
| 1198 | IPC::RequestParser rp{ctx}; | 1226 | IPC::RequestParser rp{ctx}; |
| 1199 | struct Parameters { | 1227 | struct Parameters { |
| 1200 | Controller_NPad::DeviceHandle vibration_device_handle; | 1228 | Core::HID::VibrationDeviceHandle vibration_device_handle; |
| 1201 | INSERT_PADDING_WORDS_NOINIT(1); | 1229 | INSERT_PADDING_WORDS_NOINIT(1); |
| 1202 | u64 applet_resource_user_id; | 1230 | u64 applet_resource_user_id; |
| 1203 | }; | 1231 | }; |
| 1232 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 1204 | 1233 | ||
| 1205 | const auto parameters{rp.PopRaw<Parameters>()}; | 1234 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1206 | 1235 | ||
| @@ -1251,10 +1280,10 @@ void Hid::SendVibrationValues(Kernel::HLERequestContext& ctx) { | |||
| 1251 | const auto handles = ctx.ReadBuffer(0); | 1280 | const auto handles = ctx.ReadBuffer(0); |
| 1252 | const auto vibrations = ctx.ReadBuffer(1); | 1281 | const auto vibrations = ctx.ReadBuffer(1); |
| 1253 | 1282 | ||
| 1254 | std::vector<Controller_NPad::DeviceHandle> vibration_device_handles( | 1283 | std::vector<Core::HID::VibrationDeviceHandle> vibration_device_handles( |
| 1255 | handles.size() / sizeof(Controller_NPad::DeviceHandle)); | 1284 | handles.size() / sizeof(Core::HID::VibrationDeviceHandle)); |
| 1256 | std::vector<Controller_NPad::VibrationValue> vibration_values( | 1285 | std::vector<Core::HID::VibrationValue> vibration_values(vibrations.size() / |
| 1257 | vibrations.size() / sizeof(Controller_NPad::VibrationValue)); | 1286 | sizeof(Core::HID::VibrationValue)); |
| 1258 | 1287 | ||
| 1259 | std::memcpy(vibration_device_handles.data(), handles.data(), handles.size()); | 1288 | std::memcpy(vibration_device_handles.data(), handles.data(), handles.size()); |
| 1260 | std::memcpy(vibration_values.data(), vibrations.data(), vibrations.size()); | 1289 | std::memcpy(vibration_values.data(), vibrations.data(), vibrations.size()); |
| @@ -1271,7 +1300,8 @@ void Hid::SendVibrationValues(Kernel::HLERequestContext& ctx) { | |||
| 1271 | void Hid::SendVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { | 1300 | void Hid::SendVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { |
| 1272 | IPC::RequestParser rp{ctx}; | 1301 | IPC::RequestParser rp{ctx}; |
| 1273 | struct Parameters { | 1302 | struct Parameters { |
| 1274 | Controller_NPad::DeviceHandle vibration_device_handle; | 1303 | Core::HID::VibrationDeviceHandle vibration_device_handle; |
| 1304 | INSERT_PADDING_WORDS_NOINIT(1); | ||
| 1275 | u64 applet_resource_user_id; | 1305 | u64 applet_resource_user_id; |
| 1276 | Core::HID::VibrationGcErmCommand gc_erm_command; | 1306 | Core::HID::VibrationGcErmCommand gc_erm_command; |
| 1277 | }; | 1307 | }; |
| @@ -1288,25 +1318,25 @@ void Hid::SendVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { | |||
| 1288 | const auto vibration_value = [parameters] { | 1318 | const auto vibration_value = [parameters] { |
| 1289 | switch (parameters.gc_erm_command) { | 1319 | switch (parameters.gc_erm_command) { |
| 1290 | case Core::HID::VibrationGcErmCommand::Stop: | 1320 | case Core::HID::VibrationGcErmCommand::Stop: |
| 1291 | return Controller_NPad::VibrationValue{ | 1321 | return Core::HID::VibrationValue{ |
| 1292 | .amp_low = 0.0f, | 1322 | .low_amplitude = 0.0f, |
| 1293 | .freq_low = 160.0f, | 1323 | .low_frequency = 160.0f, |
| 1294 | .amp_high = 0.0f, | 1324 | .high_amplitude = 0.0f, |
| 1295 | .freq_high = 320.0f, | 1325 | .high_frequency = 320.0f, |
| 1296 | }; | 1326 | }; |
| 1297 | case Core::HID::VibrationGcErmCommand::Start: | 1327 | case Core::HID::VibrationGcErmCommand::Start: |
| 1298 | return Controller_NPad::VibrationValue{ | 1328 | return Core::HID::VibrationValue{ |
| 1299 | .amp_low = 1.0f, | 1329 | .low_amplitude = 1.0f, |
| 1300 | .freq_low = 160.0f, | 1330 | .low_frequency = 160.0f, |
| 1301 | .amp_high = 1.0f, | 1331 | .high_amplitude = 1.0f, |
| 1302 | .freq_high = 320.0f, | 1332 | .high_frequency = 320.0f, |
| 1303 | }; | 1333 | }; |
| 1304 | case Core::HID::VibrationGcErmCommand::StopHard: | 1334 | case Core::HID::VibrationGcErmCommand::StopHard: |
| 1305 | return Controller_NPad::VibrationValue{ | 1335 | return Core::HID::VibrationValue{ |
| 1306 | .amp_low = 0.0f, | 1336 | .low_amplitude = 0.0f, |
| 1307 | .freq_low = 0.0f, | 1337 | .low_frequency = 0.0f, |
| 1308 | .amp_high = 0.0f, | 1338 | .high_amplitude = 0.0f, |
| 1309 | .freq_high = 0.0f, | 1339 | .high_frequency = 0.0f, |
| 1310 | }; | 1340 | }; |
| 1311 | default: | 1341 | default: |
| 1312 | return Controller_NPad::DEFAULT_VIBRATION_VALUE; | 1342 | return Controller_NPad::DEFAULT_VIBRATION_VALUE; |
| @@ -1331,7 +1361,7 @@ void Hid::SendVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { | |||
| 1331 | void Hid::GetActualVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { | 1361 | void Hid::GetActualVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { |
| 1332 | IPC::RequestParser rp{ctx}; | 1362 | IPC::RequestParser rp{ctx}; |
| 1333 | struct Parameters { | 1363 | struct Parameters { |
| 1334 | Controller_NPad::DeviceHandle vibration_device_handle; | 1364 | Core::HID::VibrationDeviceHandle vibration_device_handle; |
| 1335 | INSERT_PADDING_WORDS_NOINIT(1); | 1365 | INSERT_PADDING_WORDS_NOINIT(1); |
| 1336 | u64 applet_resource_user_id; | 1366 | u64 applet_resource_user_id; |
| 1337 | }; | 1367 | }; |
| @@ -1342,7 +1372,7 @@ void Hid::GetActualVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { | |||
| 1342 | .GetLastVibration(parameters.vibration_device_handle); | 1372 | .GetLastVibration(parameters.vibration_device_handle); |
| 1343 | 1373 | ||
| 1344 | const auto gc_erm_command = [last_vibration] { | 1374 | const auto gc_erm_command = [last_vibration] { |
| 1345 | if (last_vibration.amp_low != 0.0f || last_vibration.amp_high != 0.0f) { | 1375 | if (last_vibration.low_amplitude != 0.0f || last_vibration.high_amplitude != 0.0f) { |
| 1346 | return Core::HID::VibrationGcErmCommand::Start; | 1376 | return Core::HID::VibrationGcErmCommand::Start; |
| 1347 | } | 1377 | } |
| 1348 | 1378 | ||
| @@ -1352,7 +1382,7 @@ void Hid::GetActualVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { | |||
| 1352 | * SendVibrationGcErmCommand, in order to differentiate between Stop and StopHard commands. | 1382 | * SendVibrationGcErmCommand, in order to differentiate between Stop and StopHard commands. |
| 1353 | * This is done to reuse the controller vibration functions made for regular controllers. | 1383 | * This is done to reuse the controller vibration functions made for regular controllers. |
| 1354 | */ | 1384 | */ |
| 1355 | if (last_vibration.freq_low == 0.0f && last_vibration.freq_high == 0.0f) { | 1385 | if (last_vibration.low_frequency == 0.0f && last_vibration.high_frequency == 0.0f) { |
| 1356 | return Core::HID::VibrationGcErmCommand::StopHard; | 1386 | return Core::HID::VibrationGcErmCommand::StopHard; |
| 1357 | } | 1387 | } |
| 1358 | 1388 | ||
| @@ -1396,10 +1426,11 @@ void Hid::EndPermitVibrationSession(Kernel::HLERequestContext& ctx) { | |||
| 1396 | void Hid::IsVibrationDeviceMounted(Kernel::HLERequestContext& ctx) { | 1426 | void Hid::IsVibrationDeviceMounted(Kernel::HLERequestContext& ctx) { |
| 1397 | IPC::RequestParser rp{ctx}; | 1427 | IPC::RequestParser rp{ctx}; |
| 1398 | struct Parameters { | 1428 | struct Parameters { |
| 1399 | Controller_NPad::DeviceHandle vibration_device_handle; | 1429 | Core::HID::VibrationDeviceHandle vibration_device_handle; |
| 1400 | INSERT_PADDING_WORDS_NOINIT(1); | 1430 | INSERT_PADDING_WORDS_NOINIT(1); |
| 1401 | u64 applet_resource_user_id; | 1431 | u64 applet_resource_user_id; |
| 1402 | }; | 1432 | }; |
| 1433 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 1403 | 1434 | ||
| 1404 | const auto parameters{rp.PopRaw<Parameters>()}; | 1435 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1405 | 1436 | ||
| @@ -1430,18 +1461,18 @@ void Hid::ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { | |||
| 1430 | void Hid::StartConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { | 1461 | void Hid::StartConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 1431 | IPC::RequestParser rp{ctx}; | 1462 | IPC::RequestParser rp{ctx}; |
| 1432 | struct Parameters { | 1463 | struct Parameters { |
| 1433 | Controller_NPad::DeviceHandle sixaxis_handle; | 1464 | Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle; |
| 1434 | INSERT_PADDING_WORDS_NOINIT(1); | 1465 | INSERT_PADDING_WORDS_NOINIT(1); |
| 1435 | u64 applet_resource_user_id; | 1466 | u64 applet_resource_user_id; |
| 1436 | }; | 1467 | }; |
| 1468 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 1437 | 1469 | ||
| 1438 | const auto parameters{rp.PopRaw<Parameters>()}; | 1470 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1439 | 1471 | ||
| 1440 | LOG_WARNING( | 1472 | LOG_WARNING(Service_HID, |
| 1441 | Service_HID, | 1473 | "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}", |
| 1442 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 1474 | parameters.console_sixaxis_handle.unknown_1, |
| 1443 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | 1475 | parameters.console_sixaxis_handle.unknown_2, parameters.applet_resource_user_id); |
| 1444 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 1445 | 1476 | ||
| 1446 | IPC::ResponseBuilder rb{ctx, 2}; | 1477 | IPC::ResponseBuilder rb{ctx, 2}; |
| 1447 | rb.Push(ResultSuccess); | 1478 | rb.Push(ResultSuccess); |
| @@ -1450,18 +1481,18 @@ void Hid::StartConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { | |||
| 1450 | void Hid::StopConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { | 1481 | void Hid::StopConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 1451 | IPC::RequestParser rp{ctx}; | 1482 | IPC::RequestParser rp{ctx}; |
| 1452 | struct Parameters { | 1483 | struct Parameters { |
| 1453 | Controller_NPad::DeviceHandle sixaxis_handle; | 1484 | Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle; |
| 1454 | INSERT_PADDING_WORDS_NOINIT(1); | 1485 | INSERT_PADDING_WORDS_NOINIT(1); |
| 1455 | u64 applet_resource_user_id; | 1486 | u64 applet_resource_user_id; |
| 1456 | }; | 1487 | }; |
| 1488 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 1457 | 1489 | ||
| 1458 | const auto parameters{rp.PopRaw<Parameters>()}; | 1490 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1459 | 1491 | ||
| 1460 | LOG_WARNING( | 1492 | LOG_WARNING(Service_HID, |
| 1461 | Service_HID, | 1493 | "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}", |
| 1462 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 1494 | parameters.console_sixaxis_handle.unknown_1, |
| 1463 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | 1495 | parameters.console_sixaxis_handle.unknown_2, parameters.applet_resource_user_id); |
| 1464 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 1465 | 1496 | ||
| 1466 | IPC::ResponseBuilder rb{ctx, 2}; | 1497 | IPC::ResponseBuilder rb{ctx, 2}; |
| 1467 | rb.Push(ResultSuccess); | 1498 | rb.Push(ResultSuccess); |
| @@ -1615,10 +1646,8 @@ void Hid::SetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { | |||
| 1615 | 1646 | ||
| 1616 | void Hid::GetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { | 1647 | void Hid::GetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { |
| 1617 | IPC::RequestParser rp{ctx}; | 1648 | IPC::RequestParser rp{ctx}; |
| 1618 | const auto applet_resource_user_id{rp.Pop<u64>()}; | ||
| 1619 | 1649 | ||
| 1620 | LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", | 1650 | LOG_WARNING(Service_HID, "(STUBBED) called"); |
| 1621 | applet_resource_user_id); | ||
| 1622 | 1651 | ||
| 1623 | IPC::ResponseBuilder rb{ctx, 4}; | 1652 | IPC::ResponseBuilder rb{ctx, 4}; |
| 1624 | rb.Push(ResultSuccess); | 1653 | rb.Push(ResultSuccess); |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 76f55eb54..0254ea6fe 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -627,7 +627,8 @@ void ConfigureInputPlayer::UpdateInputDeviceCombobox() { | |||
| 627 | return; | 627 | return; |
| 628 | } | 628 | } |
| 629 | 629 | ||
| 630 | const auto devices = emulated_controller->GetMappedDevices(Core::HID::DeviceIndex::AllDevices); | 630 | const auto devices = |
| 631 | emulated_controller->GetMappedDevices(Core::HID::EmulatedDeviceIndex::AllDevices); | ||
| 631 | UpdateInputDevices(); | 632 | UpdateInputDevices(); |
| 632 | 633 | ||
| 633 | if (devices.empty()) { | 634 | if (devices.empty()) { |
| @@ -846,6 +847,7 @@ void ConfigureInputPlayer::SetConnectableControllers() { | |||
| 846 | 847 | ||
| 847 | if (!is_powered_on) { | 848 | if (!is_powered_on) { |
| 848 | add_controllers(true); | 849 | add_controllers(true); |
| 850 | return; | ||
| 849 | } | 851 | } |
| 850 | 852 | ||
| 851 | add_controllers(false, hid_core.GetSupportedStyleTag()); | 853 | add_controllers(false, hid_core.GetSupportedStyleTag()); |
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index ff40f57f5..6630321cb 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp | |||
| @@ -357,7 +357,8 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center) | |||
| 357 | DrawCircle(p, center + QPoint(26, 71), 5); | 357 | DrawCircle(p, center + QPoint(26, 71), 5); |
| 358 | 358 | ||
| 359 | // Draw battery | 359 | // Draw battery |
| 360 | DrawBattery(p, center + QPoint(-170, -140), battery_values[Core::HID::DeviceIndex::LeftIndex]); | 360 | DrawBattery(p, center + QPoint(-170, -140), |
| 361 | battery_values[Core::HID::EmulatedDeviceIndex::LeftIndex]); | ||
| 361 | } | 362 | } |
| 362 | 363 | ||
| 363 | void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center) { | 364 | void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center) { |
| @@ -483,7 +484,8 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center | |||
| 483 | DrawSymbol(p, center + QPoint(-26, 66), Symbol::House, 5); | 484 | DrawSymbol(p, center + QPoint(-26, 66), Symbol::House, 5); |
| 484 | 485 | ||
| 485 | // Draw battery | 486 | // Draw battery |
| 486 | DrawBattery(p, center + QPoint(110, -140), battery_values[Core::HID::DeviceIndex::RightIndex]); | 487 | DrawBattery(p, center + QPoint(110, -140), |
| 488 | battery_values[Core::HID::EmulatedDeviceIndex::RightIndex]); | ||
| 487 | } | 489 | } |
| 488 | 490 | ||
| 489 | void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center) { | 491 | void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center) { |
| @@ -619,8 +621,10 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center) | |||
| 619 | DrawSymbol(p, center + QPoint(50, 60), Symbol::House, 4.2f); | 621 | DrawSymbol(p, center + QPoint(50, 60), Symbol::House, 4.2f); |
| 620 | 622 | ||
| 621 | // Draw battery | 623 | // Draw battery |
| 622 | DrawBattery(p, center + QPoint(-100, -160), battery_values[Core::HID::DeviceIndex::LeftIndex]); | 624 | DrawBattery(p, center + QPoint(-100, -160), |
| 623 | DrawBattery(p, center + QPoint(40, -160), battery_values[Core::HID::DeviceIndex::RightIndex]); | 625 | battery_values[Core::HID::EmulatedDeviceIndex::LeftIndex]); |
| 626 | DrawBattery(p, center + QPoint(40, -160), | ||
| 627 | battery_values[Core::HID::EmulatedDeviceIndex::RightIndex]); | ||
| 624 | } | 628 | } |
| 625 | 629 | ||
| 626 | void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF center) { | 630 | void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF center) { |
| @@ -721,8 +725,10 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen | |||
| 721 | DrawSymbol(p, center + QPoint(161, 37), Symbol::House, 2.75f); | 725 | DrawSymbol(p, center + QPoint(161, 37), Symbol::House, 2.75f); |
| 722 | 726 | ||
| 723 | // Draw battery | 727 | // Draw battery |
| 724 | DrawBattery(p, center + QPoint(-200, 110), battery_values[Core::HID::DeviceIndex::LeftIndex]); | 728 | DrawBattery(p, center + QPoint(-200, 110), |
| 725 | DrawBattery(p, center + QPoint(130, 110), battery_values[Core::HID::DeviceIndex::RightIndex]); | 729 | battery_values[Core::HID::EmulatedDeviceIndex::LeftIndex]); |
| 730 | DrawBattery(p, center + QPoint(130, 110), | ||
| 731 | battery_values[Core::HID::EmulatedDeviceIndex::RightIndex]); | ||
| 726 | } | 732 | } |
| 727 | 733 | ||
| 728 | void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center) { | 734 | void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center) { |
| @@ -812,7 +818,8 @@ void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center) | |||
| 812 | DrawSymbol(p, center + QPoint(29, -56), Symbol::House, 3.9f); | 818 | DrawSymbol(p, center + QPoint(29, -56), Symbol::House, 3.9f); |
| 813 | 819 | ||
| 814 | // Draw battery | 820 | // Draw battery |
| 815 | DrawBattery(p, center + QPoint(-30, -160), battery_values[Core::HID::DeviceIndex::LeftIndex]); | 821 | DrawBattery(p, center + QPoint(-30, -160), |
| 822 | battery_values[Core::HID::EmulatedDeviceIndex::LeftIndex]); | ||
| 816 | } | 823 | } |
| 817 | 824 | ||
| 818 | void PlayerControlPreview::DrawGCController(QPainter& p, const QPointF center) { | 825 | void PlayerControlPreview::DrawGCController(QPainter& p, const QPointF center) { |
| @@ -868,7 +875,8 @@ void PlayerControlPreview::DrawGCController(QPainter& p, const QPointF center) { | |||
| 868 | DrawCircleButton(p, center + QPoint(0, -44), button_values[Plus], 8); | 875 | DrawCircleButton(p, center + QPoint(0, -44), button_values[Plus], 8); |
| 869 | 876 | ||
| 870 | // Draw battery | 877 | // Draw battery |
| 871 | DrawBattery(p, center + QPoint(-30, -165), battery_values[Core::HID::DeviceIndex::LeftIndex]); | 878 | DrawBattery(p, center + QPoint(-30, -165), |
| 879 | battery_values[Core::HID::EmulatedDeviceIndex::LeftIndex]); | ||
| 872 | } | 880 | } |
| 873 | 881 | ||
| 874 | constexpr std::array<float, 13 * 2> symbol_a = { | 882 | constexpr std::array<float, 13 * 2> symbol_a = { |