summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/hid
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/hid/controllers/console_sixaxis.cpp90
-rw-r--r--src/core/hle/service/hid/controllers/console_sixaxis.h80
-rw-r--r--src/core/hle/service/hid/controllers/controller_base.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/controller_base.h2
-rw-r--r--src/core/hle/service/hid/controllers/debug_pad.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/debug_pad.h2
-rw-r--r--src/core/hle/service/hid/controllers/gesture.cpp356
-rw-r--r--src/core/hle/service/hid/controllers/gesture.h79
-rw-r--r--src/core/hle/service/hid/controllers/keyboard.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/keyboard.h2
-rw-r--r--src/core/hle/service/hid/controllers/mouse.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/mouse.h2
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp26
-rw-r--r--src/core/hle/service/hid/controllers/npad.h12
-rw-r--r--src/core/hle/service/hid/controllers/stubbed.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/stubbed.h2
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.cpp6
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.h2
-rw-r--r--src/core/hle/service/hid/controllers/xpad.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/xpad.h2
-rw-r--r--src/core/hle/service/hid/hid.cpp58
-rw-r--r--src/core/hle/service/hid/hid.h6
-rw-r--r--src/core/hle/service/hid/irs.cpp6
-rw-r--r--src/core/hle/service/hid/irs.h6
24 files changed, 598 insertions, 153 deletions
diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.cpp b/src/core/hle/service/hid/controllers/console_sixaxis.cpp
new file mode 100644
index 000000000..bda6e2557
--- /dev/null
+++ b/src/core/hle/service/hid/controllers/console_sixaxis.cpp
@@ -0,0 +1,90 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "common/settings.h"
+#include "core/core_timing.h"
+#include "core/hle/service/hid/controllers/console_sixaxis.h"
+
+namespace Service::HID {
+constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200;
+
+Controller_ConsoleSixAxis::Controller_ConsoleSixAxis(Core::System& system_)
+ : ControllerBase{system_} {}
+Controller_ConsoleSixAxis::~Controller_ConsoleSixAxis() = default;
+
+void Controller_ConsoleSixAxis::OnInit() {}
+
+void Controller_ConsoleSixAxis::OnRelease() {}
+
+void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
+ std::size_t size) {
+ seven_six_axis.header.timestamp = core_timing.GetCPUTicks();
+ seven_six_axis.header.total_entry_count = 17;
+
+ if (!IsControllerActivated() || !is_transfer_memory_set) {
+ seven_six_axis.header.entry_count = 0;
+ seven_six_axis.header.last_entry_index = 0;
+ return;
+ }
+ seven_six_axis.header.entry_count = 16;
+
+ const auto& last_entry =
+ seven_six_axis.sevensixaxis_states[seven_six_axis.header.last_entry_index];
+ seven_six_axis.header.last_entry_index = (seven_six_axis.header.last_entry_index + 1) % 17;
+ auto& cur_entry = seven_six_axis.sevensixaxis_states[seven_six_axis.header.last_entry_index];
+
+ cur_entry.sampling_number = last_entry.sampling_number + 1;
+ cur_entry.sampling_number2 = cur_entry.sampling_number;
+
+ // Try to read sixaxis sensor states
+ MotionDevice motion_device{};
+ const auto& device = motions[0];
+ if (device) {
+ std::tie(motion_device.accel, motion_device.gyro, motion_device.rotation,
+ motion_device.orientation, motion_device.quaternion) = device->GetStatus();
+ console_six_axis.is_seven_six_axis_sensor_at_rest = motion_device.gyro.Length2() < 0.0001f;
+ }
+
+ cur_entry.accel = motion_device.accel;
+ // Zero gyro values as they just mess up with the camera
+ // Note: Probably a correct sensivity setting must be set
+ cur_entry.gyro = {};
+ cur_entry.quaternion = {
+ {
+ motion_device.quaternion.xyz.y,
+ motion_device.quaternion.xyz.x,
+ -motion_device.quaternion.w,
+ },
+ -motion_device.quaternion.xyz.z,
+ };
+
+ console_six_axis.sampling_number++;
+ // TODO(German77): Find the purpose of those values
+ console_six_axis.verticalization_error = 0.0f;
+ console_six_axis.gyro_bias = {0.0f, 0.0f, 0.0f};
+
+ // Update console six axis shared memory
+ std::memcpy(data + SHARED_MEMORY_OFFSET, &console_six_axis, sizeof(console_six_axis));
+ // Update seven six axis transfer memory
+ std::memcpy(transfer_memory, &seven_six_axis, sizeof(seven_six_axis));
+}
+
+void Controller_ConsoleSixAxis::OnLoadInputDevices() {
+ const auto player = Settings::values.players.GetValue()[0];
+ std::transform(player.motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN,
+ player.motions.begin() + Settings::NativeMotion::MOTION_HID_END, motions.begin(),
+ Input::CreateDevice<Input::MotionDevice>);
+}
+
+void Controller_ConsoleSixAxis::SetTransferMemoryPointer(u8* t_mem) {
+ is_transfer_memory_set = true;
+ transfer_memory = t_mem;
+}
+
+void Controller_ConsoleSixAxis::ResetTimestamp() {
+ auto& cur_entry = seven_six_axis.sevensixaxis_states[seven_six_axis.header.last_entry_index];
+ cur_entry.sampling_number = 0;
+ cur_entry.sampling_number2 = 0;
+}
+} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.h b/src/core/hle/service/hid/controllers/console_sixaxis.h
new file mode 100644
index 000000000..fd8a427af
--- /dev/null
+++ b/src/core/hle/service/hid/controllers/console_sixaxis.h
@@ -0,0 +1,80 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <array>
+#include "common/bit_field.h"
+#include "common/common_types.h"
+#include "common/quaternion.h"
+#include "core/frontend/input.h"
+#include "core/hle/service/hid/controllers/controller_base.h"
+
+namespace Service::HID {
+class Controller_ConsoleSixAxis final : public ControllerBase {
+public:
+ explicit Controller_ConsoleSixAxis(Core::System& system_);
+ ~Controller_ConsoleSixAxis() override;
+
+ // Called when the controller is initialized
+ void OnInit() override;
+
+ // When the controller is released
+ void OnRelease() override;
+
+ // When the controller is requesting an update for the shared memory
+ void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, size_t size) override;
+
+ // Called when input devices should be loaded
+ void OnLoadInputDevices() override;
+
+ // Called on InitializeSevenSixAxisSensor
+ void SetTransferMemoryPointer(u8* t_mem);
+
+ // Called on ResetSevenSixAxisSensorTimestamp
+ void ResetTimestamp();
+
+private:
+ struct SevenSixAxisState {
+ INSERT_PADDING_WORDS(4); // unused
+ s64_le sampling_number{};
+ s64_le sampling_number2{};
+ u64 unknown{};
+ Common::Vec3f accel{};
+ Common::Vec3f gyro{};
+ Common::Quaternion<f32> quaternion{};
+ };
+ static_assert(sizeof(SevenSixAxisState) == 0x50, "SevenSixAxisState is an invalid size");
+
+ struct SevenSixAxisMemory {
+ CommonHeader header{};
+ std::array<SevenSixAxisState, 0x21> sevensixaxis_states{};
+ };
+ static_assert(sizeof(SevenSixAxisMemory) == 0xA70, "SevenSixAxisMemory is an invalid size");
+
+ struct ConsoleSharedMemory {
+ u64_le sampling_number{};
+ bool is_seven_six_axis_sensor_at_rest{};
+ f32 verticalization_error{};
+ Common::Vec3f gyro_bias{};
+ };
+ static_assert(sizeof(ConsoleSharedMemory) == 0x20, "ConsoleSharedMemory is an invalid size");
+
+ struct MotionDevice {
+ Common::Vec3f accel;
+ Common::Vec3f gyro;
+ Common::Vec3f rotation;
+ std::array<Common::Vec3f, 3> orientation;
+ Common::Quaternion<f32> quaternion;
+ };
+
+ using MotionArray =
+ std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>;
+ MotionArray motions;
+ u8* transfer_memory = nullptr;
+ bool is_transfer_memory_set = false;
+ ConsoleSharedMemory console_six_axis{};
+ SevenSixAxisMemory seven_six_axis{};
+};
+} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp
index 8091db9d7..9d1e6db6a 100644
--- a/src/core/hle/service/hid/controllers/controller_base.cpp
+++ b/src/core/hle/service/hid/controllers/controller_base.cpp
@@ -6,7 +6,7 @@
namespace Service::HID {
-ControllerBase::ControllerBase(Core::System& system) : system(system) {}
+ControllerBase::ControllerBase(Core::System& system_) : system(system_) {}
ControllerBase::~ControllerBase() = default;
void ControllerBase::ActivateController() {
diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h
index f47a9e61c..1556fb08e 100644
--- a/src/core/hle/service/hid/controllers/controller_base.h
+++ b/src/core/hle/service/hid/controllers/controller_base.h
@@ -18,7 +18,7 @@ class System;
namespace Service::HID {
class ControllerBase {
public:
- explicit ControllerBase(Core::System& system);
+ explicit ControllerBase(Core::System& system_);
virtual ~ControllerBase();
// Called when the controller is initialized
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp
index a460f2f79..d439b8fb0 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.cpp
+++ b/src/core/hle/service/hid/controllers/debug_pad.cpp
@@ -14,7 +14,7 @@ constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
[[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff;
enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right };
-Controller_DebugPad::Controller_DebugPad(Core::System& system) : ControllerBase(system) {}
+Controller_DebugPad::Controller_DebugPad(Core::System& system_) : ControllerBase{system_} {}
Controller_DebugPad::~Controller_DebugPad() = default;
void Controller_DebugPad::OnInit() {}
diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h
index 0593d7d39..1b1645184 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.h
+++ b/src/core/hle/service/hid/controllers/debug_pad.h
@@ -16,7 +16,7 @@
namespace Service::HID {
class Controller_DebugPad final : public ControllerBase {
public:
- explicit Controller_DebugPad(Core::System& system);
+ explicit Controller_DebugPad(Core::System& system_);
~Controller_DebugPad() override;
// Called when the controller is initialized
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp
index 155808f6a..d311f754b 100644
--- a/src/core/hle/service/hid/controllers/gesture.cpp
+++ b/src/core/hle/service/hid/controllers/gesture.cpp
@@ -1,10 +1,9 @@
-// Copyright 2018 yuzu emulator team
+// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#include <cstring>
-#include "common/common_types.h"
#include "common/logging/log.h"
+#include "common/math_util.h"
#include "common/settings.h"
#include "core/core_timing.h"
#include "core/frontend/emu_window.h"
@@ -12,10 +11,19 @@
namespace Service::HID {
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00;
-constexpr f32 angle_threshold = 0.08f;
-constexpr f32 pinch_threshold = 100.0f;
-Controller_Gesture::Controller_Gesture(Core::System& system) : ControllerBase(system) {}
+// HW is around 700, value is set to 400 to make it easier to trigger with mouse
+constexpr f32 swipe_threshold = 400.0f; // Threshold in pixels/s
+constexpr f32 angle_threshold = 0.015f; // Threshold in radians
+constexpr f32 pinch_threshold = 0.5f; // Threshold in pixels
+constexpr f32 press_delay = 0.5f; // Time in seconds
+constexpr f32 double_tap_delay = 0.35f; // Time in seconds
+
+constexpr f32 Square(s32 num) {
+ return static_cast<f32>(num * num);
+}
+
+Controller_Gesture::Controller_Gesture(Core::System& system_) : ControllerBase(system_) {}
Controller_Gesture::~Controller_Gesture() = default;
void Controller_Gesture::OnInit() {
@@ -24,6 +32,8 @@ void Controller_Gesture::OnInit() {
keyboard_finger_id[id] = MAX_POINTS;
udp_finger_id[id] = MAX_POINTS;
}
+ shared_memory.header.entry_count = 0;
+ force_update = true;
}
void Controller_Gesture::OnRelease() {}
@@ -38,17 +48,23 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
shared_memory.header.last_entry_index = 0;
return;
}
- shared_memory.header.entry_count = 16;
- const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
- shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
- auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
+ ReadTouchInput();
- cur_entry.sampling_number = last_entry.sampling_number + 1;
- cur_entry.sampling_number2 = cur_entry.sampling_number;
+ GestureProperties gesture = GetGestureProperties();
+ f32 time_difference = static_cast<f32>(shared_memory.header.timestamp - last_update_timestamp) /
+ (1000 * 1000 * 1000);
- // TODO(german77): Implement all gesture types
+ // Only update if necesary
+ if (!ShouldUpdateGesture(gesture, time_difference)) {
+ return;
+ }
+ last_update_timestamp = shared_memory.header.timestamp;
+ UpdateGestureSharedMemory(data, size, gesture, time_difference);
+}
+
+void Controller_Gesture::ReadTouchInput() {
const Input::TouchStatus& mouse_status = touch_mouse_device->GetStatus();
const Input::TouchStatus& udp_status = touch_udp_device->GetStatus();
for (std::size_t id = 0; id < mouse_status.size(); ++id) {
@@ -63,50 +79,71 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
UpdateTouchInputEvent(keyboard_status[id], keyboard_finger_id[id]);
}
}
+}
- TouchType type = TouchType::Idle;
- Attribute attributes{};
- GestureProperties gesture = GetGestureProperties();
- if (last_gesture.active_points != gesture.active_points) {
- ++last_gesture.detection_count;
+bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture,
+ f32 time_difference) {
+ const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
+ if (force_update) {
+ force_update = false;
+ return true;
}
- if (gesture.active_points > 0) {
- if (last_gesture.active_points == 0) {
- attributes.is_new_touch.Assign(true);
- last_gesture.average_distance = gesture.average_distance;
- last_gesture.angle = gesture.angle;
- }
- type = TouchType::Touch;
- if (gesture.mid_point.x != last_entry.x || gesture.mid_point.y != last_entry.y) {
- type = TouchType::Pan;
- }
- if (std::abs(gesture.average_distance - last_gesture.average_distance) > pinch_threshold) {
- type = TouchType::Pinch;
- }
- if (std::abs(gesture.angle - last_gesture.angle) > angle_threshold) {
- type = TouchType::Rotate;
+ // Update if coordinates change
+ for (size_t id = 0; id < MAX_POINTS; id++) {
+ if (gesture.points[id].x != last_gesture.points[id].x ||
+ gesture.points[id].y != last_gesture.points[id].y) {
+ return true;
}
+ }
- cur_entry.delta_x = gesture.mid_point.x - last_entry.x;
- cur_entry.delta_y = gesture.mid_point.y - last_entry.y;
- // TODO: Find how velocities are calculated
- cur_entry.vel_x = static_cast<float>(cur_entry.delta_x) * 150.1f;
- cur_entry.vel_y = static_cast<float>(cur_entry.delta_y) * 150.1f;
+ // Update on press and hold event after 0.5 seconds
+ if (last_entry.type == TouchType::Touch && last_entry.point_count == 1 &&
+ time_difference > press_delay) {
+ return enable_press_and_tap;
+ }
- // Slowdown the rate of change for less flapping
- last_gesture.average_distance =
- (last_gesture.average_distance * 0.9f) + (gesture.average_distance * 0.1f);
- last_gesture.angle = (last_gesture.angle * 0.9f) + (gesture.angle * 0.1f);
+ return false;
+}
+void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
+ GestureProperties& gesture,
+ f32 time_difference) {
+ TouchType type = TouchType::Idle;
+ Attribute attributes{};
+
+ const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
+ shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
+ auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
+
+ if (shared_memory.header.entry_count < 16) {
+ shared_memory.header.entry_count++;
+ }
+
+ cur_entry.sampling_number = last_entry.sampling_number + 1;
+ cur_entry.sampling_number2 = cur_entry.sampling_number;
+
+ // Reset values to default
+ cur_entry.delta_x = 0;
+ cur_entry.delta_y = 0;
+ cur_entry.vel_x = 0;
+ cur_entry.vel_y = 0;
+ cur_entry.direction = Direction::None;
+ cur_entry.rotation_angle = 0;
+ cur_entry.scale = 0;
+
+ if (gesture.active_points > 0) {
+ if (last_gesture.active_points == 0) {
+ NewGesture(gesture, type, attributes);
+ } else {
+ UpdateExistingGesture(gesture, type, time_difference);
+ }
} else {
- cur_entry.delta_x = 0;
- cur_entry.delta_y = 0;
- cur_entry.vel_x = 0;
- cur_entry.vel_y = 0;
+ EndGesture(gesture, last_gesture, type, attributes, time_difference);
}
- last_gesture.active_points = gesture.active_points;
- cur_entry.detection_count = last_gesture.detection_count;
+
+ // Apply attributes
+ cur_entry.detection_count = gesture.detection_count;
cur_entry.type = type;
cur_entry.attributes = attributes;
cur_entry.x = gesture.mid_point.x;
@@ -116,12 +153,195 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
cur_entry.points[id].x = gesture.points[id].x;
cur_entry.points[id].y = gesture.points[id].y;
}
- cur_entry.rotation_angle = 0;
- cur_entry.scale = 0;
+ last_gesture = gesture;
std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory));
}
+void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
+ Attribute& attributes) {
+ const auto& last_entry =
+ shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ gesture.detection_count++;
+ type = TouchType::Touch;
+
+ // New touch after cancel is not considered new
+ if (last_entry.type != TouchType::Cancel) {
+ attributes.is_new_touch.Assign(1);
+ enable_press_and_tap = true;
+ }
+}
+
+void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, TouchType& type,
+ f32 time_difference) {
+ const auto& last_entry =
+ shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+
+ // Promote to pan type if touch moved
+ for (size_t id = 0; id < MAX_POINTS; id++) {
+ if (gesture.points[id].x != last_gesture.points[id].x ||
+ gesture.points[id].y != last_gesture.points[id].y) {
+ type = TouchType::Pan;
+ break;
+ }
+ }
+
+ // Number of fingers changed cancel the last event and clear data
+ if (gesture.active_points != last_gesture.active_points) {
+ type = TouchType::Cancel;
+ enable_press_and_tap = false;
+ gesture.active_points = 0;
+ gesture.mid_point = {};
+ for (size_t id = 0; id < MAX_POINTS; id++) {
+ gesture.points[id].x = 0;
+ gesture.points[id].y = 0;
+ }
+ return;
+ }
+
+ // Calculate extra parameters of panning
+ if (type == TouchType::Pan) {
+ UpdatePanEvent(gesture, last_gesture, type, time_difference);
+ return;
+ }
+
+ // Promote to press type
+ if (last_entry.type == TouchType::Touch) {
+ type = TouchType::Press;
+ }
+}
+
+void Controller_Gesture::EndGesture(GestureProperties& gesture,
+ GestureProperties& last_gesture_props, TouchType& type,
+ Attribute& attributes, f32 time_difference) {
+ const auto& last_entry =
+ shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ if (last_gesture_props.active_points != 0) {
+ switch (last_entry.type) {
+ case TouchType::Touch:
+ if (enable_press_and_tap) {
+ SetTapEvent(gesture, last_gesture_props, type, attributes);
+ return;
+ }
+ type = TouchType::Cancel;
+ force_update = true;
+ break;
+ case TouchType::Press:
+ case TouchType::Tap:
+ case TouchType::Swipe:
+ case TouchType::Pinch:
+ case TouchType::Rotate:
+ type = TouchType::Complete;
+ force_update = true;
+ break;
+ case TouchType::Pan:
+ EndPanEvent(gesture, last_gesture_props, type, time_difference);
+ break;
+ default:
+ break;
+ }
+ return;
+ }
+ if (last_entry.type == TouchType::Complete || last_entry.type == TouchType::Cancel) {
+ gesture.detection_count++;
+ }
+}
+
+void Controller_Gesture::SetTapEvent(GestureProperties& gesture,
+ GestureProperties& last_gesture_props, TouchType& type,
+ Attribute& attributes) {
+ type = TouchType::Tap;
+ gesture = last_gesture_props;
+ force_update = true;
+ f32 tap_time_difference =
+ static_cast<f32>(last_update_timestamp - last_tap_timestamp) / (1000 * 1000 * 1000);
+ last_tap_timestamp = last_update_timestamp;
+ if (tap_time_difference < double_tap_delay) {
+ attributes.is_double_tap.Assign(1);
+ }
+}
+
+void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture,
+ GestureProperties& last_gesture_props, TouchType& type,
+ f32 time_difference) {
+ auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
+ const auto& last_entry =
+ shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ cur_entry.delta_x = gesture.mid_point.x - last_entry.x;
+ cur_entry.delta_y = gesture.mid_point.y - last_entry.y;
+
+ cur_entry.vel_x = static_cast<f32>(cur_entry.delta_x) / time_difference;
+ cur_entry.vel_y = static_cast<f32>(cur_entry.delta_y) / time_difference;
+ last_pan_time_difference = time_difference;
+
+ // Promote to pinch type
+ if (std::abs(gesture.average_distance - last_gesture_props.average_distance) >
+ pinch_threshold) {
+ type = TouchType::Pinch;
+ cur_entry.scale = gesture.average_distance / last_gesture_props.average_distance;
+ }
+
+ const f32 angle_between_two_lines = std::atan((gesture.angle - last_gesture_props.angle) /
+ (1 + (gesture.angle * last_gesture_props.angle)));
+ // Promote to rotate type
+ if (std::abs(angle_between_two_lines) > angle_threshold) {
+ type = TouchType::Rotate;
+ cur_entry.scale = 0;
+ cur_entry.rotation_angle = angle_between_two_lines * 180.0f / Common::PI;
+ }
+}
+
+void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
+ GestureProperties& last_gesture_props, TouchType& type,
+ f32 time_difference) {
+ auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
+ const auto& last_entry =
+ shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ cur_entry.vel_x =
+ static_cast<f32>(last_entry.delta_x) / (last_pan_time_difference + time_difference);
+ cur_entry.vel_y =
+ static_cast<f32>(last_entry.delta_y) / (last_pan_time_difference + time_difference);
+ const f32 curr_vel =
+ std::sqrt((cur_entry.vel_x * cur_entry.vel_x) + (cur_entry.vel_y * cur_entry.vel_y));
+
+ // Set swipe event with parameters
+ if (curr_vel > swipe_threshold) {
+ SetSwipeEvent(gesture, last_gesture_props, type);
+ return;
+ }
+
+ // End panning without swipe
+ type = TouchType::Complete;
+ cur_entry.vel_x = 0;
+ cur_entry.vel_y = 0;
+ force_update = true;
+}
+
+void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture,
+ GestureProperties& last_gesture_props, TouchType& type) {
+ auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
+ const auto& last_entry =
+ shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ type = TouchType::Swipe;
+ gesture = last_gesture_props;
+ force_update = true;
+ cur_entry.delta_x = last_entry.delta_x;
+ cur_entry.delta_y = last_entry.delta_y;
+ if (std::abs(cur_entry.delta_x) > std::abs(cur_entry.delta_y)) {
+ if (cur_entry.delta_x > 0) {
+ cur_entry.direction = Direction::Right;
+ return;
+ }
+ cur_entry.direction = Direction::Left;
+ return;
+ }
+ if (cur_entry.delta_y > 0) {
+ cur_entry.direction = Direction::Down;
+ return;
+ }
+ cur_entry.direction = Direction::Up;
+}
+
void Controller_Gesture::OnLoadInputDevices() {
touch_mouse_device = Input::CreateDevice<Input::TouchDevice>("engine:emu_window");
touch_udp_device = Input::CreateDevice<Input::TouchDevice>("engine:cemuhookudp");
@@ -129,6 +349,10 @@ void Controller_Gesture::OnLoadInputDevices() {
}
std::optional<std::size_t> Controller_Gesture::GetUnusedFingerID() const {
+ // Dont assign any touch input to a point if disabled
+ if (!Settings::values.touchscreen.enabled) {
+ return std::nullopt;
+ }
std::size_t first_free_id = 0;
while (first_free_id < MAX_POINTS) {
if (!fingers[first_free_id].pressed) {
@@ -179,23 +403,33 @@ Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties()
for (size_t id = 0; id < gesture.active_points; ++id) {
gesture.points[id].x =
- static_cast<int>(active_fingers[id].x * Layout::ScreenUndocked::Width);
+ static_cast<s32>(active_fingers[id].x * Layout::ScreenUndocked::Width);
gesture.points[id].y =
- static_cast<int>(active_fingers[id].y * Layout::ScreenUndocked::Height);
- gesture.mid_point.x += static_cast<int>(gesture.points[id].x / gesture.active_points);
- gesture.mid_point.y += static_cast<int>(gesture.points[id].y / gesture.active_points);
+ static_cast<s32>(active_fingers[id].y * Layout::ScreenUndocked::Height);
+
+ // Hack: There is no touch in docked but games still allow it
+ if (Settings::values.use_docked_mode.GetValue()) {
+ gesture.points[id].x =
+ static_cast<s32>(active_fingers[id].x * Layout::ScreenDocked::Width);
+ gesture.points[id].y =
+ static_cast<s32>(active_fingers[id].y * Layout::ScreenDocked::Height);
+ }
+
+ gesture.mid_point.x += static_cast<s32>(gesture.points[id].x / gesture.active_points);
+ gesture.mid_point.y += static_cast<s32>(gesture.points[id].y / gesture.active_points);
}
for (size_t id = 0; id < gesture.active_points; ++id) {
- const double distance =
- std::pow(static_cast<float>(gesture.mid_point.x - gesture.points[id].x), 2) +
- std::pow(static_cast<float>(gesture.mid_point.y - gesture.points[id].y), 2);
- gesture.average_distance +=
- static_cast<float>(distance) / static_cast<float>(gesture.active_points);
+ const f32 distance = std::sqrt(Square(gesture.mid_point.x - gesture.points[id].x) +
+ Square(gesture.mid_point.y - gesture.points[id].y));
+ gesture.average_distance += distance / static_cast<f32>(gesture.active_points);
}
- gesture.angle = std::atan2(static_cast<float>(gesture.mid_point.y - gesture.points[0].y),
- static_cast<float>(gesture.mid_point.x - gesture.points[0].x));
+ gesture.angle = std::atan2(static_cast<f32>(gesture.mid_point.y - gesture.points[0].y),
+ static_cast<f32>(gesture.mid_point.x - gesture.points[0].x));
+
+ gesture.detection_count = last_gesture.detection_count;
+
return gesture;
}
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h
index 60ecc7822..f46e29411 100644
--- a/src/core/hle/service/hid/controllers/gesture.h
+++ b/src/core/hle/service/hid/controllers/gesture.h
@@ -1,4 +1,4 @@
-// Copyright 2018 yuzu emulator team
+// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
@@ -7,14 +7,13 @@
#include <array>
#include "common/bit_field.h"
#include "common/common_types.h"
-#include "common/swap.h"
#include "core/frontend/input.h"
#include "core/hle/service/hid/controllers/controller_base.h"
namespace Service::HID {
class Controller_Gesture final : public ControllerBase {
public:
- explicit Controller_Gesture(Core::System& system);
+ explicit Controller_Gesture(Core::System& system_);
~Controller_Gesture() override;
// Called when the controller is initialized
@@ -35,10 +34,10 @@ private:
enum class TouchType : u32 {
Idle, // Nothing touching the screen
- Complete, // Unknown. End of touch?
- Cancel, // Never triggered
- Touch, // Pressing without movement
- Press, // Never triggered
+ Complete, // Set at the end of a touch event
+ Cancel, // Set when the number of fingers change
+ Touch, // A finger just touched the screen
+ Press, // Set if last type is touch and the finger hasn't moved
Tap, // Fast press then release
Pan, // All points moving together across the screen
Swipe, // Fast press movement and release of a single point
@@ -58,8 +57,8 @@ private:
union {
u32_le raw{};
- BitField<0, 1, u32> is_new_touch;
- BitField<1, 1, u32> is_double_tap;
+ BitField<4, 1, u32> is_new_touch;
+ BitField<8, 1, u32> is_double_tap;
};
};
static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size");
@@ -73,10 +72,9 @@ private:
struct GestureState {
s64_le sampling_number;
s64_le sampling_number2;
-
s64_le detection_count;
TouchType type;
- Direction dir;
+ Direction direction;
s32_le x;
s32_le y;
s32_le delta_x;
@@ -84,8 +82,8 @@ private:
f32 vel_x;
f32 vel_y;
Attribute attributes;
- u32 scale;
- u32 rotation_angle;
+ f32 scale;
+ f32 rotation_angle;
s32_le point_count;
std::array<Points, 4> points;
};
@@ -109,17 +107,55 @@ private:
Points mid_point{};
s64_le detection_count{};
u64_le delta_time{};
- float average_distance{};
- float angle{};
+ f32 average_distance{};
+ f32 angle{};
};
- // Returns an unused finger id, if there is no fingers avaliable MAX_FINGERS will be returned
+ // Reads input from all available input engines
+ void ReadTouchInput();
+
+ // Returns true if gesture state needs to be updated
+ bool ShouldUpdateGesture(const GestureProperties& gesture, f32 time_difference);
+
+ // Updates the shared memory to the next state
+ void UpdateGestureSharedMemory(u8* data, std::size_t size, GestureProperties& gesture,
+ f32 time_difference);
+
+ // Initializes new gesture
+ void NewGesture(GestureProperties& gesture, TouchType& type, Attribute& attributes);
+
+ // Updates existing gesture state
+ void UpdateExistingGesture(GestureProperties& gesture, TouchType& type, f32 time_difference);
+
+ // Terminates exiting gesture
+ void EndGesture(GestureProperties& gesture, GestureProperties& last_gesture_props,
+ TouchType& type, Attribute& attributes, f32 time_difference);
+
+ // Set current event to a tap event
+ void SetTapEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
+ TouchType& type, Attribute& attributes);
+
+ // Calculates and set the extra parameters related to a pan event
+ void UpdatePanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
+ TouchType& type, f32 time_difference);
+
+ // Terminates the pan event
+ void EndPanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
+ TouchType& type, f32 time_difference);
+
+ // Set current event to a swipe event
+ void SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
+ TouchType& type);
+
+ // Returns an unused finger id, if there is no fingers available std::nullopt is returned.
std::optional<size_t> GetUnusedFingerID() const;
- /** If the touch is new it tries to assing a new finger id, if there is no fingers avaliable no
+ /**
+ * If the touch is new it tries to assign a new finger id, if there is no fingers available no
* changes will be made. Updates the coordinates if the finger id it's already set. If the touch
* ends delays the output by one frame to set the end_touch flag before finally freeing the
- * finger id */
+ * finger id
+ */
size_t UpdateTouchInputEvent(const std::tuple<float, float, bool>& touch_input,
size_t finger_id);
@@ -134,6 +170,11 @@ private:
std::array<size_t, MAX_FINGERS> keyboard_finger_id;
std::array<size_t, MAX_FINGERS> udp_finger_id;
std::array<Finger, MAX_POINTS> fingers;
- GestureProperties last_gesture;
+ GestureProperties last_gesture{};
+ s64_le last_update_timestamp{};
+ s64_le last_tap_timestamp{};
+ f32 last_pan_time_difference{};
+ bool force_update{false};
+ bool enable_press_and_tap{false};
};
} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp
index 18b76038f..c6c620008 100644
--- a/src/core/hle/service/hid/controllers/keyboard.cpp
+++ b/src/core/hle/service/hid/controllers/keyboard.cpp
@@ -12,7 +12,7 @@ namespace Service::HID {
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800;
constexpr u8 KEYS_PER_BYTE = 8;
-Controller_Keyboard::Controller_Keyboard(Core::System& system) : ControllerBase(system) {}
+Controller_Keyboard::Controller_Keyboard(Core::System& system_) : ControllerBase{system_} {}
Controller_Keyboard::~Controller_Keyboard() = default;
void Controller_Keyboard::OnInit() {}
diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h
index e72948591..172a80e9c 100644
--- a/src/core/hle/service/hid/controllers/keyboard.h
+++ b/src/core/hle/service/hid/controllers/keyboard.h
@@ -16,7 +16,7 @@
namespace Service::HID {
class Controller_Keyboard final : public ControllerBase {
public:
- explicit Controller_Keyboard(Core::System& system);
+ explicit Controller_Keyboard(Core::System& system_);
~Controller_Keyboard() override;
// Called when the controller is initialized
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp
index 2e7457604..544a71948 100644
--- a/src/core/hle/service/hid/controllers/mouse.cpp
+++ b/src/core/hle/service/hid/controllers/mouse.cpp
@@ -11,7 +11,7 @@
namespace Service::HID {
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400;
-Controller_Mouse::Controller_Mouse(Core::System& system) : ControllerBase(system) {}
+Controller_Mouse::Controller_Mouse(Core::System& system_) : ControllerBase{system_} {}
Controller_Mouse::~Controller_Mouse() = default;
void Controller_Mouse::OnInit() {}
diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h
index 0ec0c2b94..3d391a798 100644
--- a/src/core/hle/service/hid/controllers/mouse.h
+++ b/src/core/hle/service/hid/controllers/mouse.h
@@ -15,7 +15,7 @@
namespace Service::HID {
class Controller_Mouse final : public ControllerBase {
public:
- explicit Controller_Mouse(Core::System& system);
+ explicit Controller_Mouse(Core::System& system_);
~Controller_Mouse() override;
// Called when the controller is initialized
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 113a41254..7acad3798 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -147,7 +147,7 @@ bool Controller_NPad::IsDeviceHandleValid(const DeviceHandle& device_handle) {
device_handle.device_index < DeviceIndex::MaxDeviceIndex;
}
-Controller_NPad::Controller_NPad(Core::System& system) : ControllerBase(system) {
+Controller_NPad::Controller_NPad(Core::System& system_) : ControllerBase{system_} {
latest_vibration_values.fill({DEFAULT_VIBRATION_VALUE, DEFAULT_VIBRATION_VALUE});
}
@@ -159,7 +159,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
const auto controller_type = connected_controllers[controller_idx].type;
auto& controller = shared_memory_entries[controller_idx];
if (controller_type == NPadControllerType::None) {
- styleset_changed_events[controller_idx]->GetWritableEvent()->Signal();
+ styleset_changed_events[controller_idx]->GetWritableEvent().Signal();
return;
}
controller.style_set.raw = 0; // Zero out
@@ -253,9 +253,8 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
void Controller_NPad::OnInit() {
auto& kernel = system.Kernel();
for (std::size_t i = 0; i < styleset_changed_events.size(); ++i) {
- styleset_changed_events[i] =
- Kernel::KEvent::Create(kernel, fmt::format("npad:NpadStyleSetChanged_{}", i));
- styleset_changed_events[i]->Initialize();
+ styleset_changed_events[i] = Kernel::KEvent::Create(kernel);
+ styleset_changed_events[i]->Initialize(fmt::format("npad:NpadStyleSetChanged_{}", i));
}
if (!IsControllerActivated()) {
@@ -341,6 +340,11 @@ void Controller_NPad::OnRelease() {
VibrateControllerAtIndex(npad_idx, device_idx, {});
}
}
+
+ for (std::size_t i = 0; i < styleset_changed_events.size(); ++i) {
+ styleset_changed_events[i]->Close();
+ styleset_changed_events[i] = nullptr;
+ }
}
void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
@@ -654,8 +658,8 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
const auto& device = motions[i][e];
if (device) {
std::tie(motion_devices[e].accel, motion_devices[e].gyro,
- motion_devices[e].rotation, motion_devices[e].orientation) =
- device->GetStatus();
+ motion_devices[e].rotation, motion_devices[e].orientation,
+ motion_devices[e].quaternion) = device->GetStatus();
sixaxis_at_rest = sixaxis_at_rest && motion_devices[e].gyro.Length2() < 0.0001f;
}
}
@@ -955,14 +959,12 @@ bool Controller_NPad::IsVibrationDeviceMounted(const DeviceHandle& vibration_dev
return vibration_devices_mounted[npad_index][device_index];
}
-std::shared_ptr<Kernel::KReadableEvent> Controller_NPad::GetStyleSetChangedEvent(
- u32 npad_id) const {
- const auto& styleset_event = styleset_changed_events[NPadIdToIndex(npad_id)];
- return styleset_event->GetReadableEvent();
+Kernel::KReadableEvent& Controller_NPad::GetStyleSetChangedEvent(u32 npad_id) {
+ return styleset_changed_events[NPadIdToIndex(npad_id)]->GetReadableEvent();
}
void Controller_NPad::SignalStyleSetChangedEvent(u32 npad_id) const {
- styleset_changed_events[NPadIdToIndex(npad_id)]->GetWritableEvent()->Signal();
+ styleset_changed_events[NPadIdToIndex(npad_id)]->GetWritableEvent().Signal();
}
void Controller_NPad::AddNewControllerAt(NPadControllerType controller, std::size_t npad_index) {
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index c3b07bd41..c050c9a44 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -8,9 +8,9 @@
#include <atomic>
#include "common/bit_field.h"
#include "common/common_types.h"
+#include "common/quaternion.h"
#include "common/settings.h"
#include "core/frontend/input.h"
-#include "core/hle/kernel/object.h"
#include "core/hle/service/hid/controllers/controller_base.h"
namespace Kernel {
@@ -25,7 +25,7 @@ constexpr u32 NPAD_UNKNOWN = 16; // TODO(ogniK): What is this?
class Controller_NPad final : public ControllerBase {
public:
- explicit Controller_NPad(Core::System& system);
+ explicit Controller_NPad(Core::System& system_);
~Controller_NPad() override;
// Called when the controller is initialized
@@ -198,7 +198,7 @@ public:
bool IsVibrationDeviceMounted(const DeviceHandle& vibration_device_handle) const;
- std::shared_ptr<Kernel::KReadableEvent> GetStyleSetChangedEvent(u32 npad_id) const;
+ Kernel::KReadableEvent& GetStyleSetChangedEvent(u32 npad_id);
void SignalStyleSetChangedEvent(u32 npad_id) const;
// Adds a new controller at an index.
@@ -467,6 +467,7 @@ private:
Common::Vec3f gyro;
Common::Vec3f rotation;
std::array<Common::Vec3f, 3> orientation;
+ Common::Quaternion<f32> quaternion;
};
struct NfcXcdHandle {
@@ -571,8 +572,9 @@ private:
NpadHandheldActivationMode handheld_activation_mode{NpadHandheldActivationMode::Dual};
NpadCommunicationMode communication_mode{NpadCommunicationMode::Default};
// Each controller should have their own styleset changed event
- std::array<std::shared_ptr<Kernel::KEvent>, 10> styleset_changed_events;
- std::array<std::array<std::chrono::steady_clock::time_point, 2>, 10> last_vibration_timepoints;
+ std::array<Kernel::KEvent*, 10> styleset_changed_events{};
+ std::array<std::array<std::chrono::steady_clock::time_point, 2>, 10>
+ last_vibration_timepoints{};
std::array<std::array<VibrationValue, 2>, 10> latest_vibration_values{};
bool permit_vibration_session_enabled{false};
std::array<std::array<bool, 2>, 10> vibration_devices_mounted{};
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp
index e7483bfa2..772c20453 100644
--- a/src/core/hle/service/hid/controllers/stubbed.cpp
+++ b/src/core/hle/service/hid/controllers/stubbed.cpp
@@ -9,7 +9,7 @@
namespace Service::HID {
-Controller_Stubbed::Controller_Stubbed(Core::System& system) : ControllerBase(system) {}
+Controller_Stubbed::Controller_Stubbed(Core::System& system_) : ControllerBase{system_} {}
Controller_Stubbed::~Controller_Stubbed() = default;
void Controller_Stubbed::OnInit() {}
diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/stubbed.h
index 4fa83ac85..21092af0d 100644
--- a/src/core/hle/service/hid/controllers/stubbed.h
+++ b/src/core/hle/service/hid/controllers/stubbed.h
@@ -10,7 +10,7 @@
namespace Service::HID {
class Controller_Stubbed final : public ControllerBase {
public:
- explicit Controller_Stubbed(Core::System& system);
+ explicit Controller_Stubbed(Core::System& system_);
~Controller_Stubbed() override;
// Called when the controller is initialized
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp
index b5f8077be..ac9112c40 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.cpp
+++ b/src/core/hle/service/hid/controllers/touchscreen.cpp
@@ -15,7 +15,7 @@
namespace Service::HID {
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400;
-Controller_Touchscreen::Controller_Touchscreen(Core::System& system) : ControllerBase(system) {}
+Controller_Touchscreen::Controller_Touchscreen(Core::System& system_) : ControllerBase{system_} {}
Controller_Touchscreen::~Controller_Touchscreen() = default;
void Controller_Touchscreen::OnInit() {
@@ -105,6 +105,10 @@ void Controller_Touchscreen::OnLoadInputDevices() {
}
std::optional<std::size_t> Controller_Touchscreen::GetUnusedFingerID() const {
+ // Dont assign any touch input to a finger if disabled
+ if (!Settings::values.touchscreen.enabled) {
+ return std::nullopt;
+ }
std::size_t first_free_id = 0;
while (first_free_id < MAX_FINGERS) {
if (!fingers[first_free_id].pressed) {
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h
index 784124e25..2869d0cfd 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.h
+++ b/src/core/hle/service/hid/controllers/touchscreen.h
@@ -14,7 +14,7 @@
namespace Service::HID {
class Controller_Touchscreen final : public ControllerBase {
public:
- explicit Controller_Touchscreen(Core::System& system);
+ explicit Controller_Touchscreen(Core::System& system_);
~Controller_Touchscreen() override;
// Called when the controller is initialized
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp
index 2503ef241..41dc22cf9 100644
--- a/src/core/hle/service/hid/controllers/xpad.cpp
+++ b/src/core/hle/service/hid/controllers/xpad.cpp
@@ -10,7 +10,7 @@
namespace Service::HID {
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00;
-Controller_XPad::Controller_XPad(Core::System& system) : ControllerBase(system) {}
+Controller_XPad::Controller_XPad(Core::System& system_) : ControllerBase{system_} {}
Controller_XPad::~Controller_XPad() = default;
void Controller_XPad::OnInit() {}
diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h
index 5b59961bd..f9ab5facf 100644
--- a/src/core/hle/service/hid/controllers/xpad.h
+++ b/src/core/hle/service/hid/controllers/xpad.h
@@ -13,7 +13,7 @@
namespace Service::HID {
class Controller_XPad final : public ControllerBase {
public:
- explicit Controller_XPad(Core::System& system);
+ explicit Controller_XPad(Core::System& system_);
~Controller_XPad() override;
// Called when the controller is initialized
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 2aa1942cb..49c17fd14 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -13,19 +13,20 @@
#include "core/frontend/input.h"
#include "core/hardware_properties.h"
#include "core/hle/ipc_helpers.h"
-#include "core/hle/kernel/client_port.h"
-#include "core/hle/kernel/client_session.h"
+#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_readable_event.h"
#include "core/hle/kernel/k_shared_memory.h"
+#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/kernel/k_writable_event.h"
#include "core/hle/kernel/kernel.h"
-#include "core/hle/kernel/transfer_memory.h"
#include "core/hle/service/hid/errors.h"
#include "core/hle/service/hid/hid.h"
#include "core/hle/service/hid/irs.h"
#include "core/hle/service/hid/xcd.h"
#include "core/hle/service/service.h"
+#include "core/memory.h"
+#include "core/hle/service/hid/controllers/console_sixaxis.h"
#include "core/hle/service/hid/controllers/controller_base.h"
#include "core/hle/service/hid/controllers/debug_pad.h"
#include "core/hle/service/hid/controllers/gesture.h"
@@ -52,9 +53,6 @@ IAppletResource::IAppletResource(Core::System& system_)
};
RegisterHandlers(functions);
- auto& kernel = system.Kernel();
- shared_mem = SharedFrom(&kernel.GetHidSharedMem());
-
MakeController<Controller_DebugPad>(HidController::DebugPad);
MakeController<Controller_Touchscreen>(HidController::Touchscreen);
MakeController<Controller_Mouse>(HidController::Mouse);
@@ -67,7 +65,7 @@ IAppletResource::IAppletResource(Core::System& system_)
MakeController<Controller_Stubbed>(HidController::UniquePad);
MakeController<Controller_NPad>(HidController::NPad);
MakeController<Controller_Gesture>(HidController::Gesture);
- MakeController<Controller_Stubbed>(HidController::ConsoleSixAxisSensor);
+ MakeController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor);
// Homebrew doesn't try to activate some controllers, so we activate them by default
GetController<Controller_NPad>(HidController::NPad).ActivateController();
@@ -78,8 +76,6 @@ IAppletResource::IAppletResource(Core::System& system_)
GetController<Controller_Stubbed>(HidController::CaptureButton).SetCommonHeaderOffset(0x5000);
GetController<Controller_Stubbed>(HidController::InputDetector).SetCommonHeaderOffset(0x5200);
GetController<Controller_Stubbed>(HidController::UniquePad).SetCommonHeaderOffset(0x5A00);
- GetController<Controller_Stubbed>(HidController::ConsoleSixAxisSensor)
- .SetCommonHeaderOffset(0x3C200);
// Register update callbacks
pad_update_event = Core::Timing::CreateEvent(
@@ -119,7 +115,7 @@ void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
- rb.PushCopyObjects(shared_mem);
+ rb.PushCopyObjects(&system.Kernel().GetHidSharedMem());
}
void IAppletResource::UpdateControllers(std::uintptr_t user_data,
@@ -131,7 +127,8 @@ void IAppletResource::UpdateControllers(std::uintptr_t user_data,
if (should_reload) {
controller->OnLoadInputDevices();
}
- controller->OnUpdate(core_timing, shared_mem->GetPointer(), SHARED_MEMORY_SIZE);
+ controller->OnUpdate(core_timing, system.Kernel().GetHidSharedMem().GetPointer(),
+ SHARED_MEMORY_SIZE);
}
// If ns_late is higher than the update rate ignore the delay
@@ -146,7 +143,7 @@ void IAppletResource::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose
auto& core_timing = system.CoreTiming();
controllers[static_cast<size_t>(HidController::NPad)]->OnMotionUpdate(
- core_timing, shared_mem->GetPointer(), SHARED_MEMORY_SIZE);
+ core_timing, system.Kernel().GetHidSharedMem().GetPointer(), SHARED_MEMORY_SIZE);
// If ns_late is higher than the update rate ignore the delay
if (ns_late > motion_update_ns) {
@@ -1404,8 +1401,9 @@ void Hid::ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto applet_resource_user_id{rp.Pop<u64>()};
- LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}",
- applet_resource_user_id);
+ applet_resource->ActivateController(HidController::ConsoleSixAxisSensor);
+
+ LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
@@ -1455,8 +1453,9 @@ void Hid::ActivateSevenSixAxisSensor(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto applet_resource_user_id{rp.Pop<u64>()};
- LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}",
- applet_resource_user_id);
+ applet_resource->ActivateController(HidController::ConsoleSixAxisSensor);
+
+ LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
@@ -1495,20 +1494,20 @@ void Hid::InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) {
ASSERT_MSG(t_mem_1_size == 0x1000, "t_mem_1_size is not 0x1000 bytes");
ASSERT_MSG(t_mem_2_size == 0x7F000, "t_mem_2_size is not 0x7F000 bytes");
- auto t_mem_1 =
- system.CurrentProcess()->GetHandleTable().Get<Kernel::TransferMemory>(t_mem_1_handle);
+ auto t_mem_1 = system.CurrentProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(
+ t_mem_1_handle);
- if (t_mem_1 == nullptr) {
+ if (t_mem_1.IsNull()) {
LOG_ERROR(Service_HID, "t_mem_1 is a nullptr for handle=0x{:08X}", t_mem_1_handle);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_UNKNOWN);
return;
}
- auto t_mem_2 =
- system.CurrentProcess()->GetHandleTable().Get<Kernel::TransferMemory>(t_mem_2_handle);
+ auto t_mem_2 = system.CurrentProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(
+ t_mem_2_handle);
- if (t_mem_2 == nullptr) {
+ if (t_mem_2.IsNull()) {
LOG_ERROR(Service_HID, "t_mem_2 is a nullptr for handle=0x{:08X}", t_mem_2_handle);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_UNKNOWN);
@@ -1518,8 +1517,15 @@ void Hid::InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) {
ASSERT_MSG(t_mem_1->GetSize() == 0x1000, "t_mem_1 has incorrect size");
ASSERT_MSG(t_mem_2->GetSize() == 0x7F000, "t_mem_2 has incorrect size");
+ // Activate console six axis controller
+ applet_resource->GetController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor)
+ .ActivateController();
+
+ applet_resource->GetController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor)
+ .SetTransferMemoryPointer(system.Memory().GetPointer(t_mem_1->GetSourceAddress()));
+
LOG_WARNING(Service_HID,
- "(STUBBED) called, t_mem_1_handle=0x{:08X}, t_mem_2_handle=0x{:08X}, "
+ "called, t_mem_1_handle=0x{:08X}, t_mem_2_handle=0x{:08X}, "
"applet_resource_user_id={}",
t_mem_1_handle, t_mem_2_handle, applet_resource_user_id);
@@ -1542,8 +1548,10 @@ void Hid::ResetSevenSixAxisSensorTimestamp(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto applet_resource_user_id{rp.Pop<u64>()};
- LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}",
- applet_resource_user_id);
+ applet_resource->GetController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor)
+ .ResetTimestamp();
+
+ LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index c2bdd39a3..aa3307955 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -13,10 +13,6 @@ namespace Core::Timing {
struct EventType;
}
-namespace Kernel {
-class KSharedMemory;
-}
-
namespace Service::SM {
class ServiceManager;
}
@@ -69,8 +65,6 @@ private:
void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
- std::shared_ptr<Kernel::KSharedMemory> shared_mem;
-
std::shared_ptr<Core::Timing::EventType> pad_update_event;
std::shared_ptr<Core::Timing::EventType> motion_update_event;
diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp
index 2dfa936fb..3c6085990 100644
--- a/src/core/hle/service/hid/irs.cpp
+++ b/src/core/hle/service/hid/irs.cpp
@@ -37,10 +37,6 @@ IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} {
// clang-format on
RegisterHandlers(functions);
-
- auto& kernel = system.Kernel();
-
- shared_mem = SharedFrom(&kernel.GetIrsSharedMem());
}
void IRS::ActivateIrsensor(Kernel::HLERequestContext& ctx) {
@@ -62,7 +58,7 @@ void IRS::GetIrsensorSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
- rb.PushCopyObjects(shared_mem);
+ rb.PushCopyObjects(&system.Kernel().GetIrsSharedMem());
}
void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/hid/irs.h b/src/core/hle/service/hid/irs.h
index b0c8c7168..9bc6462b0 100644
--- a/src/core/hle/service/hid/irs.h
+++ b/src/core/hle/service/hid/irs.h
@@ -4,17 +4,12 @@
#pragma once
-#include "core/hle/kernel/object.h"
#include "core/hle/service/service.h"
namespace Core {
class System;
}
-namespace Kernel {
-class KSharedMemory;
-}
-
namespace Service::HID {
class IRS final : public ServiceFramework<IRS> {
@@ -42,7 +37,6 @@ private:
void StopImageProcessorAsync(Kernel::HLERequestContext& ctx);
void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx);
- std::shared_ptr<Kernel::KSharedMemory> shared_mem;
const u32 device_handle{0xABCD};
};