summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/frontend/input.h29
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp5
-rw-r--r--src/core/hle/service/hid/controllers/npad.h10
-rw-r--r--src/input_common/motion_emu.cpp17
-rw-r--r--src/input_common/udp/client.cpp10
-rw-r--r--src/input_common/udp/client.h3
-rw-r--r--src/input_common/udp/udp.cpp2
7 files changed, 41 insertions, 35 deletions
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h
index 6770475cf..9da0d2829 100644
--- a/src/core/frontend/input.h
+++ b/src/core/frontend/input.h
@@ -119,25 +119,7 @@ using ButtonDevice = InputDevice<bool>;
119using AnalogDevice = InputDevice<std::tuple<float, float>>; 119using AnalogDevice = InputDevice<std::tuple<float, float>>;
120 120
121/** 121/**
122 * A motion device is an input device that returns a tuple of accelerometer state vector and 122 * A motion status is an object that returns a tuple of accelerometer state vector,
123 * gyroscope state vector.
124 *
125 * For both vectors:
126 * x+ is the same direction as LEFT on D-pad.
127 * y+ is normal to the touch screen, pointing outward.
128 * z+ is the same direction as UP on D-pad.
129 *
130 * For accelerometer state vector
131 * Units: g (gravitational acceleration)
132 *
133 * For gyroscope state vector:
134 * Orientation is determined by right-hand rule.
135 * Units: deg/sec
136 */
137using MotionDevice = InputDevice<std::tuple<Common::Vec3<float>, Common::Vec3<float>>>;
138
139/**
140 * A real motion device is an input device that returns a tuple of accelerometer state vector,
141 * gyroscope state vector, rotation state vector and orientation state matrix. 123 * gyroscope state vector, rotation state vector and orientation state matrix.
142 * 124 *
143 * For both vectors: 125 * For both vectors:
@@ -160,8 +142,13 @@ using MotionDevice = InputDevice<std::tuple<Common::Vec3<float>, Common::Vec3<fl
160 * y vector 142 * y vector
161 * z vector 143 * z vector
162 */ 144 */
163using RealMotionDevice = InputDevice<std::tuple<Common::Vec3<float>, Common::Vec3<float>, 145using MotionStatus = std::tuple<Common::Vec3<float>, Common::Vec3<float>, Common::Vec3<float>,
164 Common::Vec3<float>, std::array<Common::Vec3f, 3>>>; 146 std::array<Common::Vec3f, 3>>;
147
148/**
149 * A motion device is an input device that returns a motion status object
150 */
151using MotionDevice = InputDevice<MotionStatus>;
165 152
166/** 153/**
167 * A touch device is an input device that returns a tuple of two floats and a bool. The floats are 154 * A touch device is an input device that returns a tuple of two floats and a bool. The floats are
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 9701318b5..2e06372a4 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -251,7 +251,7 @@ void Controller_NPad::OnLoadInputDevices() {
251 sticks[i].begin(), Input::CreateDevice<Input::AnalogDevice>); 251 sticks[i].begin(), Input::CreateDevice<Input::AnalogDevice>);
252 std::transform(players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, 252 std::transform(players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN,
253 players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_END, 253 players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_END,
254 motions[i].begin(), Input::CreateDevice<Input::RealMotionDevice>); 254 motions[i].begin(), Input::CreateDevice<Input::MotionDevice>);
255 } 255 }
256} 256}
257 257
@@ -397,7 +397,8 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
397 std::tie(motion_devices[e].accel, motion_devices[e].gyro, 397 std::tie(motion_devices[e].accel, motion_devices[e].gyro,
398 motion_devices[e].rotation, motion_devices[e].orientation) = 398 motion_devices[e].rotation, motion_devices[e].orientation) =
399 device->GetStatus(); 399 device->GetStatus();
400 sixaxis_at_rest = sixaxis_at_rest && motion_devices[e].gyro.Length2() < 1.0f; 400 sixaxis_at_rest =
401 sixaxis_at_rest && motion_devices[e].gyro.Length2() < 0.00005f;
401 } 402 }
402 } 403 }
403 } 404 }
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index 99d7e459a..7b07d2e8b 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -299,9 +299,9 @@ private:
299 299
300 struct MotionDevice { 300 struct MotionDevice {
301 Common::Vec3f accel; 301 Common::Vec3f accel;
302 Common::Vec3f gyro{}; 302 Common::Vec3f gyro;
303 Common::Vec3f rotation; 303 Common::Vec3f rotation;
304 std::array<Common::Vec3f, 3> orientation{}; 304 std::array<Common::Vec3f, 3> orientation;
305 }; 305 };
306 306
307 struct NPadEntry { 307 struct NPadEntry {
@@ -358,9 +358,9 @@ private:
358 using StickArray = std::array< 358 using StickArray = std::array<
359 std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>, 359 std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>,
360 10>; 360 10>;
361 using MotionArray = std::array<std::array<std::unique_ptr<Input::RealMotionDevice>, 361 using MotionArray = std::array<
362 Settings::NativeMotion::NUM_MOTION_HID>, 362 std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTION_HID>,
363 10>; 363 10>;
364 ButtonArray buttons; 364 ButtonArray buttons;
365 StickArray sticks; 365 StickArray sticks;
366 MotionArray motions; 366 MotionArray motions;
diff --git a/src/input_common/motion_emu.cpp b/src/input_common/motion_emu.cpp
index d4cdf76a3..69fd3c1d2 100644
--- a/src/input_common/motion_emu.cpp
+++ b/src/input_common/motion_emu.cpp
@@ -56,7 +56,7 @@ public:
56 is_tilting = false; 56 is_tilting = false;
57 } 57 }
58 58
59 std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() { 59 Input::MotionStatus GetStatus() {
60 std::lock_guard guard{status_mutex}; 60 std::lock_guard guard{status_mutex};
61 return status; 61 return status;
62 } 62 }
@@ -76,7 +76,7 @@ private:
76 76
77 Common::Event shutdown_event; 77 Common::Event shutdown_event;
78 78
79 std::tuple<Common::Vec3<float>, Common::Vec3<float>> status; 79 Input::MotionStatus status;
80 std::mutex status_mutex; 80 std::mutex status_mutex;
81 81
82 // Note: always keep the thread declaration at the end so that other objects are initialized 82 // Note: always keep the thread declaration at the end so that other objects are initialized
@@ -113,10 +113,19 @@ private:
113 gravity = QuaternionRotate(inv_q, gravity); 113 gravity = QuaternionRotate(inv_q, gravity);
114 angular_rate = QuaternionRotate(inv_q, angular_rate); 114 angular_rate = QuaternionRotate(inv_q, angular_rate);
115 115
116 // TODO: Calculate the correct rotation vector and orientation matrix
117 const auto matrix4x4 = q.ToMatrix();
118 const auto rotation = Common::MakeVec(0.0f, 0.0f, 0.0f);
119 const std::array orientation{
120 Common::Vec3f(matrix4x4[0], matrix4x4[1], -matrix4x4[2]),
121 Common::Vec3f(matrix4x4[4], matrix4x4[5], -matrix4x4[6]),
122 Common::Vec3f(-matrix4x4[8], -matrix4x4[9], matrix4x4[10]),
123 };
124
116 // Update the sensor state 125 // Update the sensor state
117 { 126 {
118 std::lock_guard guard{status_mutex}; 127 std::lock_guard guard{status_mutex};
119 status = std::make_tuple(gravity, angular_rate); 128 status = std::make_tuple(gravity, angular_rate, rotation, orientation);
120 } 129 }
121 } 130 }
122 } 131 }
@@ -131,7 +140,7 @@ public:
131 device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity); 140 device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity);
132 } 141 }
133 142
134 std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override { 143 Input::MotionStatus GetStatus() const override {
135 return device->GetStatus(); 144 return device->GetStatus();
136 } 145 }
137 146
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp
index 3f4eaf448..91e13482d 100644
--- a/src/input_common/udp/client.cpp
+++ b/src/input_common/udp/client.cpp
@@ -170,10 +170,18 @@ void Client::OnPadData(Response::PadData data) {
170 // directions correspond to the ones of the Switch 170 // directions correspond to the ones of the Switch
171 Common::Vec3f accel = Common::MakeVec<float>(data.accel.x, data.accel.y, data.accel.z); 171 Common::Vec3f accel = Common::MakeVec<float>(data.accel.x, data.accel.y, data.accel.z);
172 Common::Vec3f gyro = Common::MakeVec<float>(data.gyro.pitch, data.gyro.yaw, data.gyro.roll); 172 Common::Vec3f gyro = Common::MakeVec<float>(data.gyro.pitch, data.gyro.yaw, data.gyro.roll);
173
174 // TODO: Calculate the correct rotation vector and orientation matrix
175 const auto rotation = Common::MakeVec(0.0f, 0.0f, 0.0f);
176 const std::array orientation{
177 Common::Vec3f(1.0f, 0.0f, 0.0f),
178 Common::Vec3f(0.0f, 1.0f, 0.0f),
179 Common::Vec3f(0.0f, 0.0f, 1.0f),
180 };
173 { 181 {
174 std::lock_guard guard(status->update_mutex); 182 std::lock_guard guard(status->update_mutex);
175 183
176 status->motion_status = {accel, gyro}; 184 status->motion_status = {accel, gyro, rotation, orientation};
177 185
178 // TODO: add a setting for "click" touch. Click touch refers to a device that differentiates 186 // TODO: add a setting for "click" touch. Click touch refers to a device that differentiates
179 // between a simple "tap" and a hard press that causes the touch screen to click. 187 // between a simple "tap" and a hard press that causes the touch screen to click.
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h
index b8c654755..a73283ae8 100644
--- a/src/input_common/udp/client.h
+++ b/src/input_common/udp/client.h
@@ -14,6 +14,7 @@
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/thread.h" 15#include "common/thread.h"
16#include "common/vector_math.h" 16#include "common/vector_math.h"
17#include "core/frontend/input.h"
17 18
18namespace InputCommon::CemuhookUDP { 19namespace InputCommon::CemuhookUDP {
19 20
@@ -30,7 +31,7 @@ struct Version;
30 31
31struct DeviceStatus { 32struct DeviceStatus {
32 std::mutex update_mutex; 33 std::mutex update_mutex;
33 std::tuple<Common::Vec3<float>, Common::Vec3<float>> motion_status; 34 Input::MotionStatus motion_status;
34 std::tuple<float, float, bool> touch_status; 35 std::tuple<float, float, bool> touch_status;
35 36
36 // calibration data for scaling the device's touch area to 3ds 37 // calibration data for scaling the device's touch area to 3ds
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp
index 4b347e47e..03bae5752 100644
--- a/src/input_common/udp/udp.cpp
+++ b/src/input_common/udp/udp.cpp
@@ -29,7 +29,7 @@ private:
29class UDPMotionDevice final : public Input::MotionDevice { 29class UDPMotionDevice final : public Input::MotionDevice {
30public: 30public:
31 explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {} 31 explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
32 std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override { 32 Input::MotionStatus GetStatus() const override {
33 std::lock_guard guard(status->update_mutex); 33 std::lock_guard guard(status->update_mutex);
34 return status->motion_status; 34 return status->motion_status;
35 } 35 }