diff options
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 57 | ||||
| -rw-r--r-- | src/core/hid/emulated_console.h | 3 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/gesture.cpp | 124 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/gesture.h | 29 | ||||
| -rw-r--r-- | src/input_common/drivers/gc_adapter.cpp | 4 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.cpp | 27 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 2 |
8 files changed, 159 insertions, 91 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index 7f7c8fd59..e82cf5990 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp | |||
| @@ -20,27 +20,21 @@ void EmulatedConsole::ReloadFromSettings() { | |||
| 20 | ReloadInput(); | 20 | ReloadInput(); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | void EmulatedConsole::ReloadInput() { | 23 | void EmulatedConsole::SetTouchParams() { |
| 24 | motion_devices = Input::CreateDevice<Input::InputDevice>(motion_params); | 24 | // TODO(german77): Support any number of fingers |
| 25 | if (motion_devices) { | ||
| 26 | Input::InputCallback motion_callback{ | ||
| 27 | [this](Input::CallbackStatus callback) { SetMotion(callback); }}; | ||
| 28 | motion_devices->SetCallback(motion_callback); | ||
| 29 | } | ||
| 30 | |||
| 31 | // TODO: Fix this mess | ||
| 32 | std::size_t index = 0; | 25 | std::size_t index = 0; |
| 33 | const std::string mouse_device_string = | 26 | |
| 34 | fmt::format("engine:mouse,axis_x:10,axis_y:11,button:{}", index); | 27 | // Hardcode mouse, touchscreen and cemuhook parameters |
| 35 | touch_devices[index] = Input::CreateDeviceFromString<Input::InputDevice>(mouse_device_string); | 28 | touch_params[index++] = Common::ParamPackage{"engine:mouse,axis_x:10,axis_y:11,button:0"}; |
| 36 | Input::InputCallback trigger_callbackk{ | 29 | touch_params[index++] = Common::ParamPackage{"engine:touch,axis_x:0,axis_y:1,button:0"}; |
| 37 | [this, index](Input::CallbackStatus callback) { SetTouch(callback, index); }}; | 30 | touch_params[index++] = Common::ParamPackage{"engine:touch,axis_x:2,axis_y:3,button:1"}; |
| 38 | touch_devices[index]->SetCallback(trigger_callbackk); | 31 | touch_params[index++] = Common::ParamPackage{"engine:cemuhookudp,axis_x:0,axis_y:1,button:0"}; |
| 39 | 32 | touch_params[index++] = Common::ParamPackage{"engine:cemuhookudp,axis_x:2,axis_y:3,button:1"}; | |
| 40 | index++; | 33 | |
| 41 | const auto button_index = | 34 | const auto button_index = |
| 42 | static_cast<u64>(Settings::values.touch_from_button_map_index.GetValue()); | 35 | static_cast<u64>(Settings::values.touch_from_button_map_index.GetValue()); |
| 43 | const auto& touch_buttons = Settings::values.touch_from_button_maps[button_index].buttons; | 36 | const auto& touch_buttons = Settings::values.touch_from_button_maps[button_index].buttons; |
| 37 | |||
| 44 | for (const auto& config_entry : touch_buttons) { | 38 | for (const auto& config_entry : touch_buttons) { |
| 45 | Common::ParamPackage params{config_entry}; | 39 | Common::ParamPackage params{config_entry}; |
| 46 | Common::ParamPackage touch_button_params; | 40 | Common::ParamPackage touch_button_params; |
| @@ -53,15 +47,32 @@ void EmulatedConsole::ReloadInput() { | |||
| 53 | touch_button_params.Set("x", x); | 47 | touch_button_params.Set("x", x); |
| 54 | touch_button_params.Set("y", y); | 48 | touch_button_params.Set("y", y); |
| 55 | touch_button_params.Set("touch_id", static_cast<int>(index)); | 49 | touch_button_params.Set("touch_id", static_cast<int>(index)); |
| 56 | touch_devices[index] = | 50 | touch_params[index] = touch_button_params; |
| 57 | Input::CreateDeviceFromString<Input::InputDevice>(touch_button_params.Serialize()); | 51 | index++; |
| 58 | if (!touch_devices[index]) { | 52 | if (index >= touch_params.size()) { |
| 59 | continue; | 53 | return; |
| 60 | } | 54 | } |
| 55 | } | ||
| 56 | } | ||
| 61 | 57 | ||
| 62 | Input::InputCallback trigger_callback{ | 58 | void EmulatedConsole::ReloadInput() { |
| 59 | SetTouchParams(); | ||
| 60 | motion_devices = Input::CreateDevice<Input::InputDevice>(motion_params); | ||
| 61 | if (motion_devices) { | ||
| 62 | Input::InputCallback motion_callback{ | ||
| 63 | [this](Input::CallbackStatus callback) { SetMotion(callback); }}; | ||
| 64 | motion_devices->SetCallback(motion_callback); | ||
| 65 | } | ||
| 66 | |||
| 67 | std::size_t index = 0; | ||
| 68 | for (auto& touch_device : touch_devices) { | ||
| 69 | touch_device = Input::CreateDevice<Input::InputDevice>(touch_params[index]); | ||
| 70 | if (!touch_device) { | ||
| 71 | continue; | ||
| 72 | } | ||
| 73 | Input::InputCallback touch_callback{ | ||
| 63 | [this, index](Input::CallbackStatus callback) { SetTouch(callback, index); }}; | 74 | [this, index](Input::CallbackStatus callback) { SetTouch(callback, index); }}; |
| 64 | touch_devices[index]->SetCallback(trigger_callback); | 75 | touch_device->SetCallback(touch_callback); |
| 65 | index++; | 76 | index++; |
| 66 | } | 77 | } |
| 67 | } | 78 | } |
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h index 7d6cf9506..c48d25794 100644 --- a/src/core/hid/emulated_console.h +++ b/src/core/hid/emulated_console.h | |||
| @@ -144,6 +144,9 @@ public: | |||
| 144 | void DeleteCallback(int key); | 144 | void DeleteCallback(int key); |
| 145 | 145 | ||
| 146 | private: | 146 | private: |
| 147 | /// Creates and stores the touch params | ||
| 148 | void SetTouchParams(); | ||
| 149 | |||
| 147 | /** | 150 | /** |
| 148 | * Updates the motion status of the console | 151 | * Updates the motion status of the console |
| 149 | * @param A CallbackStatus containing gyro and accelerometer data | 152 | * @param A CallbackStatus containing gyro and accelerometer data |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 662260327..1ff3022c5 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -705,7 +705,6 @@ void EmulatedController::Connect() { | |||
| 705 | } | 705 | } |
| 706 | is_connected = true; | 706 | is_connected = true; |
| 707 | } | 707 | } |
| 708 | LOG_ERROR(Service_HID, "Connected controller {}", NpadIdTypeToIndex(npad_id_type)); | ||
| 709 | TriggerOnChange(ControllerTriggerType::Connected, true); | 708 | TriggerOnChange(ControllerTriggerType::Connected, true); |
| 710 | } | 709 | } |
| 711 | 710 | ||
| @@ -714,8 +713,6 @@ void EmulatedController::Disconnect() { | |||
| 714 | std::lock_guard lock{mutex}; | 713 | std::lock_guard lock{mutex}; |
| 715 | if (is_configuring) { | 714 | if (is_configuring) { |
| 716 | temporary_is_connected = false; | 715 | temporary_is_connected = false; |
| 717 | LOG_ERROR(Service_HID, "Disconnected temporal controller {}", | ||
| 718 | NpadIdTypeToIndex(npad_id_type)); | ||
| 719 | TriggerOnChange(ControllerTriggerType::Disconnected, false); | 716 | TriggerOnChange(ControllerTriggerType::Disconnected, false); |
| 720 | return; | 717 | return; |
| 721 | } | 718 | } |
| @@ -725,7 +722,6 @@ void EmulatedController::Disconnect() { | |||
| 725 | } | 722 | } |
| 726 | is_connected = false; | 723 | is_connected = false; |
| 727 | } | 724 | } |
| 728 | LOG_ERROR(Service_HID, "Disconnected controller {}", NpadIdTypeToIndex(npad_id_type)); | ||
| 729 | TriggerOnChange(ControllerTriggerType::Disconnected, true); | 725 | TriggerOnChange(ControllerTriggerType::Disconnected, true); |
| 730 | } | 726 | } |
| 731 | 727 | ||
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index 2f98cc54b..a26ce5383 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp | |||
| @@ -28,12 +28,10 @@ constexpr f32 Square(s32 num) { | |||
| 28 | Controller_Gesture::Controller_Gesture(Core::System& system_) : ControllerBase(system_) { | 28 | Controller_Gesture::Controller_Gesture(Core::System& system_) : ControllerBase(system_) { |
| 29 | console = system.HIDCore().GetEmulatedConsole(); | 29 | console = system.HIDCore().GetEmulatedConsole(); |
| 30 | } | 30 | } |
| 31 | |||
| 32 | Controller_Gesture::~Controller_Gesture() = default; | 31 | Controller_Gesture::~Controller_Gesture() = default; |
| 33 | 32 | ||
| 34 | void Controller_Gesture::OnInit() { | 33 | void Controller_Gesture::OnInit() { |
| 35 | gesture_lifo.entry_count = 0; | 34 | shared_memory.header.entry_count = 0; |
| 36 | gesture_lifo.last_entry_index = 0; | ||
| 37 | force_update = true; | 35 | force_update = true; |
| 38 | } | 36 | } |
| 39 | 37 | ||
| @@ -41,27 +39,27 @@ void Controller_Gesture::OnRelease() {} | |||
| 41 | 39 | ||
| 42 | void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 40 | void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 43 | std::size_t size) { | 41 | std::size_t size) { |
| 44 | // TODO FIND WTF IS WRONG HERE!!!!!!!! | 42 | shared_memory.header.timestamp = core_timing.GetCPUTicks(); |
| 45 | return; | 43 | shared_memory.header.total_entry_count = 17; |
| 44 | |||
| 46 | if (!IsControllerActivated()) { | 45 | if (!IsControllerActivated()) { |
| 47 | gesture_lifo.entry_count = 0; | 46 | shared_memory.header.entry_count = 0; |
| 48 | gesture_lifo.last_entry_index = 0; | 47 | shared_memory.header.last_entry_index = 0; |
| 49 | std::memcpy(data, &gesture_lifo, sizeof(gesture_lifo)); | ||
| 50 | return; | 48 | return; |
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | ReadTouchInput(); | 51 | ReadTouchInput(); |
| 54 | 52 | ||
| 55 | GestureProperties gesture = GetGestureProperties(); | 53 | GestureProperties gesture = GetGestureProperties(); |
| 56 | f32 time_difference = | 54 | f32 time_difference = static_cast<f32>(shared_memory.header.timestamp - last_update_timestamp) / |
| 57 | static_cast<f32>(gesture_lifo.timestamp - last_update_timestamp) / (1000 * 1000 * 1000); | 55 | (1000 * 1000 * 1000); |
| 58 | 56 | ||
| 59 | // Only update if necesary | 57 | // Only update if necesary |
| 60 | if (!ShouldUpdateGesture(gesture, time_difference)) { | 58 | if (!ShouldUpdateGesture(gesture, time_difference)) { |
| 61 | return; | 59 | return; |
| 62 | } | 60 | } |
| 63 | 61 | ||
| 64 | last_update_timestamp = gesture_lifo.timestamp; | 62 | last_update_timestamp = shared_memory.header.timestamp; |
| 65 | UpdateGestureSharedMemory(data, size, gesture, time_difference); | 63 | UpdateGestureSharedMemory(data, size, gesture, time_difference); |
| 66 | } | 64 | } |
| 67 | 65 | ||
| @@ -77,7 +75,7 @@ void Controller_Gesture::ReadTouchInput() { | |||
| 77 | 75 | ||
| 78 | bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture, | 76 | bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture, |
| 79 | f32 time_difference) { | 77 | f32 time_difference) { |
| 80 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 78 | const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 81 | if (force_update) { | 79 | if (force_update) { |
| 82 | force_update = false; | 80 | force_update = false; |
| 83 | return true; | 81 | return true; |
| @@ -105,16 +103,24 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size, | |||
| 105 | GestureType type = GestureType::Idle; | 103 | GestureType type = GestureType::Idle; |
| 106 | GestureAttribute attributes{}; | 104 | GestureAttribute attributes{}; |
| 107 | 105 | ||
| 108 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 106 | const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 107 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | ||
| 108 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; | ||
| 109 | |||
| 110 | if (shared_memory.header.entry_count < 16) { | ||
| 111 | shared_memory.header.entry_count++; | ||
| 112 | } | ||
| 113 | |||
| 114 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 115 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 109 | 116 | ||
| 110 | // Reset next state to default | 117 | // Reset values to default |
| 111 | next_state.sampling_number = last_entry.sampling_number + 1; | 118 | cur_entry.delta = {}; |
| 112 | next_state.delta = {}; | 119 | cur_entry.vel_x = 0; |
| 113 | next_state.vel_x = 0; | 120 | cur_entry.vel_y = 0; |
| 114 | next_state.vel_y = 0; | 121 | cur_entry.direction = GestureDirection::None; |
| 115 | next_state.direction = GestureDirection::None; | 122 | cur_entry.rotation_angle = 0; |
| 116 | next_state.rotation_angle = 0; | 123 | cur_entry.scale = 0; |
| 117 | next_state.scale = 0; | ||
| 118 | 124 | ||
| 119 | if (gesture.active_points > 0) { | 125 | if (gesture.active_points > 0) { |
| 120 | if (last_gesture.active_points == 0) { | 126 | if (last_gesture.active_points == 0) { |
| @@ -127,21 +133,20 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size, | |||
| 127 | } | 133 | } |
| 128 | 134 | ||
| 129 | // Apply attributes | 135 | // Apply attributes |
| 130 | next_state.detection_count = gesture.detection_count; | 136 | cur_entry.detection_count = gesture.detection_count; |
| 131 | next_state.type = type; | 137 | cur_entry.type = type; |
| 132 | next_state.attributes = attributes; | 138 | cur_entry.attributes = attributes; |
| 133 | next_state.pos = gesture.mid_point; | 139 | cur_entry.pos = gesture.mid_point; |
| 134 | next_state.point_count = static_cast<s32>(gesture.active_points); | 140 | cur_entry.point_count = static_cast<s32>(gesture.active_points); |
| 135 | next_state.points = gesture.points; | 141 | cur_entry.points = gesture.points; |
| 136 | last_gesture = gesture; | 142 | last_gesture = gesture; |
| 137 | 143 | ||
| 138 | gesture_lifo.WriteNextEntry(next_state); | 144 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); |
| 139 | std::memcpy(data + SHARED_MEMORY_OFFSET, &gesture_lifo, sizeof(gesture_lifo)); | ||
| 140 | } | 145 | } |
| 141 | 146 | ||
| 142 | void Controller_Gesture::NewGesture(GestureProperties& gesture, GestureType& type, | 147 | void Controller_Gesture::NewGesture(GestureProperties& gesture, GestureType& type, |
| 143 | GestureAttribute& attributes) { | 148 | GestureAttribute& attributes) { |
| 144 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 149 | const auto& last_entry = GetLastGestureEntry(); |
| 145 | 150 | ||
| 146 | gesture.detection_count++; | 151 | gesture.detection_count++; |
| 147 | type = GestureType::Touch; | 152 | type = GestureType::Touch; |
| @@ -155,7 +160,7 @@ void Controller_Gesture::NewGesture(GestureProperties& gesture, GestureType& typ | |||
| 155 | 160 | ||
| 156 | void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, GestureType& type, | 161 | void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, GestureType& type, |
| 157 | f32 time_difference) { | 162 | f32 time_difference) { |
| 158 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 163 | const auto& last_entry = GetLastGestureEntry(); |
| 159 | 164 | ||
| 160 | // Promote to pan type if touch moved | 165 | // Promote to pan type if touch moved |
| 161 | for (size_t id = 0; id < MAX_POINTS; id++) { | 166 | for (size_t id = 0; id < MAX_POINTS; id++) { |
| @@ -190,7 +195,7 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Gestu | |||
| 190 | void Controller_Gesture::EndGesture(GestureProperties& gesture, | 195 | void Controller_Gesture::EndGesture(GestureProperties& gesture, |
| 191 | GestureProperties& last_gesture_props, GestureType& type, | 196 | GestureProperties& last_gesture_props, GestureType& type, |
| 192 | GestureAttribute& attributes, f32 time_difference) { | 197 | GestureAttribute& attributes, f32 time_difference) { |
| 193 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 198 | const auto& last_entry = GetLastGestureEntry(); |
| 194 | 199 | ||
| 195 | if (last_gesture_props.active_points != 0) { | 200 | if (last_gesture_props.active_points != 0) { |
| 196 | switch (last_entry.type) { | 201 | switch (last_entry.type) { |
| @@ -240,18 +245,19 @@ void Controller_Gesture::SetTapEvent(GestureProperties& gesture, | |||
| 240 | void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture, | 245 | void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture, |
| 241 | GestureProperties& last_gesture_props, GestureType& type, | 246 | GestureProperties& last_gesture_props, GestureType& type, |
| 242 | f32 time_difference) { | 247 | f32 time_difference) { |
| 243 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 248 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 249 | const auto& last_entry = GetLastGestureEntry(); | ||
| 244 | 250 | ||
| 245 | next_state.delta = gesture.mid_point - last_entry.pos; | 251 | cur_entry.delta = gesture.mid_point - last_entry.pos; |
| 246 | next_state.vel_x = static_cast<f32>(next_state.delta.x) / time_difference; | 252 | cur_entry.vel_x = static_cast<f32>(cur_entry.delta.x) / time_difference; |
| 247 | next_state.vel_y = static_cast<f32>(next_state.delta.y) / time_difference; | 253 | cur_entry.vel_y = static_cast<f32>(cur_entry.delta.y) / time_difference; |
| 248 | last_pan_time_difference = time_difference; | 254 | last_pan_time_difference = time_difference; |
| 249 | 255 | ||
| 250 | // Promote to pinch type | 256 | // Promote to pinch type |
| 251 | if (std::abs(gesture.average_distance - last_gesture_props.average_distance) > | 257 | if (std::abs(gesture.average_distance - last_gesture_props.average_distance) > |
| 252 | pinch_threshold) { | 258 | pinch_threshold) { |
| 253 | type = GestureType::Pinch; | 259 | type = GestureType::Pinch; |
| 254 | next_state.scale = gesture.average_distance / last_gesture_props.average_distance; | 260 | cur_entry.scale = gesture.average_distance / last_gesture_props.average_distance; |
| 255 | } | 261 | } |
| 256 | 262 | ||
| 257 | const f32 angle_between_two_lines = std::atan((gesture.angle - last_gesture_props.angle) / | 263 | const f32 angle_between_two_lines = std::atan((gesture.angle - last_gesture_props.angle) / |
| @@ -259,21 +265,22 @@ void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture, | |||
| 259 | // Promote to rotate type | 265 | // Promote to rotate type |
| 260 | if (std::abs(angle_between_two_lines) > angle_threshold) { | 266 | if (std::abs(angle_between_two_lines) > angle_threshold) { |
| 261 | type = GestureType::Rotate; | 267 | type = GestureType::Rotate; |
| 262 | next_state.scale = 0; | 268 | cur_entry.scale = 0; |
| 263 | next_state.rotation_angle = angle_between_two_lines * 180.0f / Common::PI; | 269 | cur_entry.rotation_angle = angle_between_two_lines * 180.0f / Common::PI; |
| 264 | } | 270 | } |
| 265 | } | 271 | } |
| 266 | 272 | ||
| 267 | void Controller_Gesture::EndPanEvent(GestureProperties& gesture, | 273 | void Controller_Gesture::EndPanEvent(GestureProperties& gesture, |
| 268 | GestureProperties& last_gesture_props, GestureType& type, | 274 | GestureProperties& last_gesture_props, GestureType& type, |
| 269 | f32 time_difference) { | 275 | f32 time_difference) { |
| 270 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 276 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 271 | next_state.vel_x = | 277 | const auto& last_entry = GetLastGestureEntry(); |
| 278 | cur_entry.vel_x = | ||
| 272 | static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference); | 279 | static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference); |
| 273 | next_state.vel_y = | 280 | cur_entry.vel_y = |
| 274 | static_cast<f32>(last_entry.delta.y) / (last_pan_time_difference + time_difference); | 281 | static_cast<f32>(last_entry.delta.y) / (last_pan_time_difference + time_difference); |
| 275 | const f32 curr_vel = | 282 | const f32 curr_vel = |
| 276 | std::sqrt((next_state.vel_x * next_state.vel_x) + (next_state.vel_y * next_state.vel_y)); | 283 | std::sqrt((cur_entry.vel_x * cur_entry.vel_x) + (cur_entry.vel_y * cur_entry.vel_y)); |
| 277 | 284 | ||
| 278 | // Set swipe event with parameters | 285 | // Set swipe event with parameters |
| 279 | if (curr_vel > swipe_threshold) { | 286 | if (curr_vel > swipe_threshold) { |
| @@ -283,33 +290,42 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture, | |||
| 283 | 290 | ||
| 284 | // End panning without swipe | 291 | // End panning without swipe |
| 285 | type = GestureType::Complete; | 292 | type = GestureType::Complete; |
| 286 | next_state.vel_x = 0; | 293 | cur_entry.vel_x = 0; |
| 287 | next_state.vel_y = 0; | 294 | cur_entry.vel_y = 0; |
| 288 | force_update = true; | 295 | force_update = true; |
| 289 | } | 296 | } |
| 290 | 297 | ||
| 291 | void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture, | 298 | void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture, |
| 292 | GestureProperties& last_gesture_props, GestureType& type) { | 299 | GestureProperties& last_gesture_props, GestureType& type) { |
| 293 | const auto& last_entry = gesture_lifo.ReadCurrentEntry().state; | 300 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 301 | const auto& last_entry = GetLastGestureEntry(); | ||
| 294 | 302 | ||
| 295 | type = GestureType::Swipe; | 303 | type = GestureType::Swipe; |
| 296 | gesture = last_gesture_props; | 304 | gesture = last_gesture_props; |
| 297 | force_update = true; | 305 | force_update = true; |
| 298 | next_state.delta = last_entry.delta; | 306 | cur_entry.delta = last_entry.delta; |
| 299 | 307 | ||
| 300 | if (std::abs(next_state.delta.x) > std::abs(next_state.delta.y)) { | 308 | if (std::abs(cur_entry.delta.x) > std::abs(cur_entry.delta.y)) { |
| 301 | if (next_state.delta.x > 0) { | 309 | if (cur_entry.delta.x > 0) { |
| 302 | next_state.direction = GestureDirection::Right; | 310 | cur_entry.direction = GestureDirection::Right; |
| 303 | return; | 311 | return; |
| 304 | } | 312 | } |
| 305 | next_state.direction = GestureDirection::Left; | 313 | cur_entry.direction = GestureDirection::Left; |
| 306 | return; | 314 | return; |
| 307 | } | 315 | } |
| 308 | if (next_state.delta.y > 0) { | 316 | if (cur_entry.delta.y > 0) { |
| 309 | next_state.direction = GestureDirection::Down; | 317 | cur_entry.direction = GestureDirection::Down; |
| 310 | return; | 318 | return; |
| 311 | } | 319 | } |
| 312 | next_state.direction = GestureDirection::Up; | 320 | cur_entry.direction = GestureDirection::Up; |
| 321 | } | ||
| 322 | |||
| 323 | Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() { | ||
| 324 | return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; | ||
| 325 | } | ||
| 326 | |||
| 327 | const Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() const { | ||
| 328 | return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; | ||
| 313 | } | 329 | } |
| 314 | 330 | ||
| 315 | Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties() { | 331 | Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties() { |
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index 8e6f315a4..6128fb0ad 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -71,6 +71,7 @@ private: | |||
| 71 | // This is nn::hid::GestureState | 71 | // This is nn::hid::GestureState |
| 72 | struct GestureState { | 72 | struct GestureState { |
| 73 | s64_le sampling_number; | 73 | s64_le sampling_number; |
| 74 | s64_le sampling_number2; | ||
| 74 | s64_le detection_count; | 75 | s64_le detection_count; |
| 75 | GestureType type; | 76 | GestureType type; |
| 76 | GestureDirection direction; | 77 | GestureDirection direction; |
| @@ -84,7 +85,21 @@ private: | |||
| 84 | s32_le point_count; | 85 | s32_le point_count; |
| 85 | std::array<Common::Point<s32_le>, 4> points; | 86 | std::array<Common::Point<s32_le>, 4> points; |
| 86 | }; | 87 | }; |
| 87 | static_assert(sizeof(GestureState) == 0x60, "GestureState is an invalid size"); | 88 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); |
| 89 | |||
| 90 | struct CommonHeader { | ||
| 91 | s64_le timestamp; | ||
| 92 | s64_le total_entry_count; | ||
| 93 | s64_le last_entry_index; | ||
| 94 | s64_le entry_count; | ||
| 95 | }; | ||
| 96 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); | ||
| 97 | |||
| 98 | struct SharedMemory { | ||
| 99 | CommonHeader header; | ||
| 100 | std::array<GestureState, 17> gesture_states; | ||
| 101 | }; | ||
| 102 | static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); | ||
| 88 | 103 | ||
| 89 | struct Finger { | 104 | struct Finger { |
| 90 | Common::Point<f32> pos{}; | 105 | Common::Point<f32> pos{}; |
| @@ -137,17 +152,17 @@ private: | |||
| 137 | void SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_gesture_props, | 152 | void SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_gesture_props, |
| 138 | GestureType& type); | 153 | GestureType& type); |
| 139 | 154 | ||
| 155 | // Retrieves the last gesture entry, as indicated by shared memory indices. | ||
| 156 | [[nodiscard]] GestureState& GetLastGestureEntry(); | ||
| 157 | [[nodiscard]] const GestureState& GetLastGestureEntry() const; | ||
| 158 | |||
| 140 | // Returns the average distance, angle and middle point of the active fingers | 159 | // Returns the average distance, angle and middle point of the active fingers |
| 141 | GestureProperties GetGestureProperties(); | 160 | GestureProperties GetGestureProperties(); |
| 142 | 161 | ||
| 143 | // This is nn::hid::detail::GestureLifo | 162 | SharedMemory shared_memory{}; |
| 144 | Lifo<GestureState> gesture_lifo{}; | ||
| 145 | static_assert(sizeof(gesture_lifo) == 0x708, "gesture_lifo is an invalid size"); | ||
| 146 | GestureState next_state{}; | ||
| 147 | |||
| 148 | std::array<Finger, MAX_POINTS> fingers{}; | ||
| 149 | Core::HID::EmulatedConsole* console; | 163 | Core::HID::EmulatedConsole* console; |
| 150 | 164 | ||
| 165 | std::array<Finger, MAX_POINTS> fingers{}; | ||
| 151 | GestureProperties last_gesture{}; | 166 | GestureProperties last_gesture{}; |
| 152 | s64_le last_update_timestamp{}; | 167 | s64_le last_update_timestamp{}; |
| 153 | s64_le last_tap_timestamp{}; | 168 | s64_le last_tap_timestamp{}; |
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 4fb6ab5af..25b66f528 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp | |||
| @@ -209,7 +209,7 @@ void GCAdapter::UpdateStateAxes(std::size_t port, const AdapterPayload& adapter_ | |||
| 209 | pads[port].axis_origin[index] = axis_value; | 209 | pads[port].axis_origin[index] = axis_value; |
| 210 | pads[port].reset_origin_counter++; | 210 | pads[port].reset_origin_counter++; |
| 211 | } | 211 | } |
| 212 | const f32 axis_status = (axis_value - pads[port].axis_origin[index]) / 110.0f; | 212 | const f32 axis_status = (axis_value - pads[port].axis_origin[index]) / 100.0f; |
| 213 | SetAxis(pads[port].identifier, static_cast<int>(index), axis_status); | 213 | SetAxis(pads[port].identifier, static_cast<int>(index), axis_status); |
| 214 | } | 214 | } |
| 215 | } | 215 | } |
| @@ -530,7 +530,7 @@ std::string GCAdapter::GetUIName(const Common::ParamPackage& params) const { | |||
| 530 | return fmt::format("Button {}", GetUIButtonName(params)); | 530 | return fmt::format("Button {}", GetUIButtonName(params)); |
| 531 | } | 531 | } |
| 532 | if (params.Has("axis")) { | 532 | if (params.Has("axis")) { |
| 533 | return fmt::format("Axis {}", params.Get("axis",0)); | 533 | return fmt::format("Axis {}", params.Get("axis", 0)); |
| 534 | } | 534 | } |
| 535 | 535 | ||
| 536 | return "Bad GC Adapter"; | 536 | return "Bad GC Adapter"; |
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 6fcc3a01b..f0c0a6b8b 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -243,6 +243,33 @@ void UDPClient::OnPadData(Response::PadData data, std::size_t client) { | |||
| 243 | }; | 243 | }; |
| 244 | const PadIdentifier identifier = GetPadIdentifier(pad_index); | 244 | const PadIdentifier identifier = GetPadIdentifier(pad_index); |
| 245 | SetMotion(identifier, 0, motion); | 245 | SetMotion(identifier, 0, motion); |
| 246 | |||
| 247 | for (std::size_t id = 0; id < data.touch.size(); ++id) { | ||
| 248 | const auto touch_pad = data.touch[id]; | ||
| 249 | const int touch_id = static_cast<int>(client * 2 + id); | ||
| 250 | |||
| 251 | // TODO: Use custom calibration per device | ||
| 252 | const Common::ParamPackage touch_param(Settings::values.touch_device.GetValue()); | ||
| 253 | const u16 min_x = static_cast<u16>(touch_param.Get("min_x", 100)); | ||
| 254 | const u16 min_y = static_cast<u16>(touch_param.Get("min_y", 50)); | ||
| 255 | const u16 max_x = static_cast<u16>(touch_param.Get("max_x", 1800)); | ||
| 256 | const u16 max_y = static_cast<u16>(touch_param.Get("max_y", 850)); | ||
| 257 | |||
| 258 | const f32 x = | ||
| 259 | static_cast<f32>(std::clamp(static_cast<u16>(touch_pad.x), min_x, max_x) - min_x) / | ||
| 260 | static_cast<f32>(max_x - min_x); | ||
| 261 | const f32 y = | ||
| 262 | static_cast<f32>(std::clamp(static_cast<u16>(touch_pad.y), min_y, max_y) - min_y) / | ||
| 263 | static_cast<f32>(max_y - min_y); | ||
| 264 | |||
| 265 | if (touch_pad.is_active) { | ||
| 266 | SetAxis(identifier, touch_id * 2, x); | ||
| 267 | SetAxis(identifier, touch_id * 2 + 1, y); | ||
| 268 | SetButton(identifier, touch_id, true); | ||
| 269 | continue; | ||
| 270 | } | ||
| 271 | SetButton(identifier, touch_id, false); | ||
| 272 | } | ||
| 246 | } | 273 | } |
| 247 | 274 | ||
| 248 | void UDPClient::StartCommunication(std::size_t client, const std::string& host, u16 port) { | 275 | void UDPClient::StartCommunication(std::size_t client, const std::string& host, u16 port) { |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 46a5f62ad..022d11cc4 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -2973,7 +2973,7 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie | |||
| 2973 | QString GMainWindow::GetTasStateDescription() const { | 2973 | QString GMainWindow::GetTasStateDescription() const { |
| 2974 | auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus(); | 2974 | auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus(); |
| 2975 | switch (tas_status) { | 2975 | switch (tas_status) { |
| 2976 | case InputCommon::TasInput::TasState::Running : | 2976 | case InputCommon::TasInput::TasState::Running: |
| 2977 | return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames); | 2977 | return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames); |
| 2978 | case InputCommon::TasInput::TasState::Recording: | 2978 | case InputCommon::TasInput::TasState::Recording: |
| 2979 | return tr("TAS state: Recording %1").arg(total_tas_frames); | 2979 | return tr("TAS state: Recording %1").arg(total_tas_frames); |