|
|
@ -5,8 +5,10 @@
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "common/math_util.h"
|
|
|
|
#include "common/math_util.h"
|
|
|
|
#include "common/settings.h"
|
|
|
|
#include "common/settings.h"
|
|
|
|
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/core_timing.h"
|
|
|
|
#include "core/core_timing.h"
|
|
|
|
#include "core/frontend/emu_window.h"
|
|
|
|
#include "core/frontend/emu_window.h"
|
|
|
|
|
|
|
|
#include "core/hid/hid_core.h"
|
|
|
|
#include "core/hle/service/hid/controllers/gesture.h"
|
|
|
|
#include "core/hle/service/hid/controllers/gesture.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Service::HID {
|
|
|
|
namespace Service::HID {
|
|
|
@ -23,16 +25,15 @@ constexpr f32 Square(s32 num) {
|
|
|
|
return static_cast<f32>(num * num);
|
|
|
|
return static_cast<f32>(num * num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Controller_Gesture::Controller_Gesture(Core::System& system_) : ControllerBase(system_) {}
|
|
|
|
Controller_Gesture::Controller_Gesture(Core::System& system_) : ControllerBase(system_) {
|
|
|
|
|
|
|
|
console = system.HIDCore().GetEmulatedConsole();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Controller_Gesture::~Controller_Gesture() = default;
|
|
|
|
Controller_Gesture::~Controller_Gesture() = default;
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::OnInit() {
|
|
|
|
void Controller_Gesture::OnInit() {
|
|
|
|
for (std::size_t id = 0; id < MAX_FINGERS; ++id) {
|
|
|
|
gesture_lifo.entry_count = 0;
|
|
|
|
mouse_finger_id[id] = MAX_POINTS;
|
|
|
|
gesture_lifo.last_entry_index = 0;
|
|
|
|
keyboard_finger_id[id] = MAX_POINTS;
|
|
|
|
|
|
|
|
udp_finger_id[id] = MAX_POINTS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
shared_memory.header.entry_count = 0;
|
|
|
|
|
|
|
|
force_update = true;
|
|
|
|
force_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -40,50 +41,43 @@ void Controller_Gesture::OnRelease() {}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
|
|
|
|
void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
|
|
|
|
std::size_t size) {
|
|
|
|
std::size_t size) {
|
|
|
|
shared_memory.header.timestamp = core_timing.GetCPUTicks();
|
|
|
|
// TODO FIND WTF IS WRONG HERE!!!!!!!!
|
|
|
|
shared_memory.header.total_entry_count = 17;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!IsControllerActivated()) {
|
|
|
|
if (!IsControllerActivated()) {
|
|
|
|
shared_memory.header.entry_count = 0;
|
|
|
|
gesture_lifo.entry_count = 0;
|
|
|
|
shared_memory.header.last_entry_index = 0;
|
|
|
|
gesture_lifo.last_entry_index = 0;
|
|
|
|
|
|
|
|
std::memcpy(data, &gesture_lifo, sizeof(gesture_lifo));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ReadTouchInput();
|
|
|
|
ReadTouchInput();
|
|
|
|
|
|
|
|
|
|
|
|
GestureProperties gesture = GetGestureProperties();
|
|
|
|
GestureProperties gesture = GetGestureProperties();
|
|
|
|
f32 time_difference = static_cast<f32>(shared_memory.header.timestamp - last_update_timestamp) /
|
|
|
|
f32 time_difference =
|
|
|
|
(1000 * 1000 * 1000);
|
|
|
|
static_cast<f32>(gesture_lifo.timestamp - last_update_timestamp) / (1000 * 1000 * 1000);
|
|
|
|
|
|
|
|
|
|
|
|
// Only update if necesary
|
|
|
|
// Only update if necesary
|
|
|
|
if (!ShouldUpdateGesture(gesture, time_difference)) {
|
|
|
|
if (!ShouldUpdateGesture(gesture, time_difference)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
last_update_timestamp = shared_memory.header.timestamp;
|
|
|
|
last_update_timestamp = gesture_lifo.timestamp;
|
|
|
|
UpdateGestureSharedMemory(data, size, gesture, time_difference);
|
|
|
|
UpdateGestureSharedMemory(data, size, gesture, time_difference);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::ReadTouchInput() {
|
|
|
|
void Controller_Gesture::ReadTouchInput() {
|
|
|
|
const Input::TouchStatus& mouse_status = touch_mouse_device->GetStatus();
|
|
|
|
const auto touch_status = console->GetTouch();
|
|
|
|
const Input::TouchStatus& udp_status = touch_udp_device->GetStatus();
|
|
|
|
for (std::size_t id = 0; id < fingers.size(); ++id) {
|
|
|
|
for (std::size_t id = 0; id < mouse_status.size(); ++id) {
|
|
|
|
const Core::HID::TouchFinger& status = touch_status[id];
|
|
|
|
mouse_finger_id[id] = UpdateTouchInputEvent(mouse_status[id], mouse_finger_id[id]);
|
|
|
|
Finger& finger = fingers[id];
|
|
|
|
udp_finger_id[id] = UpdateTouchInputEvent(udp_status[id], udp_finger_id[id]);
|
|
|
|
finger.pos = status.position;
|
|
|
|
}
|
|
|
|
finger.pressed = status.pressed;
|
|
|
|
|
|
|
|
|
|
|
|
if (Settings::values.use_touch_from_button) {
|
|
|
|
|
|
|
|
const Input::TouchStatus& keyboard_status = touch_btn_device->GetStatus();
|
|
|
|
|
|
|
|
for (std::size_t id = 0; id < mouse_status.size(); ++id) {
|
|
|
|
|
|
|
|
keyboard_finger_id[id] =
|
|
|
|
|
|
|
|
UpdateTouchInputEvent(keyboard_status[id], keyboard_finger_id[id]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture,
|
|
|
|
bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
if (force_update) {
|
|
|
|
if (force_update) {
|
|
|
|
force_update = false;
|
|
|
|
force_update = false;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -97,7 +91,7 @@ bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update on press and hold event after 0.5 seconds
|
|
|
|
// Update on press and hold event after 0.5 seconds
|
|
|
|
if (last_entry.type == TouchType::Touch && last_entry.point_count == 1 &&
|
|
|
|
if (last_entry.type == GestureType::Touch && last_entry.point_count == 1 &&
|
|
|
|
time_difference > press_delay) {
|
|
|
|
time_difference > press_delay) {
|
|
|
|
return enable_press_and_tap;
|
|
|
|
return enable_press_and_tap;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -108,27 +102,19 @@ bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture,
|
|
|
|
void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
|
|
|
|
void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
|
|
|
|
GestureProperties& gesture,
|
|
|
|
GestureProperties& gesture,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
TouchType type = TouchType::Idle;
|
|
|
|
GestureType type = GestureType::Idle;
|
|
|
|
Attribute attributes{};
|
|
|
|
GestureAttribute attributes{};
|
|
|
|
|
|
|
|
|
|
|
|
const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
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) {
|
|
|
|
// Reset next state to default
|
|
|
|
shared_memory.header.entry_count++;
|
|
|
|
next_state.sampling_number = last_entry.sampling_number + 1;
|
|
|
|
}
|
|
|
|
next_state.delta = {};
|
|
|
|
|
|
|
|
next_state.vel_x = 0;
|
|
|
|
cur_entry.sampling_number = last_entry.sampling_number + 1;
|
|
|
|
next_state.vel_y = 0;
|
|
|
|
cur_entry.sampling_number2 = cur_entry.sampling_number;
|
|
|
|
next_state.direction = GestureDirection::None;
|
|
|
|
|
|
|
|
next_state.rotation_angle = 0;
|
|
|
|
// Reset values to default
|
|
|
|
next_state.scale = 0;
|
|
|
|
cur_entry.delta = {};
|
|
|
|
|
|
|
|
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 (gesture.active_points > 0) {
|
|
|
|
if (last_gesture.active_points == 0) {
|
|
|
|
if (last_gesture.active_points == 0) {
|
|
|
@ -141,46 +127,47 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Apply attributes
|
|
|
|
// Apply attributes
|
|
|
|
cur_entry.detection_count = gesture.detection_count;
|
|
|
|
next_state.detection_count = gesture.detection_count;
|
|
|
|
cur_entry.type = type;
|
|
|
|
next_state.type = type;
|
|
|
|
cur_entry.attributes = attributes;
|
|
|
|
next_state.attributes = attributes;
|
|
|
|
cur_entry.pos = gesture.mid_point;
|
|
|
|
next_state.pos = gesture.mid_point;
|
|
|
|
cur_entry.point_count = static_cast<s32>(gesture.active_points);
|
|
|
|
next_state.point_count = static_cast<s32>(gesture.active_points);
|
|
|
|
cur_entry.points = gesture.points;
|
|
|
|
next_state.points = gesture.points;
|
|
|
|
last_gesture = gesture;
|
|
|
|
last_gesture = gesture;
|
|
|
|
|
|
|
|
|
|
|
|
std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory));
|
|
|
|
gesture_lifo.WriteNextEntry(next_state);
|
|
|
|
|
|
|
|
std::memcpy(data + SHARED_MEMORY_OFFSET, &gesture_lifo, sizeof(gesture_lifo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
|
|
|
|
void Controller_Gesture::NewGesture(GestureProperties& gesture, GestureType& type,
|
|
|
|
Attribute& attributes) {
|
|
|
|
GestureAttribute& attributes) {
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
|
|
|
|
|
|
|
|
gesture.detection_count++;
|
|
|
|
gesture.detection_count++;
|
|
|
|
type = TouchType::Touch;
|
|
|
|
type = GestureType::Touch;
|
|
|
|
|
|
|
|
|
|
|
|
// New touch after cancel is not considered new
|
|
|
|
// New touch after cancel is not considered new
|
|
|
|
if (last_entry.type != TouchType::Cancel) {
|
|
|
|
if (last_entry.type != GestureType::Cancel) {
|
|
|
|
attributes.is_new_touch.Assign(1);
|
|
|
|
attributes.is_new_touch.Assign(1);
|
|
|
|
enable_press_and_tap = true;
|
|
|
|
enable_press_and_tap = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, TouchType& type,
|
|
|
|
void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, GestureType& type,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
|
|
|
|
|
|
|
|
// Promote to pan type if touch moved
|
|
|
|
// Promote to pan type if touch moved
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
if (gesture.points[id] != last_gesture.points[id]) {
|
|
|
|
if (gesture.points[id] != last_gesture.points[id]) {
|
|
|
|
type = TouchType::Pan;
|
|
|
|
type = GestureType::Pan;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Number of fingers changed cancel the last event and clear data
|
|
|
|
// Number of fingers changed cancel the last event and clear data
|
|
|
|
if (gesture.active_points != last_gesture.active_points) {
|
|
|
|
if (gesture.active_points != last_gesture.active_points) {
|
|
|
|
type = TouchType::Cancel;
|
|
|
|
type = GestureType::Cancel;
|
|
|
|
enable_press_and_tap = false;
|
|
|
|
enable_press_and_tap = false;
|
|
|
|
gesture.active_points = 0;
|
|
|
|
gesture.active_points = 0;
|
|
|
|
gesture.mid_point = {};
|
|
|
|
gesture.mid_point = {};
|
|
|
@ -189,41 +176,41 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Touch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate extra parameters of panning
|
|
|
|
// Calculate extra parameters of panning
|
|
|
|
if (type == TouchType::Pan) {
|
|
|
|
if (type == GestureType::Pan) {
|
|
|
|
UpdatePanEvent(gesture, last_gesture, type, time_difference);
|
|
|
|
UpdatePanEvent(gesture, last_gesture, type, time_difference);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Promote to press type
|
|
|
|
// Promote to press type
|
|
|
|
if (last_entry.type == TouchType::Touch) {
|
|
|
|
if (last_entry.type == GestureType::Touch) {
|
|
|
|
type = TouchType::Press;
|
|
|
|
type = GestureType::Press;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::EndGesture(GestureProperties& gesture,
|
|
|
|
void Controller_Gesture::EndGesture(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
GestureProperties& last_gesture_props, GestureType& type,
|
|
|
|
Attribute& attributes, f32 time_difference) {
|
|
|
|
GestureAttribute& attributes, f32 time_difference) {
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
|
|
|
|
|
|
|
|
if (last_gesture_props.active_points != 0) {
|
|
|
|
if (last_gesture_props.active_points != 0) {
|
|
|
|
switch (last_entry.type) {
|
|
|
|
switch (last_entry.type) {
|
|
|
|
case TouchType::Touch:
|
|
|
|
case GestureType::Touch:
|
|
|
|
if (enable_press_and_tap) {
|
|
|
|
if (enable_press_and_tap) {
|
|
|
|
SetTapEvent(gesture, last_gesture_props, type, attributes);
|
|
|
|
SetTapEvent(gesture, last_gesture_props, type, attributes);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type = TouchType::Cancel;
|
|
|
|
type = GestureType::Cancel;
|
|
|
|
force_update = true;
|
|
|
|
force_update = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case TouchType::Press:
|
|
|
|
case GestureType::Press:
|
|
|
|
case TouchType::Tap:
|
|
|
|
case GestureType::Tap:
|
|
|
|
case TouchType::Swipe:
|
|
|
|
case GestureType::Swipe:
|
|
|
|
case TouchType::Pinch:
|
|
|
|
case GestureType::Pinch:
|
|
|
|
case TouchType::Rotate:
|
|
|
|
case GestureType::Rotate:
|
|
|
|
type = TouchType::Complete;
|
|
|
|
type = GestureType::Complete;
|
|
|
|
force_update = true;
|
|
|
|
force_update = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case TouchType::Pan:
|
|
|
|
case GestureType::Pan:
|
|
|
|
EndPanEvent(gesture, last_gesture_props, type, time_difference);
|
|
|
|
EndPanEvent(gesture, last_gesture_props, type, time_difference);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -231,15 +218,15 @@ void Controller_Gesture::EndGesture(GestureProperties& gesture,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (last_entry.type == TouchType::Complete || last_entry.type == TouchType::Cancel) {
|
|
|
|
if (last_entry.type == GestureType::Complete || last_entry.type == GestureType::Cancel) {
|
|
|
|
gesture.detection_count++;
|
|
|
|
gesture.detection_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::SetTapEvent(GestureProperties& gesture,
|
|
|
|
void Controller_Gesture::SetTapEvent(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
GestureProperties& last_gesture_props, GestureType& type,
|
|
|
|
Attribute& attributes) {
|
|
|
|
GestureAttribute& attributes) {
|
|
|
|
type = TouchType::Tap;
|
|
|
|
type = GestureType::Tap;
|
|
|
|
gesture = last_gesture_props;
|
|
|
|
gesture = last_gesture_props;
|
|
|
|
force_update = true;
|
|
|
|
force_update = true;
|
|
|
|
f32 tap_time_difference =
|
|
|
|
f32 tap_time_difference =
|
|
|
@ -251,44 +238,42 @@ void Controller_Gesture::SetTapEvent(GestureProperties& gesture,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture,
|
|
|
|
void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
GestureProperties& last_gesture_props, GestureType& type,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cur_entry.delta = gesture.mid_point - last_entry.pos;
|
|
|
|
next_state.delta = gesture.mid_point - last_entry.pos;
|
|
|
|
cur_entry.vel_x = static_cast<f32>(cur_entry.delta.x) / time_difference;
|
|
|
|
next_state.vel_x = static_cast<f32>(next_state.delta.x) / time_difference;
|
|
|
|
cur_entry.vel_y = static_cast<f32>(cur_entry.delta.y) / time_difference;
|
|
|
|
next_state.vel_y = static_cast<f32>(next_state.delta.y) / time_difference;
|
|
|
|
last_pan_time_difference = time_difference;
|
|
|
|
last_pan_time_difference = time_difference;
|
|
|
|
|
|
|
|
|
|
|
|
// Promote to pinch type
|
|
|
|
// Promote to pinch type
|
|
|
|
if (std::abs(gesture.average_distance - last_gesture_props.average_distance) >
|
|
|
|
if (std::abs(gesture.average_distance - last_gesture_props.average_distance) >
|
|
|
|
pinch_threshold) {
|
|
|
|
pinch_threshold) {
|
|
|
|
type = TouchType::Pinch;
|
|
|
|
type = GestureType::Pinch;
|
|
|
|
cur_entry.scale = gesture.average_distance / last_gesture_props.average_distance;
|
|
|
|
next_state.scale = gesture.average_distance / last_gesture_props.average_distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const f32 angle_between_two_lines = std::atan((gesture.angle - last_gesture_props.angle) /
|
|
|
|
const f32 angle_between_two_lines = std::atan((gesture.angle - last_gesture_props.angle) /
|
|
|
|
(1 + (gesture.angle * last_gesture_props.angle)));
|
|
|
|
(1 + (gesture.angle * last_gesture_props.angle)));
|
|
|
|
// Promote to rotate type
|
|
|
|
// Promote to rotate type
|
|
|
|
if (std::abs(angle_between_two_lines) > angle_threshold) {
|
|
|
|
if (std::abs(angle_between_two_lines) > angle_threshold) {
|
|
|
|
type = TouchType::Rotate;
|
|
|
|
type = GestureType::Rotate;
|
|
|
|
cur_entry.scale = 0;
|
|
|
|
next_state.scale = 0;
|
|
|
|
cur_entry.rotation_angle = angle_between_two_lines * 180.0f / Common::PI;
|
|
|
|
next_state.rotation_angle = angle_between_two_lines * 180.0f / Common::PI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
|
|
|
|
void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
GestureProperties& last_gesture_props, GestureType& type,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
next_state.vel_x =
|
|
|
|
cur_entry.vel_x =
|
|
|
|
|
|
|
|
static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference);
|
|
|
|
static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference);
|
|
|
|
cur_entry.vel_y =
|
|
|
|
next_state.vel_y =
|
|
|
|
static_cast<f32>(last_entry.delta.y) / (last_pan_time_difference + time_difference);
|
|
|
|
static_cast<f32>(last_entry.delta.y) / (last_pan_time_difference + time_difference);
|
|
|
|
const f32 curr_vel =
|
|
|
|
const f32 curr_vel =
|
|
|
|
std::sqrt((cur_entry.vel_x * cur_entry.vel_x) + (cur_entry.vel_y * cur_entry.vel_y));
|
|
|
|
std::sqrt((next_state.vel_x * next_state.vel_x) + (next_state.vel_y * next_state.vel_y));
|
|
|
|
|
|
|
|
|
|
|
|
// Set swipe event with parameters
|
|
|
|
// Set swipe event with parameters
|
|
|
|
if (curr_vel > swipe_threshold) {
|
|
|
|
if (curr_vel > swipe_threshold) {
|
|
|
@ -297,93 +282,34 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// End panning without swipe
|
|
|
|
// End panning without swipe
|
|
|
|
type = TouchType::Complete;
|
|
|
|
type = GestureType::Complete;
|
|
|
|
cur_entry.vel_x = 0;
|
|
|
|
next_state.vel_x = 0;
|
|
|
|
cur_entry.vel_y = 0;
|
|
|
|
next_state.vel_y = 0;
|
|
|
|
force_update = true;
|
|
|
|
force_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture,
|
|
|
|
void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type) {
|
|
|
|
GestureProperties& last_gesture_props, GestureType& type) {
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry = gesture_lifo.ReadCurrentEntry().state;
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type = TouchType::Swipe;
|
|
|
|
type = GestureType::Swipe;
|
|
|
|
gesture = last_gesture_props;
|
|
|
|
gesture = last_gesture_props;
|
|
|
|
force_update = true;
|
|
|
|
force_update = true;
|
|
|
|
cur_entry.delta = last_entry.delta;
|
|
|
|
next_state.delta = last_entry.delta;
|
|
|
|
|
|
|
|
|
|
|
|
if (std::abs(cur_entry.delta.x) > std::abs(cur_entry.delta.y)) {
|
|
|
|
if (std::abs(next_state.delta.x) > std::abs(next_state.delta.y)) {
|
|
|
|
if (cur_entry.delta.x > 0) {
|
|
|
|
if (next_state.delta.x > 0) {
|
|
|
|
cur_entry.direction = Direction::Right;
|
|
|
|
next_state.direction = GestureDirection::Right;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur_entry.direction = Direction::Left;
|
|
|
|
next_state.direction = GestureDirection::Left;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cur_entry.delta.y > 0) {
|
|
|
|
if (next_state.delta.y > 0) {
|
|
|
|
cur_entry.direction = Direction::Down;
|
|
|
|
next_state.direction = GestureDirection::Down;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur_entry.direction = Direction::Up;
|
|
|
|
next_state.direction = GestureDirection::Up;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::OnLoadInputDevices() {
|
|
|
|
|
|
|
|
touch_mouse_device = Input::CreateDevice<Input::TouchDevice>("engine:emu_window");
|
|
|
|
|
|
|
|
touch_udp_device = Input::CreateDevice<Input::TouchDevice>("engine:cemuhookudp");
|
|
|
|
|
|
|
|
touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
return first_free_id;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
first_free_id++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() {
|
|
|
|
|
|
|
|
return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() const {
|
|
|
|
|
|
|
|
return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::size_t Controller_Gesture::UpdateTouchInputEvent(
|
|
|
|
|
|
|
|
const std::tuple<float, float, bool>& touch_input, std::size_t finger_id) {
|
|
|
|
|
|
|
|
const auto& [x, y, pressed] = touch_input;
|
|
|
|
|
|
|
|
if (finger_id > MAX_POINTS) {
|
|
|
|
|
|
|
|
LOG_ERROR(Service_HID, "Invalid finger id {}", finger_id);
|
|
|
|
|
|
|
|
return MAX_POINTS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pressed) {
|
|
|
|
|
|
|
|
if (finger_id == MAX_POINTS) {
|
|
|
|
|
|
|
|
const auto first_free_id = GetUnusedFingerID();
|
|
|
|
|
|
|
|
if (!first_free_id) {
|
|
|
|
|
|
|
|
// Invalid finger id do nothing
|
|
|
|
|
|
|
|
return MAX_POINTS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finger_id = first_free_id.value();
|
|
|
|
|
|
|
|
fingers[finger_id].pressed = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fingers[finger_id].pos = {x, y};
|
|
|
|
|
|
|
|
return finger_id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (finger_id != MAX_POINTS) {
|
|
|
|
|
|
|
|
fingers[finger_id].pressed = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return MAX_POINTS;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties() {
|
|
|
|
Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties() {
|
|
|
|