diff options
| -rw-r--r-- | src/core/hle/service/hid/controllers/console_sixaxis.cpp | 33 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/console_sixaxis.h | 21 |
2 files changed, 26 insertions, 28 deletions
diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.cpp b/src/core/hle/service/hid/controllers/console_sixaxis.cpp index bda6e2557..1d351fde0 100644 --- a/src/core/hle/service/hid/controllers/console_sixaxis.cpp +++ b/src/core/hle/service/hid/controllers/console_sixaxis.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/settings.h" | 5 | #include "common/settings.h" |
| 6 | #include "core/core.h" | ||
| 6 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 7 | #include "core/hle/service/hid/controllers/console_sixaxis.h" | 8 | #include "core/hle/service/hid/controllers/console_sixaxis.h" |
| 8 | 9 | ||
| @@ -10,7 +11,10 @@ namespace Service::HID { | |||
| 10 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200; | 11 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200; |
| 11 | 12 | ||
| 12 | Controller_ConsoleSixAxis::Controller_ConsoleSixAxis(Core::System& system_) | 13 | Controller_ConsoleSixAxis::Controller_ConsoleSixAxis(Core::System& system_) |
| 13 | : ControllerBase{system_} {} | 14 | : ControllerBase{system_} { |
| 15 | console = system.HIDCore().GetEmulatedConsole(); | ||
| 16 | } | ||
| 17 | |||
| 14 | Controller_ConsoleSixAxis::~Controller_ConsoleSixAxis() = default; | 18 | Controller_ConsoleSixAxis::~Controller_ConsoleSixAxis() = default; |
| 15 | 19 | ||
| 16 | void Controller_ConsoleSixAxis::OnInit() {} | 20 | void Controller_ConsoleSixAxis::OnInit() {} |
| @@ -38,25 +42,21 @@ void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_ti | |||
| 38 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 42 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
| 39 | 43 | ||
| 40 | // Try to read sixaxis sensor states | 44 | // Try to read sixaxis sensor states |
| 41 | MotionDevice motion_device{}; | 45 | const auto motion_status = console->GetMotion(); |
| 42 | const auto& device = motions[0]; | ||
| 43 | if (device) { | ||
| 44 | std::tie(motion_device.accel, motion_device.gyro, motion_device.rotation, | ||
| 45 | motion_device.orientation, motion_device.quaternion) = device->GetStatus(); | ||
| 46 | console_six_axis.is_seven_six_axis_sensor_at_rest = motion_device.gyro.Length2() < 0.0001f; | ||
| 47 | } | ||
| 48 | 46 | ||
| 49 | cur_entry.accel = motion_device.accel; | 47 | console_six_axis.is_seven_six_axis_sensor_at_rest = motion_status.is_at_rest; |
| 48 | |||
| 49 | cur_entry.accel = motion_status.accel; | ||
| 50 | // Zero gyro values as they just mess up with the camera | 50 | // Zero gyro values as they just mess up with the camera |
| 51 | // Note: Probably a correct sensivity setting must be set | 51 | // Note: Probably a correct sensivity setting must be set |
| 52 | cur_entry.gyro = {}; | 52 | cur_entry.gyro = {}; |
| 53 | cur_entry.quaternion = { | 53 | cur_entry.quaternion = { |
| 54 | { | 54 | { |
| 55 | motion_device.quaternion.xyz.y, | 55 | motion_status.quaternion.xyz.y, |
| 56 | motion_device.quaternion.xyz.x, | 56 | motion_status.quaternion.xyz.x, |
| 57 | -motion_device.quaternion.w, | 57 | -motion_status.quaternion.w, |
| 58 | }, | 58 | }, |
| 59 | -motion_device.quaternion.xyz.z, | 59 | -motion_status.quaternion.xyz.z, |
| 60 | }; | 60 | }; |
| 61 | 61 | ||
| 62 | console_six_axis.sampling_number++; | 62 | console_six_axis.sampling_number++; |
| @@ -70,13 +70,6 @@ void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_ti | |||
| 70 | std::memcpy(transfer_memory, &seven_six_axis, sizeof(seven_six_axis)); | 70 | std::memcpy(transfer_memory, &seven_six_axis, sizeof(seven_six_axis)); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | void Controller_ConsoleSixAxis::OnLoadInputDevices() { | ||
| 74 | const auto player = Settings::values.players.GetValue()[0]; | ||
| 75 | std::transform(player.motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, | ||
| 76 | player.motions.begin() + Settings::NativeMotion::MOTION_HID_END, motions.begin(), | ||
| 77 | Input::CreateDevice<Input::MotionDevice>); | ||
| 78 | } | ||
| 79 | |||
| 80 | void Controller_ConsoleSixAxis::SetTransferMemoryPointer(u8* t_mem) { | 73 | void Controller_ConsoleSixAxis::SetTransferMemoryPointer(u8* t_mem) { |
| 81 | is_transfer_memory_set = true; | 74 | is_transfer_memory_set = true; |
| 82 | transfer_memory = t_mem; | 75 | transfer_memory = t_mem; |
diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.h b/src/core/hle/service/hid/controllers/console_sixaxis.h index fd8a427af..6d18d2ce0 100644 --- a/src/core/hle/service/hid/controllers/console_sixaxis.h +++ b/src/core/hle/service/hid/controllers/console_sixaxis.h | |||
| @@ -5,10 +5,10 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include "common/bit_field.h" | ||
| 9 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 10 | #include "common/quaternion.h" | 9 | #include "common/quaternion.h" |
| 11 | #include "core/frontend/input.h" | 10 | #include "core/hid/hid_core.h" |
| 11 | #include "core/hid/hid_types.h" | ||
| 12 | #include "core/hle/service/hid/controllers/controller_base.h" | 12 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 13 | 13 | ||
| 14 | namespace Service::HID { | 14 | namespace Service::HID { |
| @@ -26,9 +26,6 @@ public: | |||
| 26 | // When the controller is requesting an update for the shared memory | 26 | // When the controller is requesting an update for the shared memory |
| 27 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, size_t size) override; | 27 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, size_t size) override; |
| 28 | 28 | ||
| 29 | // Called when input devices should be loaded | ||
| 30 | void OnLoadInputDevices() override; | ||
| 31 | |||
| 32 | // Called on InitializeSevenSixAxisSensor | 29 | // Called on InitializeSevenSixAxisSensor |
| 33 | void SetTransferMemoryPointer(u8* t_mem); | 30 | void SetTransferMemoryPointer(u8* t_mem); |
| 34 | 31 | ||
| @@ -47,12 +44,22 @@ private: | |||
| 47 | }; | 44 | }; |
| 48 | static_assert(sizeof(SevenSixAxisState) == 0x50, "SevenSixAxisState is an invalid size"); | 45 | static_assert(sizeof(SevenSixAxisState) == 0x50, "SevenSixAxisState is an invalid size"); |
| 49 | 46 | ||
| 47 | struct CommonHeader { | ||
| 48 | s64_le timestamp; | ||
| 49 | s64_le total_entry_count; | ||
| 50 | s64_le last_entry_index; | ||
| 51 | s64_le entry_count; | ||
| 52 | }; | ||
| 53 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); | ||
| 54 | |||
| 55 | // TODO(german77): SevenSixAxisMemory doesn't follow the standard lifo. Investigate | ||
| 50 | struct SevenSixAxisMemory { | 56 | struct SevenSixAxisMemory { |
| 51 | CommonHeader header{}; | 57 | CommonHeader header{}; |
| 52 | std::array<SevenSixAxisState, 0x21> sevensixaxis_states{}; | 58 | std::array<SevenSixAxisState, 0x21> sevensixaxis_states{}; |
| 53 | }; | 59 | }; |
| 54 | static_assert(sizeof(SevenSixAxisMemory) == 0xA70, "SevenSixAxisMemory is an invalid size"); | 60 | static_assert(sizeof(SevenSixAxisMemory) == 0xA70, "SevenSixAxisMemory is an invalid size"); |
| 55 | 61 | ||
| 62 | // This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat | ||
| 56 | struct ConsoleSharedMemory { | 63 | struct ConsoleSharedMemory { |
| 57 | u64_le sampling_number{}; | 64 | u64_le sampling_number{}; |
| 58 | bool is_seven_six_axis_sensor_at_rest{}; | 65 | bool is_seven_six_axis_sensor_at_rest{}; |
| @@ -69,9 +76,7 @@ private: | |||
| 69 | Common::Quaternion<f32> quaternion; | 76 | Common::Quaternion<f32> quaternion; |
| 70 | }; | 77 | }; |
| 71 | 78 | ||
| 72 | using MotionArray = | 79 | Core::HID::EmulatedConsole* console; |
| 73 | std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>; | ||
| 74 | MotionArray motions; | ||
| 75 | u8* transfer_memory = nullptr; | 80 | u8* transfer_memory = nullptr; |
| 76 | bool is_transfer_memory_set = false; | 81 | bool is_transfer_memory_set = false; |
| 77 | ConsoleSharedMemory console_six_axis{}; | 82 | ConsoleSharedMemory console_six_axis{}; |